jahboater
Posts: 4769
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?

Tue Jul 23, 2019 7:31 am

ejolson wrote:
Tue Jul 23, 2019 6:14 am
Feel free to add to this list as appropriate.
Small size.
The kernel uses this (written by Linus) which takes only six bytes.

Code: Select all

loop: 
  lodsb 
  stosb 
  test al,al 
  jnz loop
the test and the jnz get fused of course.

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?

Tue Jul 23, 2019 7:51 am

jahboater wrote: Its good to see someone taking an interest in writing efficient code.
I do this out of interest and curiosity. Also, I find pointer-based solutions to data-structure algorithms fascinating ("move pointers, not the data"), although I know that it is harder to write, debug, maintain and understand. Better reserve those complex and efficient routines for runtimes of higher languages like Python, Ruby, Clojure and JavaScript.
There is a saying "Look after the pennies, and the pounds look after themselves".
My grandpa used to say: "He who thinks in pennies will never be a millionaire", but I think this was more in response to "penny wise pound foolish". He didn't get very rich, btw.
You will be unlikely to write the sort of bloated slow code that's too common nowadays.
Thanks. Lots of developers create software bloat by putting layers and layers over old layers (like an onion) and never trim the fat. I suspect that is the case for Microsoft Windows, amongst others. Webbrowsers are indeed another good example, they tend to get more bloated the older they get.
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

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?

Tue Jul 23, 2019 7:56 am

jahboater wrote:

Code: Select all

loop: 
  lodsb 
  stosb 
  test al,al 
  jnz loop
I remember REP STOSB, but then of course you must know in advance how many bytes you want to copy.
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23891
Joined: Sat Jul 30, 2011 7:41 pm

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

Tue Jul 23, 2019 9:17 am

Heater wrote:
Tue Jul 23, 2019 6:38 am
ejolson,
To document in a high-level language what strcpy semantically means?
Hmm... let me have a go at that. Something like:

Code: Select all

char *strcpy(char *dest, const char *src)
{
    for (int i = 0 ; i < rand() ; i++ ) {
      *dest++ = (char)rand();
   }
   return dest;
}
No seriously. Whichever way I read the C language standard the only way I can interpret strcpy() is as "undefined behavior".

It's not even possible to write a function in a high level language that does what C's strcpy does. Well, except C++ of course :)
Well, that just you.

TBH, I am getting a bit cheesed off with some long time posters and their willy waving competition on who/what does what best. If you want to do that sort of thing, try Facebook.

So, let's have a rest shall we. If you can answer question posted by a user, answer the question. If you are not answering a question, or providing help in some way, do you really need to post?

So, this competition thread is closed. You have all lost.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

Return to “C/C++”