User avatar
bensimmo
Posts: 4125
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 3:53 pm

Probably a bit like why do people use Photoshop and filters rather than hand edit the pixels.

Python has science, maths, etc modules where others have done the hardwork.

And yes at University level, undergrad or PhD, they may not know how to code well.
They can pick it up and do their work,.with tools.other have created and optimised under the hood, probably in C, possibly in Pascal.

They can get the job done, quickly.

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 4:03 pm

I am not so good with C code yet, but it seems to me like lot C people are pointers, eh, over-using?

+ from another keg:

https://www.tiobe.com/tiobe-index/

Java (for a change)
C is next...
Python third
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

Heater
Posts: 12969
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 4:33 pm

Musketeer,
I used this as kiddo: https://en.wikipedia.org/wiki/Karel_(pr ... _language)
That got me curious, I don't recall hearing about Karel before so I went googling.
https://en.wikipedia.org/wiki/Karel_%28 ... anguage%29

Cool, a Czech robot named after the Czech guy that gave the name "robot" to robots.

Found the original manuals:
https://sourceforge.net/p/karel-3d-webg ... 987-90.zip

Found Karel's home page:
https://www.cs.mtsu.edu/~untch/karel/

And found a modern 3D recreation of Karel for the web by Slovakian Samuel Sebastian. Based on the 1986 version for Tesla 8bit microcomputer PMD 85-2.
https://www.root.cz/clanky/ceskoslovens ... sh-pmd-85/
https://sourceforge.net/projects/karel-3d-webgl/

Which I have put up here:
https://otaniemi.conveqs.fi:3000/public ... -3DGL.html

How does that compare to the original?

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 4:38 pm

Karel Čapek - author of RUR and other books.

It was on Atari 800 XL!

You can do this then:

MOVE FORWARD
MOVE BACK
GET
DROP (10 max.)
TURN RIGHT

so

if you want TURN LEFT = you write 3 x TURN RIGHT ;)
Last edited by Musketeer on Thu Jul 11, 2019 5:35 pm, edited 2 times in total.
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 4:44 pm

Musketeer wrote:
Thu Jul 11, 2019 4:03 pm
I am not so good with C code yet, but it seems to me like lot C people are pointers, eh, over-using?

+ from another keg:

https://www.tiobe.com/tiobe-index/

