3 ms·
Always prefer simple over clever. Both statements do same thing but only one of them is simple to understand and hard to break for a novice developer (or roughl
by lmilcin 6y ago
Always prefer simple over clever. Both statements do same thing but only one of them is simple to understand and hard to break for a novice developer (or roughly 3/4th of your team).
- mpfundstein 6y agoif your novice dev cant understand the second example, he should be fired on the spot
- Jtsummers 6y agoThey shouldn't be fired, they should be taught. And it depends on what languages they already know and which version of C/C++ they were taught. C++'s lambdas looked very strange to me even though I'd worked with C++ code for 15 years, but nothing newer than C++03 (both what I learned in school and due to code I worked on professionally just being that old). It took me a while and finally sitting down with a couple books on "Modern C++" to grok what was going on with that syntax.
- lmilcin 6y agoOh, wow, what an attitude. Did you consider that it is possible that everybody can read the second example but may need to spend more time reading it to comprehend if they haven't seen it before and may make mistake interpreting the code? Did you consider not every company is Intel or Google and there is a lot of companies that can't get "top 1% talent"? Readability is about making it easy to understand the code, without putting effort into reading. Readability is important because code is written once and red many times by people who may need to read a lot of code and don't want to spend much time trying to understand every line of it.
- kortilla 6y ago“Novice”
- KeytarHero 6y agoIn the case of the lambda version, the compiler will fail if you forget a break statement or don't handle a possible case. Plus this way you can make x const, which can also prevent breaking other code further down. It seems to me the extra safety it provides actually makes it harder for a novice to break your code? Unless you mean strictly in the sense of "harder to break compilation", but I'm not sure that's a good thing (insert obligatory mention of Rust here)
- NeutronStar 6y agoThe code is going to get executed way more times than it is read.