I run a small dev company. This is the first lessons we teach our programmers. If your code cant be understood by someone else with minimal efforts it is not good enough.
Do you maintain a high-enough level within the team though? Most "clever code" I've seen is called clever by people who are not yet proficient enough in a language to understand it. So with unskilled programmers pretty much anything that isn't straight combination of classes, loops and conditionals will be considered clever. There's a tradeoff here - I get the business reasons why one may want to have the codebase at…
Why most “clever” code ain’t so clever after all
21–30 of 104 posts
Re: Why most “clever” code ain’t so clever after all
#22Your API should strive to be clever (it should allow end users to do countless things straightforwardly without error). Your implementation should not.
Re: Why most “clever” code ain’t so clever after all
#23 for(var i in list) {
(function(element) {
someAsyncCallThatNeedsTheRightIndexedElement(element);
})(list[i]);
}
I've seen people grumble that this is "too clever"I've been known to snap back "Bootcamps don't have a monopoly on what technical solutions are valid"
Pointers are probably too clever for most people.
Admittedly, goto is too clever for me. :(
Re: Why most “clever” code ain’t so clever after all
#24 fizzbuzz' :: Int -> String
fizzbuzz' n = (test 3 "fizz" . test 5 "buzz") id (show n)
where
test d s x | n `mod` d == 0 = const (s ++ x "")
| otherwise = x
fizzbuzz :: [String]
fizzbuzz = map fizzbuzz' [1..]
The article is very interesting and worth a read. In particular, this implementation doesn't come out of "thin air": it's been golfed from an implementation that defines a simple domain specific language to solve FizzBuzz. And if you understand your problem well enough, DSLs are an extreme force multiplier.Re: Why most “clever” code ain’t so clever after all
#25Not the OP of the article. Just wanted to get perspective from Haskell devs on the points raised in the article.
https://gist.github.com/anonymous/7a1829f61cf9302c188f80a736...
Re: Why most “clever” code ain’t so clever after all
#26Earlier quoted context omitted.
Do you maintain a high-enough level within the team though? Most "clever code" I've seen is called clever by people who are not yet proficient enough in a language to understand it. So with unskilled programmers pretty much anything that isn't straight combination of classes, loops and conditionals will be considered clever. There's a tradeoff here - I get the business reasons why one may want to have the codebase at…
Not every company wants highly skilled programmers. Depending on the complexity of the project, and cost of defects unskilled programmers may be the most cost effective.
Re: Why most “clever” code ain’t so clever after all
#27I've seen some weird-ass calculations in code with no comments. If the author has gone through so much effort to come up with the clever solution why not add some commentary so the next guy can read it quickly.
That's why every language has support for comments..
Re: Why most “clever” code ain’t so clever after all
#28for(var i in list) { (function(element) { someAsyncCallThatNeedsTheRightIndexedElement(element); })(list[i]); } I've seen people grumble that this is " too clever " I've been known to snap back " Bootcamps don't have a monopoly on what technical solutions are valid " Pointers are probably too clever for most people. Admittedly, goto is too clever for me. :(
Re: Why most “clever” code ain’t so clever after all
#29Re: Why most “clever” code ain’t so clever after all
#30for(var i in list) { (function(element) { someAsyncCallThatNeedsTheRightIndexedElement(element); })(list[i]); } I've seen people grumble that this is " too clever " I've been known to snap back " Bootcamps don't have a monopoly on what technical solutions are valid " Pointers are probably too clever for most people. Admittedly, goto is too clever for me. :(