Java (for a change)
C is next...
Python third
Yep C is second, and Assembly language is up to 12th (1.39% that is a lot of people coding in assembly language, does not specify the target CPU's though).

C is more usable from my view than most other HLL's.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5774
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 6:15 pm

To answer OP's question, it's because RAM and performance are irrelevant for that use case.

Numpy is mostly written in C and can use BLAS Most BLAS implementations will take full advantage of NEON and are extremely fast. and efficient. If you spend most of the time chewing through data in C, it doesn't matter if you lose a tiny bit of time in Python. When you have a gig or ram available (or even 4), python overhead won't be what's eating it.

tpyo kingg
Posts: 562
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 6:22 pm

Musketeer wrote:
Wed Jul 10, 2019 7:31 pm
Its 20-100x times faster and uses 20-100x less RAM?
C is not faster for everything. Perl is highly efficient at text processing and, especially, regular expression pattern matching. I've read anecdotes from some very skilled C programmers reporting to their consternation that it beat C for some tasks.

The early Internet and early to middle WWW were pretty much all text. The WWW still contains lots of text and what's not text is often carried in a framework (XHTML + CSS) that is text. Perl excels at text. That's not to dismiss C however. It is merely to point out that the choice is also a matter of finding the right tool for the job. Horses for courses as some might say.

There is also the question of how many lines of code you can write in a work day. In higher level languages, you get more done. In lower level languages, you get finer control.

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 6:35 pm

I heard very good for texts is Free Pascal? Low level too...

https://benchmarksgame-team.pages.debia ... l-gpp.html

"Compiler managed string types:
Strings in C is still like how it was in 1971 when the language comes out: Programmer managed pointer to array of char ending with #0. Storage, validity, etc. must be managed bt the programmer, just like another pointers. This is the biggest cause of memory leaks, buffer overruns, etc. Furthermore, strings don't know their length, thus a length retrieval operation is O(n) instead of O(1) as in Pascal. Some compilers hack this behavior by treating strlen as internal command, and whenever possible, it's replaced by actual string length. But this works only for static strings (or concatenation of them), other strings will still perform in O(n), whereas in Pascal it's always O(1) for all cases."
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

Heater
Posts: 12969
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 9:35 pm

tpyo kingg,
C is not faster for everything. Perl is highly efficient at text processing and,...
Except Perl is written in C.

So if someone's C code is slower than doing it in Perl they are doing it wrong :)

You are right though, it takes a lot more work to do many things by writing C than making use of the facilities of higher level languages.

jahboater
Posts: 4595
Joined: Wed Feb 04, 2015 6:38 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Thu Jul 11, 2019 11:35 pm

Musketeer wrote:
Thu Jul 11, 2019 6:35 pm
Furthermore, strings don't know their length, thus a length retrieval operation is O(n) instead of O(1) as in Pascal.
Out of interest, what would you suggest as an alternative?

User avatar
Douglas6
Posts: 4711
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Fri Jul 12, 2019 2:18 am

Sigh. Another "my language is better than your language" thread. What strikes me about this one is the OP's unsubstantiated 20x - 100x performance improvement claim. Any real-world evidence?

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Fri Jul 12, 2019 7:43 am

See RAM consumption for each:

https://benchmarksgame-team.pages.debia ... marksgame/

Python/Perl is vs C in worst case like 1:280-300 !

+ study this:

https://jaxenter.com/energy-efficient-p ... 37264.html

Python and Perl have 1:+/-80 bigger consumption!

This is not about whose language is better but about informed choices! On many people are languages simply forced (work, school, ...)!

Hmm... I am getting second thought about leaving Java...

What a paradox! The language which has smallest code (Pascal) and so it is most probable he will end in cache is dying today...
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

User avatar
scruss
Posts: 2356
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 7:03 pm

Musketeer wrote:
Fri Jul 12, 2019 7:43 am
See RAM consumption for each:

https://benchmarksgame-team.pages.debia ... marksgame/

Python/Perl is vs C in worst case like 1:280-300 !
Digging through some of their other files, it seems that they deliberately hamper some of the languages. The Fortran benchmarks turn off vectorization while the C code often enables OpenMP. They're also running on X86_64, which is not exactly comparable to ARM.

I see they call it benchmarksgame, which is a fair assessment of most benchmarks. A game, an amusement; nothing more¹.
+ study this:

https://jaxenter.com/energy-efficient-p ... 37264.html

Python and Perl have 1:+/-80 bigger consumption!
This reads like a Java data centre strongly pushing the case to keep using Java. And if you have long-running Java apps on a server, JIT's likely going to be useful for optimizing performance/energy use. Everything else doesn't really matter.

So here's my spicy take:
  1. Memory use doesn't matter. We've all got lots of memory in our computers. Yes, it's nice to be thoughtful of other processes and users, but don't let it get in the way of doing useful work
  2. Energy efficiency of your programs matters very little. If you spend ages writing code for a little time running it, you've still used a load of energy sitting thinking while you code/debug.
For example, my desktop + monitor draws 60 W idle or 100 W with one of its eight cores at 100%. So an hour of coding is about the same energy use as 36 minutes of run time. It takes a lot to thrash a 4 GHz i7 for an hour, but no-one thinks anything of spending hours programming. It's far more energy efficient to have quick development and slightly slower code (unless you're writing daemons) than spend weeks mucking about in the lowest levels of C to save a few T-states.

--
¹: unless you're Roy, that is.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

hippy
Posts: 5595
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 7:53 pm

Heater wrote:
Thu Jul 11, 2019 2:56 pm
If you think you need pointers to program in Python you have totally missed the point (get it :))
I would agree. If one wants to use pointers to gain advantages in an algorithm then Python is not the language to use. If one chooses Python one has to accept the limitations that language comes with, or start writing C extensions to provide the functionality one wants.

There are no data or data structure pointers in Python but it is possible to have function pointers which come in handy. That allowed me to create a quite elegant Finite State Machine design with Python.

User avatar
scruss
Posts: 2356
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 8:01 pm

Further to this, here's an example of something I do that would be very annoying to write in C, but Perl does it quickly and efficiently enough. The problem can be stated as:
List the English words (no proper nouns, no possessives) from the system word list that are valid anagrams of other words in that list. The results should be grouped by words containing the same letters and sorted alphabetically by first match
What I'm looking for is something like:

Code: Select all

abed: bade, bead
abet: bate, beat, beta
abets: baste, bates, beast, beats, betas
 …
woodworm: wormwood
wriest: writes
wrist: writs
Here's my mostly idiomatic Perl code to do this:

Code: Select all

