Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
redleader
Aug 18, 2005

Engage according to operational parameters
hot take: if you're new to programming, you should not be learning c

Adbot
ADBOT LOVES YOU

cinci zoo sniper
Mar 15, 2013




redleader posted:

hot take: if you're new to programming, you should not be learning c

bbut i heard it can big the data fast

Cybernetic Vermin
Apr 18, 2005

redleader posted:

hot take: if you're new to programming, you should not be learning c

if you're going to teach people programming in some broad sense sure, but there is a certain presumptuous air to dictate the way someone who actually does just want to learn some c should do so. it is not like it is an entirely illegitimate thing to want to do

gonadic io
Feb 16, 2011

>>=
but but the machine

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

cinci zoo sniper posted:

bbut i heard it can big the data fast

oh poo poo, he knows the secret.

Fiedler
Jun 29, 2002

I, for one, welcome our new mouse overlords.

Cybernetic Vermin posted:

if you're going to teach people programming in some broad sense sure, but there is a certain presumptuous air to dictate the way someone who actually does just want to learn some c should do so. it is not like it is an entirely illegitimate thing to want to do

No, one should learn C only reluctantly and after carefully eliminating all reasonable alternatives.

Max Facetime
Apr 18, 2009

yeah you definitely should not learn the single PL capable of accommodating every other PL

instead you should learn one of those other PLs

Xarn
Jun 26, 2015

C++ code:
    if(array) free(array);
:v:

C++ code:
DArray_resize(array, array->max + array->expand_rate)
O(N) insert at the end :suicide:

-------edit--------
C++ code:
#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
:tif:


-----edit-----
Reading through the rebuttal and that person is defending C strings... :v:

Xarn fucked around with this message at 15:22 on Nov 24, 2017

comedyblissoption
Mar 15, 2006

does a C book even exist that properly tells you about all the UB and memory corruption horrors inherent in the language or are such lessons only learned by banging your head over decades from an initial naivete of thinking C was simple and you were smart enough not to make mistakes

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
my hot take: people who think they are familiar with the pitfalls of c are even more dangerous than cautious beginners or zed shaw

esp. anyone who talks about how c is a "portable assembler" because it has an obvious mapping to machine instructions

Doom Mathematic
Sep 2, 2008

comedyblissoption posted:

an initial naivete of thinking C was simple and you were smart enough not to make mistakes

This isn't so much an initial naivete as it is existing C programmers telling newcomers outright that "C is simple" and advising them that the best way to avoid bugs is "don't write bugs".

akadajet
Sep 14, 2003


quote:

So far, The Unwired says that only Sony's browser supports floating touch even the home screen is tap-only, and no other apps have been rebuilt to support it. However, it seems to work well...

Android has always been about half baked implementations.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Doom Mathematic posted:

This isn't so much an initial naivete as it is existing C programmers telling newcomers outright that "C is simple" and advising them that the best way to avoid bugs is "don't write bugs".

people think this is a joke but no, this was genuine, honest advice i have received from a tenured professor

raminasi
Jan 25, 2005

a last drink with no ice
i got that from a BA when i told him the next sprint wouldn’t have as many features because we were setting up a new way of testing. “i don’t understand why you write code to catch bugs, just don’t write bugs”

Cybernetic Vermin
Apr 18, 2005

Internet Janitor posted:

my hot take: people who think they are familiar with the pitfalls of c are even more dangerous than cautious beginners or zed shaw

esp. anyone who talks about how c is a "portable assembler" because it has an obvious mapping to machine instructions

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Max Facetime posted:

yeah you definitely should not learn the single PL capable of accommodating every other PL

instead you should learn one of those other PLs

call me selfish but I'd rather be blood type ab+ than o-

Cybernetic Vermin
Apr 18, 2005

on some level i like zed shaw for the same reasons i like yospos. glimmers of deep competence diluted by overreaching pseudo-intellectualism, saved by some thought lent to the human in the middle of the computer mess, and redeemed by giving up computer-touching for art (in zed shaws case to instead learn to play the guitar and to paint)

also for harmless trolling of people who need it

Max Facetime
Apr 18, 2009

comedyblissoption posted:

does a C book even exist that properly tells you about all the UB

the thing about UB is that it’s undefined only by definition; a real Computer Scientist observes, measures and finally documents that which has thus far lacked definition

comedyblissoption posted:

and memory corruption

apart from things like rowhammer and wearing out flash memory through repeated writing, there’s not really any ways to actually corrupt memory; you write 1s and 0s and that’s all you’ll get back when reading

comedyblissoption posted:

