Hacker News new | ask | show | jobs
by beagle3 4258 days ago
Note that his lines are < 60 chars.

Can you write this editor in one line of less than 6000 chars of javascript (without a "textarea")?

4 comments

Why do you exclude textarea? It's a high-level functionality available in JS. That q code uses the high-level functionality of q. What's the difference?
No, it's part of webkit/blink/gecko, it's not part of JS. But that's not why I exclude textarea:

I exclude textarea for the same reason dictionaries define something without using the same word and base form.

And the argument is generally meaningless: You may just as well call emacs and say you are using "the operating system's high level functionality".

Does that k code implement cursor-movement / scrolling / etc itself, or is it relying on some sort of system functionality for it?
Someone skilled in writing compact JS probably can. People write amazing programs in 1k & 4k of JS: http://www.google.com/webhp?#q=javascript+4k
Yes.

There is, however, a fundamental difference between codegolfed K and codegolf in essentially any other language:

Codegolfed k uses 1-letter variable names, and drops white spaces (which, unfortunately, is kind of idiomatic). But everything else is idiomatic even for the non-golfers.

Codegolfed JS or C much more often than not is non-idiomatic in order to save all that space.

e.g., compare the K Sudoku solution from http://kparc.com/z/game.k to any other language, and you'll see that the K code is almost a generic solver (the 3, 9 and 10 stand for box size, board size and number of options respectively while setting up the constraints for the solver), whereas every other short solution (that usually come about twice as long to 10 times as long) is extremely specific to the standard sudoku table.

That's not random - idiomatic K solutions tend to be more generic than other languages. The syntax and semantics gently push you towards more general and more efficient solutions compared to most languages, in that the more general (and/or efficient) solution is usually shorter and simpler to code than a specific case.

I know it sounds unbelievable. But you might believe it when you see example after example and realize that it's not just a "one trick pony". And still, most people surround it with a SEP field. I recommend spending the time needed to grok it instead. [Or APL or J; my personal preference is K, but to each his own]

It does not matter. This is not a programming language; languages are designed for human comprehension. Human comprehension is an irreducible part of the whole paradigm of programming, being necessary to understand the nearly always complex logic required to describe anything of value.

This is gibberish. It fails at the one task of a programming language: to translate something a human can understand into something a computer can understand, with as little confusion as possible.

No, it is just not a language for the masses who have gotten used to all programming language syntax being minor variations on the Algol/Pascal/C theme.

Much like math and physics, this is an extremely terse notation that is immensely useful to those who practice it, and looks like gibberish to those who have not attempted to study it. You could give the same comment about an article in any area of math whose notation you are unfamiliar with -- and you would be just as equally wrong.

Any language you don't know is gibberish—hence the proverb, "it's all Greek to me." Please don't dismiss the unfamiliar just because it's strange.
You owe to yourself to read the Iverson's Turing lecture, "Notation as a tool of thought". You can find it. Apparently APL family can claim relationship to math notation - which is not a small claim. Lisp family does it too - in different way.