6 ms·
It reminds me of a typical code written by scientists. IMHO there is the biggest gap between the raw intelligence and software engineering skills (including go
by stared 7y ago
It reminds me of a typical code written by scientists.
IMHO there is the biggest gap between the raw intelligence and software engineering skills (including good practices). So, it means that most of the code ends up as code-golf-style contraptions, incomprehensible for anyone else (including their future themselves).
Full disclaimer: I used to be that guy who liked "clever hacks". Now I try to make code readable in the first place (largely thanks to Python philosophy).
- perl4ever 7y agoThis. I'm not saying I know much about good software engineering practices, but I used to be interested in amateur astronomy and spent time translating Fortran and BASIC code written by astronomers to C, and it was awful bordering on enraging. Several years ago I discouraged someone who called me about a job supporting supercomputing applications for scientists - perhaps subconsciously due to this prejudice.
- edmundhuber 7y agoYou shouldn't feel bad about this, you might have saved someone from a lifetime of fixing wacky science bugs in exchange for not a lot of money.
- perl4ever 7y ago>someone Me?
- jimws 7y agoI am one of those who moved from Perl to Python. As a Perl coder I loved writing clever hacks. After a few months of Python I began appreciating simplicity and elegance in code.
- Balgair 7y agoI'll second this. One grad student friend of mine traded me a case of beer for a Saturday of help on his code. It was some code to record spike timings in the olfactory cortex and also control valves (smelly research). By the 12th nested for-loop, I gave him back the beer.
- stared 7y agoNested 12 loops, is this part of not-so-smart code. Less code-golf, more hackathon-style "one more copy-paste and it should work". It has some use cases, just readability or maintainability are not among these.
- hinkley 7y agoI was helping a guy with some text-based game he was working on that had some pretty clever bits of code for constructing scene description text. The problem was that once in a while you'd just get some garbled text on the screen. Eventually I figured out why: Some of the sentence fragments were malloc'ed, others were returned from the stack. Once the description got over a certain number of bytes he was smashing his own stack. I say 'his' but the problem was introduced by an earlier collaborator. Buddy, I really want to help you with this but I (much younger me) am not up for unwinding a use-after-free bug of this level of recursion. Good luck, I'm out.
- hinkley 7y agoI thought this story was going to end with you consuming the beer on the spot. On several occasions, and with lesser crimes, I've told the person something like "I think you are confusing yourself with your own code. I want you to change to meaningful variable names (stop recycling variables) and factor out a couple of child functions here, and here. If you still can't see the problem, come get me and we'll try this again."
- Balgair 7y ago> I thought this story was going to end with you consuming the beer on the spot. Haha, no way. Grad students are poor as is. Drinking a month's beer budget in front of the guy would be bad, leaving him with that code was cruel enough.
- xvector 7y agoI remember in college, even Python often turned into "code golf" style competitions. Could we collapse this 10-line block into an incomprehensible nested list comprehension? Why not!? Surely 1 line is better than 10 lines! Later in college when we started doing more team projects, comprehensible code became much more important. No one had the time to understand someone's doubly-nested list comprehension. We just wanted to finish the project and get on with life. In this sense, I think the moment you read someone else's shitty code is the moment you realize that you need to write good code yourself. Still, I'd say it was good practice and helped me think about code in different ways.
- cwp 7y agoThere is an element of relativity to this though. I guarantee that there are programmers and teams for whom nested list comprehensions are much more comprehensible than 10 lines of loop code that could be doing anything and have to be carefully analyzed to be understood. This holds for just about any programming technique that you might encounter. Of course, Kernighan's law still applies, it's just that the definition of "too clever" recedes with skill and experience.
- Gibbon1 7y agoA counter is a saw a blog post by a CS professor picking apart of a single line implementation of the Sieve of Eratosthenes. She points out the first clue is that it's performance is bad, like really really bad. And then shows it's not actually implementing the Sieve of Eratosthenes. I might just be dumb but I've been bitten so many times I'm dubious anything can be verified by inspection.
- tyurok 7y agoI have experienced this. The most brilliant programmer I've ever worked with wrote hardly comprehensible code since they could understand other's code easily, so they didn't feel the need to write readable code because, in their word, "What do you mean you don't understand it? It compiles, it runs, it works, you don't need more than that".
- stared 7y ago