horrors inherent in the language

I dunno what this book part could say

“if the shackles you have made for yourself are burdensome, then cast them aside“, perhaps

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

zed shaw has the same problem a lot of consistently-wrong people (ok, all of us) do. "oh you guys thought I was serious? i was just trolling, i'm so clever" like ok person, i believed you the first dozen times you pulled that, but i'm starting to get the inkling that really youre just a blowhard

he's like the stereotype of the computer toucher. for example, iirc he had some valid criticisms of python 3, but no awareness of the fact that you can't be a complete autist when dealing with actual human people, so he surprisingly got no traction. yeah yeah meritocracy, but you know you've got to live and work with others

Soricidus
Oct 21, 2010
freedom-hating statist shill

Thermopyle posted:

zed shaw has the same problem a lot of consistently-wrong people (ok, all of us) do. "oh you guys thought I was serious? i was just trolling, i'm so clever" like ok person, i believed you the first dozen times you pulled that, but i'm starting to get the inkling that really youre just a blowhard

he's like the stereotype of the computer toucher. for example, iirc he had some valid criticisms of python 3, but no awareness of the fact that you can't be a complete autist when dealing with actual human people, so he surprisingly got no traction. yeah yeah meritocracy, but you know you've got to live and work with others

on behalf of autists everywhere, i must object to you using that word to refer to someone who writes things like "It’s the language for old programmers who want to debate section A.6.2 paragraph 4 of the undefined behavior of pointers. Good riddance", or "a bunch of closed minded conservatives who’s [sic] only joy in life is feeling like they know more about a pedantic pathetically small topic like C undefined behavior". a man who does not enjoy arguing over the minutiae of technical topics is unworthy of the title

also there is no section A.6.2 in the c standard. undefined behavior is J.2. or he might be thinking of 6.3.2.3, which does cover the behavior of pointers, but paragraph 4 has nothing to do with ub. fuckign owned

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Xarn posted:

C++ code:
    if(array) free(array);
:v:

i only learned about "free() takes null pointers without failing" thing like a year ago because it's really unlike C to not do anything on a null ptr. nothing else does that

Xarn posted:

C++ code:
DArray_resize(array, array->max + array->expand_rate)
O(N) insert at the end :suicide:

where's the O(N) insert?

Suspicious Dish fucked around with this message at 18:34 on Nov 24, 2017

Xarn
Jun 26, 2015

Suspicious Dish posted:

where's the O(N) insert?

Maybe I worded it wrong? If you grow a dynamic array by fixed amount when you run out of space, your push_backs asymptotically average out to O(N) instead of O(1).

Incidentally, the ~4 guys I know personally that really, really insist on C instead of C++ each have their lovely reimplementation of std::vector and each implementation contains the same error. :shrug:

MrMoo
Sep 14, 2000

Suspicious Dish posted:

i only learned about "free() takes null pointers without failing" thing like a year ago because it's really unlike C to not do anything on a null ptr. nothing else does that

The main concern with that code snippet is no protection against double free, it should clear after free.

fritz
Jul 26, 2003

i only glanced at it but :
code:

typedef struct DArray {
    int end;
    int max;
    size_t element_size;
    size_t expand_rate;
    void **contents;
} DArray;

static inline int DArray_resize(DArray *array, size_t newsize)
{
    array->max = newsize;
    check(array->max > 0, "The newsize must be > 0.");
     ....
}
size_t is probably 64 bits, int is probably 32 bits, and putting one into the other is almost certainly not the right thing

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
oh i'm sure you guys can nitpick it to death but the article author says "introducing some over-engineered, poorly-written data structures, etc. Things like this and this and this would be enough to make a C programmer cringe..."

this isn't over-engineered or poorly-written. it has some bugs but literally all C code has bugs like this. turns out nobody uses an array with more than 2,147,483,647 items

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
also the nitpick of "learn c the hard way" completely misses the point of that book. that book tries to skip over dumb nitpicky details and saves them for when they actually matter. so him pointing out every time he misses a detail and saves it for later is really just pointing out all the places the book follows its own philosophy.

you might *disagree* with this methodology (i think its a good idea!) but the nitpick ends up looking snarky and is basically useless

fritz
Jul 26, 2003

Suspicious Dish posted:

oh i'm sure you guys can nitpick it to death but the article author says "introducing some over-engineered, poorly-written data structures, etc. Things like this and this and this would be enough to make a C programmer cringe..."

this isn't over-engineered or poorly-written. it has some bugs but literally all C code has bugs like this. turns out nobody uses an array with more than 2,147,483,647 items