#!/usr/bin/env perl
# selfgrams.pl - find words that have valid anagrams
# scruss - 2019-07 - may need wcanadian/wbritish/wamerican package
use v5.20;
my (@words, %grams, @elem, %output, $key, $fh);

# create source word list from system file
open( $fh, '<', '/usr/share/dict/words' ) or die "$!\n";
chomp( @words = grep { /^[a-z]+$/ } <$fh> );
close($fh);

# process source word list into hash of anagrams
foreach (@words) {
    # sort word's letters to generate key - eg: 'maps' => 'amps'
    $key = join( '', sort( split( '', $_ ) ) );
    # append word to existing hash match or create if word is new
    @elem =
        ( exists( $grams{$key} ) )
      ? ( @{ $grams{$key} }, $_ )
      : ($_);
    $grams{$key} = [@elem];
}

# generate output hash of anagrams where key matched > 1 word
foreach ( grep { scalar( @{$_} ) > 1 } values(%grams) ) {
    @elem = @{ $_ };
    $key = shift(@elem);
    $output{$key} = join( ', ', @elem );
}

foreach ( sort( keys(%output) ) ) {
    say join( ': ', $_, $output{$_} );
}
exit;
The code uses some Perlisms (hashes of arrays, heavy use of list context and the grep filter function, the @{ … } array dereference operator [aka rose]) but should be fairly clear. References are the nearest thing that Perl gets to pointers. You know you've done something wrong with a reference when Perl spits out something like ARRAY(0xcd3a28) instead of the data you wanted.

Running this on a Raspberry Pi Zero:
  • takes about 7½ seconds
  • uses a little under 19 MB or RAM (if /usr/bin/time keeps good stats)
  • scans a 920 KB words file with a little over 99,000 entries
  • roughly 63,000 words from the list pass the “no proper nouns, no possessives” test, which I've assumed to be matched by /^[a-z]+$/
  • of those, around 7800 anagrams are found with ~3500 distinct forms / lines of output.
Note that nowhere do I know anything explicit about the input data. I don't allocate any memory, and I don't make any assumptions about how many lines, how many words or how many anagrams match each pattern. Perl does all that, and I'd far rather it did than me trying to hash arrays of unknown length in C without memory leaks. Many user processes use much more memory than my little program (the desktop 30x as much, VNC services 3x as much), and while it could be a bit quicker, it's hardly worth the bother.

(And why do I do this? To get better at Bananagrams. No, seriously …)
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

jahboater
Posts: 4595
Joined: Wed Feb 04, 2015 6:38 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 8:38 pm

scruss wrote:
Sat Jul 13, 2019 8:01 pm
rather it did than me trying to hash arrays of unknown length in C without memory leaks.
I think I would just mmap the dictionary and keep scanning that ? No need to allocate any memory.

User avatar
Imperf3kt
Posts: 2547
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 9:22 pm

scruss wrote:
Sat Jul 13, 2019 7:03 pm
[*]Energy efficiency of your programs matters very little. If you spend ages writing code for a little time running it, you've still used a load of energy sitting thinking while you code/debug.
[/list]
For example, my desktop + monitor draws 60 W idle or 100 W with one of its eight cores at 100%. So an hour of coding is about the same energy use as 36 minutes of run time.
There is one major flaw in this logic; it breaks down when there's more than one user of said code.
If you spend an hour coding something, and you spread that via the internet, how many million other people will run that code?
55:55:44:44:4C
52:4C:52:42:41

Heater
Posts: 12969
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 9:26 pm

hippy,
There are no data or data structure pointers in Python but it is possible to have function pointers which come in handy. That allowed me to create a quite elegant Finite State Machine design with Python.
Hey, can you post a little example of your elegant FSM in Python?

I'm no frequent Python user but a little while ago I want to create an FSM in Python. Try as I might I could not see an elegant way of doing it. I found a ton of examples on the net of course, they all seemed clunky and obscuring of the problem.

Perhaps you have something there that shows I totally missed the point! :)

But remember folks: Using Python causes global warming and climate change.

User avatar
scruss
Posts: 2356
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 10:24 pm

jahboater wrote:
Sat Jul 13, 2019 8:38 pm
I think I would just mmap the dictionary and keep scanning that ? No need to allocate any memory.
You're going to have to do a heck of a lot of scanning to find where the lines start and stop, and then run a regex on each one to see if it matches the definition of a word or not.
Imperf3kt wrote:
Sat Jul 13, 2019 9:22 pm
There is one major flaw in this logic; it breaks down when there's more than one user of said code.
If you spend an hour coding something, and you spread that via the internet, how many million other people will run that code?
Based on years of previous experience, roughly 1µmillion … :D
If I wrote popular code and people found it inefficient, they'd be free to port it to something better. Most code is throwaway rather than for the ages (look at poor old _why's last communication: programming is rather thankless. u see your works become replaced by superior ones in a year. unable to run at all in a few more)
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

