14 ms·
> so you can just write the thing rather than your name for it I do not find this convincing. Names, especially good names, can convey additional meaning, whic
by kazinator 7y ago
> so you can just write the thing rather than your name for it
I do not find this convincing. Names, especially good names, can convey additional meaning, which is helpful even if the names are longer than what they stand for in terms of raw character count.
One obvious example is that I would often rather see a seven-letter manifest constant than the two-digit decimal literal it represents.
In a similar vein, I would rather have a structure with named fields, than array indices or offsets. employee.department is objectively better than e[13]; a compiler can generate the equivalent of the latter from the former.
In calculations that have many nodes in the syntax tree, it's helpful to break up the tree and give intermediate values names, which remains true even if the names are longer than the intermediate calculations.
A name may longer than what it denotes in raw character count, but in spite of that it may less complex due to its flat structure which only indicates "same or not". If a 13 character identifier stands for some 9 character syntax that denotes a tree with 7 nodes, the identifier is certainly simpler.
Lastly, different expressions that occur in a program can sometimes be very similar to each other. If we do not use names, then these differences can be hard to find. It might seem that identifiers which are longer than what they denote make the problem worse, but that is not necessarily so. Identifiers which are clearly different from each other can be selected for denoting forms that are very similar to each other. If instead of ((<]):) and ((<[):) I write foolyfoo and barlybar, that will be less error prone.
- alimw 7y agoYou might be right that good code needs names. But since in a terse language like J or K it may take longer to think up a good name than to write the code, it's handy that one doesn't have to have names for everything when prototyping.
- rgoulter 7y agoWhat's the cost of reading it? Just use comments to roughly convey what a line of code does, and then for more precise understanding, take the time to read through it?
- philosopher1234 7y agoEach method has its own innate complexity, the complexity of "whats this method do? when do I use it? Why would I use this method instead of a different method in this class? Now I have to dive into this method to read its implementation which pulls me out of the reading context I was in before" Also, your point about the meaning beyond the code can be served by a comment, which drops the constraint of "don't make it too long" and "write in camel case", and also allows inline code reading! There's a time and a place for everything. I reccomend "A Philosophy of Software Design" for a book that elaborates on the idea of "less and longer methods tend to be better than many concise methods". What you want to make short/simple is the API, rather than the implementation!
- sbergot 7y agoA function has a well defined scope, parameters and output. A comment does not. A function name describes an intention. Within the scope of this function, someone can check whether the intention is respected by the implementation. If this function calls other functions, just assume that they are working as their name suggests. If that is not the case, fix those other functions later. This has been my overall approach to maintaining code. To such extent that I design things around the possible names I can find. Some call that DDD. I call that respecting my team mates. Without writing and naming function, this is not possible. Languages such as J and K are fine for single developers & prototypes but really bad for bigger projects.
- sriku 7y agoThe "write the thing" attitude perhaps comes to some extent from (human) languages that have that as a natural word invention mechanism - such as German, Finnish, Sanskrit. In Sanskrit, etymologies seem to often go down to single syllables. I quite often miss that in programming languages. To some extent, functional languages let you construct functions that compose like that and we also see that happen with CSS with frameworks like Semantic-ui and Bulma. But it would be fun to have or experiment with it at the identifier level. Edit: I generally prefer to use "abstraction" to refer specifically to "beta abstraction" and not the "make named functions" kind ... Which is more about encapsulation. Beta abstraction always results in something more general and abstractions are about leaving out detail.
- smabie 7y agoI used to think the exact same things, but after using kdb+/q for AoC2019, I felt like I had a revelation. When you get rid of all abstraction, your code size is reduced so dramatically that abstraction is no longer needed. My solutions were maybe 10-100x shorter than everyone else's (except some guy's k code I found) and to this day, I can still mostly remember them, character for character (much like how an equation is easier to remember than a traditional line of code). Being able to fit all of your code in your head at once is a truly magical feeling.
- chrispsn 7y agoBTW, some examples of AoC 19 answers in k: ngn's; targets ngn/k (dude's a machine): https://bitbucket.org/ngn/k/src/master/aoc19/a.k https://bitbucket.org/ngn/k/src/master/aoc19/a.k Mine; progressively porting from k7 to k9. Not as many answers and probably worse coding than ngn's, but perhaps more approachable for newcomers. https://github.com/chrispsn/aoc2019 https://github.com/chrispsn/aoc2019 llelf's; targets k7. Pretty slick. https://github.com/llelf/advent2019/blob/master/sol.k https://github.com/llelf/advent2019/blob/master/sol.k
- kazinator 7y agoYou should give definitions a chance, because they point to a way to make your code even smaller. Consider that dictionary compression, like LZ77 and LZSS works by encoding redundancy using symbols that index into a table. Even APL/J/K programs with repeated patterns in them are further compressible. Occurrences of any repeated string more than two bytes long can be replaced by a 16 bit symbol. Speaking of which, why don't you just learn the data structure and algorithm of a compression program like gzip inside out? Then you can write compressed code in any language. Others can easily work with your code by uncompressing it and then compressing it again when their changes are applied. Or vice versa; you can work with other people's code by compressing it first, then doing your changes in the more convenient, ergonomic compressed format. Maybe some checkout/commit hooks can do that transparently. Compression will ferret out gratuitous frivolities like 17 copies of remoteDatabaseConnectionHandle, and turn them into a convenient, tiny code. Think of how much smaller it can be if you go beyond reducing tokens to character. You've now got Huffman and dictionary coding at your disposal, and possibly more.
- xelxebar 7y agoDo you have trouble discerning "cobble" vs "coddle"? Maybe; how about with context? "We cobbled together some crazy hack," vs. "We coddle our infants to show love and affection." Arguably this comparison is quite similar to your "((<]):) and ((<[):)" example. Certainly the relationship between "]" and "[" is the same as between "b" and "d". Kids first learning to write often do mix up "d" and "b". The difference certainly seems subtle and arbitrary in the first stages of study. Do you have much experience in APL/J/K? As I see it, the point is that these languages offer some really spectacular ergonmics and expressibility _once one has gained fluency_ and in a way not possible elsewhere. This is really surprising! Perhaps that's why there's a lot of initial skepticism. In the space of all possible programming languages, it certainly seems like we've explored a pretty darn good chunk. There are thousands of languages trying out myriad different possibilities. We have everything from C to Java, from Haskell to Scheme, from Forth to Bash, and this still doesn't do justice covering all the paradigms and methodologies we programmers have dreamed up. Is it really possible that there's some random corner of language space that offers something more than localized and incremental benefits? Is it really true that there's some wacky scheme for writing code that is way shorter to write, pleasant to read, while also running fast? The answer is yes! And that's super cool! The catch is that it's a really weird family of languages, but if you spend the time to learn them well, I suspect that you will also see what we are talking about.
- beagle3 7y agoThat’s an excellent comment. The only thing I have to add is that is’s not some newfangled concept that’s bad but we’ll only figure out why in a couple of years: APL has been around for over 60 years on various forms - it is about as old as Fortran and Lisp. In fact, APL was designed for paper, as a well-defined notation for algorithms in math and CS papers (which are still either sloppy with algorithm semantics or spend a lot of space specifying their non standard notation to this day). But since it was well defined, it was actually executable, and when computers were good enough, an interpreter was developed at IBM. That’s why APL has so many weird symbols (it’s a paper notation for math, at heart). K is a practical simplified version/dialect that uses only ascii (as does J, which is essentially full APL with ascii) One of the main complaints against APL is that they are write only. They take longer and more effort to read per character, granted, but per “semantic information”, for any reasonable definition, APl/J/K are way faster to read for someone proficient (and yes, I take proficiency for granted - the minute details in any language between Boolean short circuit, non local control transfer, integer/float conversions etc make proficiency essential)
- nivertech 7y ago100% agree https://news.ycombinator.com/edit?id=22565985 https://news.ycombinator.com/edit?id=22565985