I'm thinking start with printf and input from command line args only (to avoid scanf awfulness & need to learn arrays+strings enough to use fgets & to mimic how real cmdline tools work)...
-
Show this thread
-
Of course you need some minimal intro of arrays to do argv[i], just passing to strtol/strtod at this point though.
1 reply 0 retweets 0 likesShow this thread -
Then do as much as makes sense (student interest, time available, etc.) without strings - expressions, conditionals, loops, functions, ...
1 reply 0 retweets 0 likesShow this thread -
Replying to @RichFelker
TA'ing an OS course with C beginners, they really needed to learn defensive programming: 1) Reading docs for function 2) Handling every return value 3) Cleaning up even in error conditions 4) Returning unsuccessfully appropriately from the current function.
2 replies 1 retweet 1 like -
Replying to @sortiecat @RichFelker
Defensive programming is such a key part of how you write C properly. It also teaches good reasoning about code and forces students to actually think about every single case. The students I TA'd had not learned this skill, and my attempt at requiring it was somewhat unsuccessful.
3 replies 1 retweet 3 likes -
Replying to @sortiecat @RichFelker
Please call this "safe programming", not "defensive programming", which is an anti-pattern (doing extra checks, adding \0 to strings, etc., "just to be sure" instead of properly analyzing what should be done). Your suggestions are about safety, which is definitely essential.
1 reply 0 retweets 0 likes -
Replying to @laurentbercot @RichFelker
Oh I thought "defensive programming" was the term for handling each potential case (including error cases). The "just to be sure" I call "cargo cult programming". I'm unclear how defensive programming has become tainted with cargo cult connotations?
2 replies 0 retweets 1 like -
Replying to @sortiecat @laurentbercot
Agreed. Analog of "defensive driving". Doesn't mean you're doing superstitious stuff to protect yourself. Means you have attitude that outside inputs can impose threats.
1 reply 0 retweets 1 like -
Replying to @RichFelker @sortiecat
Well I guess different parts of the world have different denominations for the same thing. I always called the practice of checking inputs "safety".
2 replies 0 retweets 0 likes -
Replying to @laurentbercot @sortiecat
To me defensive is a step or two beyond the minimal to be theoretically correct assuming you didn't make mistakes.
1 reply 1 retweet 1 like
It involves asking what happens if your assumed invariants aren't met, either internally or due to unchecked external input, and how to minimize fallout in that case.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.