jahboater
Posts: 4595
Joined: Wed Feb 04, 2015 6:38 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 10:46 pm

scruss wrote:
Sat Jul 13, 2019 10:24 pm
jahboater wrote:
Sat Jul 13, 2019 8:38 pm
I think I would just mmap the dictionary and keep scanning that ? No need to allocate any memory.
You're going to have to do a heck of a lot of scanning to find where the lines start and stop, and then run a regex on each one to see if it matches the definition of a word or not.
I think that could be done with a single scan, the search regex will just include the newlines as '\012'.
Treat the entire file as one large string. Also the regex code will likely have a special case optimization for this.

The perl code will have to do something similar will it not? even if its not visible to the user.

Interesting problem :)

hippy
Posts: 5595
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 10:50 pm

Heater wrote:
Sat Jul 13, 2019 9:26 pm
hippy,
There are no data or data structure pointers in Python but it is possible to have function pointers which come in handy. That allowed me to create a quite elegant Finite State Machine design with Python.
Hey, can you post a little example of your elegant FSM in Python?

I'm no frequent Python user but a little while ago I want to create an FSM in Python. Try as I might I could not see an elegant way of doing it. I found a ton of examples on the net of course, they all seemed clunky and obscuring of the problem.

Perhaps you have something there that shows I totally missed the point! :)

But remember folks: Using Python causes global warming and climate change.
Okay, but I hope we don't fall out over definitions of elegant.

For me that meant ease of actually creating the states, ensuring the flow is correct, minimal effort in making it work.

I have states where .Init is called when that state starts, .Loop repeatedly called while it's running, .Timedout if there is a timeout, and .Exit when a state ends. Just don't set the ones not needed. This just bounces between two states every 3 seconds.

I am sure there's some even more elegant 'class' way to do it rather than copy-and-pasting and renaming for new states. But it worked out nicely for my status / reboot / shutdown button handler.

Code: Select all

#!/usr/bin/python2
# -*- coding: utf-8 -*-

# *****************************************************************************
# *                                                                           *
# *     Simple Finite State Machine Framework Example                         *
# *                                                                           *
# *****************************************************************************

import time

# *****************************************************************************
# *                                                                           *
# *     States                                                                *
# *                                                                           *
# *****************************************************************************

state   = None          # Current state
timer   = 0             # Timeout timer

MS_LOOP = 100           # Loop time (ms)

# .---------------------------------------------------------------------------.
# |     First State                                                           |
# `---------------------------------------------------------------------------'

def First():
  First.Init     = "First_Init"     , First_Init
  First.Loop     = "First_Loop"     , First_Loop
  First.Exit     = "First_Exit"     , First_Exit
  First.Timedout = "First_Timedout" , First_Timedout

def First_Init():
  SetTimeout(3000)

def First_Loop():
  pass

def First_Exit():
  pass

def First_Timedout():
  SetState(Second)

# .---------------------------------------------------------------------------.
# |     Second State                                                          |
# `---------------------------------------------------------------------------'

def Second():
  Second.Init     = "Second_Init"     , Second_Init
  Second.Loop     = "Second_Loop"     , Second_Loop
  Second.Exit     = "Second_Exit"     , Second_Exit
  Second.Timedout = "Second_Timedout" , Second_Timedout

def Second_Init():
  SetTimeout(3000)

def Second_Loop():
  pass

def Second_Exit():
  pass

def Second_Timedout():
  SetState(First)

# *****************************************************************************
# *                                                                           *
# *     State Handling                                                        *
# *                                                                           *
# *****************************************************************************

# .---------------------------------------------------------------------------.
# |     Call a state handler                                                  |
# `---------------------------------------------------------------------------'

def Execute(state):
  if state != None:
    try:
      Trace(state[0])
      state[1]()
    except:
      pass

# .---------------------------------------------------------------------------.
# |     Report where we are at for debugging                                  |
# `---------------------------------------------------------------------------'

lastTrace = ""

def Trace(s):
  global lastTrace
  if s != lastTrace:
    lastTrace = s
    print(s)

# .---------------------------------------------------------------------------.
# |     Set a new state                                                       |
# `---------------------------------------------------------------------------'

