3 ms·
I've noticed the odd trend of people bragging about how few lines it took to do X. Seems like people are trying to equate less loc == better code, which is not
by Alupis 12y ago
I've noticed the odd trend of people bragging about how few lines it took to do X. Seems like people are trying to equate less loc == better code, which is not usually the case (better/more robust error handing and correcting, more complicated AI logic, etc).
It just means you are using a more abstracted version of whatever.
In reality, a 111 lines of Python program is likely thousands of lines if you were to count all of the standard Python libraries and/or any 3rd party libraries used.
What if I took this program, wrapped it in say, 5 lines of Python, then said I implemented chess in 5 lines of Python? Did I really? Of course not... but it makes for a good attention grabber.
- DanBC 12y ago> Seems like people are trying to equate less loc == better code No. It's a tradition that goes back a long way. When it started it was about making code better - more efficient; faster; smaller. Part of that was the limited hardware available. Now, when huge computing power is available to almost anyone, it's about the fun of finding that shortcut or that weird trick to remove a few lines of code.
- Alupis 12y agoAh, that does make sense. Like Code Golf. ;)
- Crisco 12y agoThat's exactly what it is. Code Golf is pretty fun to look at, check out the questions here: http://codegolf.stackexchange.com/ http://codegolf.stackexchange.com/ There's some cool techniques different people use to solve some seemingly major problems in just a few characters.
- chipsy 12y agoWhy not offer a specific criticism of how this program leverages Python, though?
- Alupis 12y agoI wasn't attempting to criticize this code - but merely comment on the trend I was noticing... however as DanBC pointed out, this is really more of a Code Golf exercise, which now makes more sense!
- rlpb 12y ago"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger." -- Dijkstra (https://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1036.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/E...) Clearly there's a line beyond which the code is no longer readable, but that is not to say that more lines is better, or that there is no elegance in implementing things more concisely.
- hngiszmo 12y agoThe best code is the code you don't have to write. I like these short cuts and I played and lost a game against this beauty after reading the code. He did not use any chess-specific libs. Just pure and simple python. I am proud to not contribute much to LOC counts on most of the teams I worked as I clean up a lot after my colleagues to keep code duplications low and pointless code out. Less code is normally easier to maintain as long as you follow some other coding practices and don't go and inline everything.
- qznc 12y agoIt is an indicator about the Kolmogorov complexity of chess. http://en.wikipedia.org/wiki/Kolmogorov_complexity http://en.wikipedia.org/wiki/Kolmogorov_complexity
- thomasahle 12y agoYou are of course right that less is not better. Indeed Sunfish often takes a more lengthy approach than say Micro-Max, because Sunfish is also meant to teach chess programming. Examples include: - Using an actual text representation of the board, rather than a binary. - Having separate functions for move generation, search and evaluation. - Using a python hashmap rather than a simple zobrist hash. - Using a direct piece square table rather than some compressed/generated nonsense. I do however also think, that trying to shorten the move generation of some programs, which can be hundreds or thousands of lines, to something like this, is a good exercise in finding patterns, and has a certain beauty ;)