Timeline for Is interleaving local variable declarations with assertions and function calls a bad practice?
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 15, 2023 at 12:20 | comment | added | Greg Burghardt |
Ok, I think I see now. You are asking two separate questions about two different styles of writing a function. I thought there was a connection between test_function_1 and test_function_2 -- there isn't. Two different examples.
|
|
Sep 15, 2023 at 11:38 | comment | added | Alexander | @SeveroRaz Ah I meant to type C99, but now I realize they're actually going to C11. Cool | |
Sep 15, 2023 at 9:34 | comment | added | Severo Raz | @Alexander thanks for elaborating. In your last sentence, I presume you're referring to the recent decision to use C11 instead of C89 for the Linux kernel, right? | |
Sep 14, 2023 at 23:18 | comment | added | Alexander | @SeveroRaz there’s pretty much no upside, besides “it makes the compiler’s stack allocator simpler to implement”. It’s all downsides: 1) needless distance from decl to use, 2) extra lines of code, which isn’t necessarily a bad thing, but it definitely is here, since those lines are completely redundant boilerplate, 3) and most importantly, it unnecessarily increases the chance of bugs, caused by scoping variables more widely than necessary. Case in point: as conservative as the Linux code as is, they’re moving C9, primarily for tighter scoping of loop variables. | |
Sep 14, 2023 at 22:47 | comment | added | Severo Raz | @GregBurghardt in the context of C, the concept of "side effects" generally implies that an operation affects the state of the program in some way. I have used it in the names of my functions to imply that one of the functions may affect the value returned by the other. | |
Sep 14, 2023 at 22:45 | comment | added | Severo Raz | @Alexander are you saying it's bad practice because it enforces distance between the declaration and the usage of a symbol? | |
Sep 14, 2023 at 22:42 | vote | accept | Severo Raz | ||
Sep 13, 2023 at 19:09 | comment | added | Alexander | "it is customary to place local variable declarations at the beginning of their scope." This was forced by a limitation of the language that was fixed over 20 years ago (in C99, IIRC). It's obsolete and bad practice today. | |
Sep 13, 2023 at 19:07 | comment | added | Ccm | It's best to validate input parameters as soon as possible. There is no practical reason not to, unless validation is non trivial. | |
Sep 13, 2023 at 17:44 | answer | added | candied_orange | timeline score: 5 | |
Sep 13, 2023 at 17:35 | review | Close votes | |||
Sep 19, 2023 at 3:03 | |||||
Sep 13, 2023 at 15:52 | comment | added | Greg Burghardt | I don't write C, so I might be missing something that experienced C developers just intrinsically know, but how are the two functions in your question related? | |
S Sep 13, 2023 at 14:10 | review | First questions | |||
Sep 13, 2023 at 14:55 | |||||
S Sep 13, 2023 at 14:10 | history | asked | Severo Raz | CC BY-SA 4.0 |