def SetState(newState):
  global state; state = newState
  global timer; timer = 0
  if state != None:
    try:
      state.InitialisedFlag
    except:
      state.InitialisedFlag = True
      state()

# .---------------------------------------------------------------------------.
# |     Set a timeout for when the state.Timedout event will be invoked       |
# `---------------------------------------------------------------------------'

def SetTimeout(ms):
  global timer; timer = ms

# .---------------------------------------------------------------------------.
# |     Check if timedout                                                     |
# `---------------------------------------------------------------------------'

def Timedout():
  global timer
  time.sleep(MS_LOOP * 0.001)
  if timer > 0:
    timer = timer - MS_LOOP
    if timer <= 0:
      timer = 0
      return True
  return False

# .---------------------------------------------------------------------------.
# |     Finite State Machine Dispatcher                                       |
# `---------------------------------------------------------------------------'

def FSM(initialState):
  SetState(initialState)
  try    : Execute(state.Init)
  except : pass
  while state != None:
    last = state
    try    : Execute(state.Loop)
    except : pass
    if state == last:
      if Timedout():
        try    : Execute(state.Timedout)
        except : pass
    if state != last:
      try    : Execute(last.Exit)
      except : pass
      try    : Execute(state.Init)
      except : pass

# .---------------------------------------------------------------------------.
# |     Start Finite State Machine                                            |
# `---------------------------------------------------------------------------'

if __name__ == "__main__":
  FSM(First)

User avatar
Michiel O.
Posts: 178
Joined: Mon Dec 12, 2016 12:06 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 11:13 pm

C optimizes for computer time, while Python optimizes for developer time. In the past decades computer time has dropped in price where development has become more expensive. It is therefore more efficient to write Python, since you will arrive at a working product earlier. Only a few niche applications need the blazing speed of C, like for example, high speed trading, or an operating system kernel.

Code: Select all

Why is everyone from science schools so obsessed with Perl and Python
Perl died long ago as an active language. Nobody chooses Perl anymore when a new software system has to be built. You might better ask yourself why JavaScript has become so popular.
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

User avatar
Douglas6
Posts: 4711
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sat Jul 13, 2019 11:18 pm

Michiel O. wrote:
Sat Jul 13, 2019 11:13 pm
You might better ask yourself why JavaScript has become so popular.
I ask myself that all the time.

Heater
Posts: 12969
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sun Jul 14, 2019 4:25 am

Douglas6,
Sigh. Another "my language is better than your language" thread. What strikes me about this one is the OP's unsubstantiated 20x - 100x performance improvement claim. Any real-world evidence?
Sure.

Recently I and others were toying with programs to calculate Fibonacci numbers in various languages. Not so much looking for speed but rather simplicity in writing (and reading) the code.

Anyway here are the results for doing the same calculation in C and Python:

Code: Select all

$ time  ./fibo_karatsuba  | tail -c 100
180149736853685001275152076875379936330930391815964864885353407167474856539211500699706378405156269

real    0m0.238s
user    0m1.063s
sys     0m0.141s

$ time python3 ./fibo.py  | tail -c 100
379936330930391815964864885353407167474856539211500699706378405156269
Run time = 0.6584830000065267

real    0m16.971s
user    0m16.891s
sys     0m0.078s
I make that C being 71 times faster than Python. For this reason I often quip that Python causes climate change and global warming.

All code for the above little demo here: https://github.com/ZiCog/fibo_4784969
I ask myself that all the time.
Sigh. There you go bashing a programming language, exactly the thing you were sighing about above.

Having used Javascript a lot and Python on and off I really cannot see how enthusiasts of one of them have got any ground to stand on from which to bash the other. They are both slow interpreted languages of similar semantic capabilities.

Javascript does have the following advantages which are not directly to do with the actual language itself:

1) A rigorous specification and international standard.
2) Multiple vendors.
3) More stable (No language changes that break everyone's code See 1 above).
4) Usually faster.
5) More easily deployed.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sun Jul 14, 2019 4:31 am

sitting back giggling at the conversation.

So it is that one of the arguments in favor of Python is that it is as simple as Basic while being more capable than Basic.

Yet we have in BBC Basic (the ARM native Basic) pointers that are as flexable as those of C while being easier to use.

We also have Pointers in ANSI Basic (just read up again on that language), and many other Basic interpreters and compilers have pointers.

And now the arguments are that if you wish to use pointers you should not be using Python? Yet pointers are the most natural ellement of programming, they are everywhere in programming, and easier to understand than the abstraction of a variable on which they are built.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Return to “C/C++”