General > General Technical Chat
Religious technical opinions
Siwastaja:
--- Quote from: m k on February 26, 2022, 12:10:03 pm ---I use as little indent as possible so that 10th indent is still sort of around.
--- End quote ---
Sometimes (I mean, with some special languages or weird edge cases; I can't think of any example right now, so it's not a common requirement) you need those deep indentations, of course, but if you are doing this with the usual programming languages, then the 10th (actually already the 5th or so) indentation is a severe warning sign you need to restructure your code.
I used to do indentation width of 4 and thought that 8 is absolutely ridiculous, the proof being that my lines wander up so far right. Experienced programmers were telling me to refactor the code, utilizing those fancy features like functions to divide the bigger task into smaller subtasks. And indeed they were right, the problem solved itself, and now I'm just using tab width = 8 and do not see any problem with it.
But I still remember my beginner days, and the problem with poorly structured code with deep nesting is that it tends to also suffer from long pieces of code with various levels of nesting. You can't afford large tab width because your lines end up too far right. Also you can't afford small tab width because then you easily lose track on what piece of code is on what indentation level. You just paint yourself into corner.
But when writing proper, high quality code, suddenly you see that small details like tab width / number of spaces becomes far less relevant.
Similarly, strong dependence on fancy editor features is a warning sign something is wrong with the code. With proper code, they can be helpful of course, but are again not that important.
m k:
You can easily comment those nested functions of functions away and have more meaningful descriptions than countless cryptic names.
Functions are not the answer, structures are, and objects of course.
With Microsoft you're also better of if you do wrappers.
billbyrd1945:
You're right of course (that the Apple laptop thing is merely product placement). Being slightly paranoid, thinking that most of the world thinks I should be more Apple-like in my politics, it just seems more like a nudge to get right with the world: hug someone, get more green, embrace new pronouns, all that woke stuff. All in my head I'm sure. And what does this have to do with spaces and tabs? Probably nothing. Or it could be the same thing-- a tendency to glom on to certain mindsets.
eugene:
I'm not so sure that Apple is as socially progressive as they would have you think. Remember those TV ads that got Justin Long started? The ones where he would be the Apple guy, all cool and friendly while Microsoft was represented by a stodgy business man in a grey suit?
Well, I've done contract work for both Apple and Microsoft. Apple would bully us into whatever they felt they wanted. IT was truly insulting sometimes, but they didn't care. We had to put in a completely separate shared network drive just for the stuff we did for them. This was literally different hardware from the network shares that we used for everything else. The only people that could access the drive were the ones that they authorized. Visiting their campus at 1 Infinite Loop was much like visiting a military base. There were not groups of armed soldiers marching around, but there were plenty of visibly armed security personnel. Getting into any building required showing identification. Getting into any room required an employee with a swipe card to serve as chaperone. While there, the project manager pointed to each of us one by one and said, "I like you, I don't like you, I don't like you..." WTF? I would be fired for doing something like that, but it was evidently SOP there.
Meanwhile, working with Microsoft was a very enjoyable experience. I recall one engineer saying, while on a conference call, "I hope you guys are having as much fun with this as we are." Visiting their campus was like visiting a vacation resort. There were small park-like spots scattered around outside with benches and decorative plants for a little bit of privacy. Inside there were gyms and workout rooms. They were obviously interested in their employees well being and even suggested that we could use the recreational facilities while in town.
Please make note that I am not commenting on the stuff that either Apple or Microsoft sell, or the way they treat those of us that use that stuff. I'm just commenting on the way we were treated as contractors and the general environment they set up in their workplace.
If you want my personal opinion, I am not fond of Microsoft and don't trust them, but I will never, ever support Apple in any way. Again, that is not based on their products but entirely on my view of the corporation itself.
T3sl4co1l:
--- Quote from: Siwastaja on February 26, 2022, 12:37:38 pm ---I used to do indentation width of 4 and thought that 8 is absolutely ridiculous, the proof being that my lines wander up so far right. Experienced programmers were telling me to refactor the code, utilizing those fancy features like functions to divide the bigger task into smaller subtasks. And indeed they were right, the problem solved itself, and now I'm just using tab width = 8 and do not see any problem with it.
--- End quote ---
I think the longest function I currently maintain (in my unimpressively sized personal codebase) is something like this:
https://github.com/T3sl4co1l/Reverb/blob/master/console.c
probably not a big sin in the grand scheme of things -- and also I'm not really sure how else to do it -- but it has that inelegant smell. Maybe that's just how it has to be, overlapping a state machine with a character decoder. I guess the insight then would be to split off the state machine. The two switchs could maybe be split, but they also share variables so a few things would be duplicated or passed around. Not to mention the goto... ;D
Oh, I should probably abstract away the serial calls, so it can do abstract IO calls instead. Though probably at some overhead (pointer function calls).
Shrug, things to think about next time I have it open. Oh, come to think of it, this version hasn't been patched with the couple bug fixes I've found since then, either, heh.
Anyway, a possible advantage to smaller functions, is better optimization. The compiler can only afford so much time to optimize sections of code, and large, interdependent stretches may perform quite poorly. That is, high complexity (in terms of number of clauses, cyclomatic complexity, AST depth, etc.) may limit the number of passes. (IANA compiler designer; this is probably at the right sort of thing, but not actually the most representative quantity.) These will be one-off functions not used anywhere else, so the compiler will happily inline them all for you -- presumably with whatever sequence of optimizations it finds beneficial. Hopefully including some before inlining? Anyway, even if you have to like pass around a dozen variables, or make a struct of your master-function local variables or something; once it's inlined, that's either trivial (register level), or you have enough that they go on the stack anyway so are only slightly less trivial to access remotely.
My one example of "compiler throws up its hands" was a 24 to 16-bit conversion macro, i.e. for 5-6-5 LCD color. I initially wrote everything out in one uber-expression, using a few macros to expand a fairly simple expression into, something like 5 or 6 lines all written out. GCC didn't like that. :-DD At least not for AVR.
Tim
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version