laffo if you think i read anything past "what's wrong with this code"

Volte
Oct 4, 2004

woosh woosh
guys, guys..you're TOTALLY missing the point of "learn to drive the hard way"

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Suspicious Dish posted:

also the nitpick of "learn c the hard way" completely misses the point of that book. that book tries to skip over dumb nitpicky details and saves them for when they actually matter. so him pointing out every time he misses a detail and saves it for later is really just pointing out all the places the book follows its own philosophy.

you might *disagree* with this methodology (i think its a good idea!) but the nitpick ends up looking snarky and is basically useless

it's been a while since I tried to read the book, I had minimal experience with C back then but the thing that struck me is that it was extremely nitpicky over a lot of poo poo that doesn't matter (or at least didn't matter to me). it was an annoying defensive style, and people nitpicked it that actually it wasn't all that defensive as he claimed it to be.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Suspicious Dish posted:

that book tries to skip over dumb nitpicky details and saves them for when they actually matter. so him pointing out every time he misses a detail and saves it for later is really just pointing out all the places the book follows its own philosophy.

I totally agree with this intent, but LCTHW just isn't it. Suspicious Dish please write the C book.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
yeah, not defending zed's book (i haven't read it beyond a few chapters), just pointing out that more nitpicking is not the correct response.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
also no way in hell i'm gonna write a C book because i dont want the nitpick squad after me

i only write about things that are small enough that nobody else really knows better, like linux graphics or webassembly.

gonadic io
Feb 16, 2011

>>=
I love it when my desktop apps are vulnerable to web exploits

https://statuscode.ch/2017/11/from-markdown-to-rce-in-atom/

redleader
Aug 18, 2005

Engage according to operational parameters

Max Facetime posted:

yeah you definitely should not learn the single PL capable of accommodating every other PL

instead you should learn one of those other PLs

not as your first lang

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

another "programming education should start with logic gates" vs "programming education should start with SICP' argument's a-brewin

VikingofRock
Aug 24, 2008




Suspicious Dish posted:

also no way in hell i'm gonna write a C book because i dont want the nitpick squad after me

Make it an internet book, host it on GitHub, put up a mostly-correct draft, and then the nitpick squad will write the rest of the book for you

Xarn
Jun 26, 2015

Suspicious Dish posted:

this isn't over-engineered or poorly-written. it has some bugs but literally all C code has bugs like this. turns out nobody uses an array with more than 2,147,483,647 items

Last person who never needed index larger than int has cost me 2 days of debugging for no reason, gently caress you! :v:


Anyway, I admit that I gave it similar amount of attention I give students' seminar work. This means that nitpicks get included, but without penalization, more of a "hey, you can write this more nicely the next time". In this context,
C++ code:
if (ptr) free(ptr);
is a nitpick that results in "hey, you can free null pointers just fine". I'd expect better from someone who wrote a book teaching C, but whatever, maybe he is super greybeard who once got bitten by Version 6 Unix (hope I got the version right :v:).

In similar vein, I once sent a long-rear end explanation of how to have header dependencies in makefile autogenerated to a student who had explicit header dependencies in his makefile... It actually earned him bonus point, as only two students figured out that headers are dependencies too, but I felt he could benefit from the explanation.


In this light, O(N) push back on a dynamic array would get a lengthy explanation of why it is bad, how to fix it, and why it is important, but relatively minor penalty. OTOH non-conditionally zeroing errno in a macro would get huge point penalty (or maybe just "unacceptable, fix it"), because we spend the whole semester repeating that correctness is the first and foremost priority, and you DO NOT ignore errors. :shrug:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
at some point i should finish this but i had way too much fun writing the code editor hoping that by the time i wrote that i'd figure out what to use it for

i was wrong

https://magcius.github.io/xplain/article/rast2.html

Max Facetime
Apr 18, 2009

redleader posted:

not as your first lang

programming a micro controller to make a row of LEDs blink in C, without abstracting away the access patterns that actually do things, should be fun

certainly UB and memory corruption would be much less of issues with behavior right away observable and all memory yours and yours alone

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters

Max Facetime posted:

programming a micro controller to make a row of LEDs blink in C, without abstracting away the access patterns that actually do things, should be fun

certainly UB and memory corruption would be much less of issues with behavior right away observable and all memory yours and yours alone

oh, fair call (i'd forgotten about embedded/actual physical devices, lol). i was thinking more in terms of a 'make computer do things' language. while serving a valuable purpose about show how computers work at a lower level (pointers et al), i don't think it's a great language to start with computers

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply