Native reactive spreadsheet in 17 LOC
red-lang.org
red-lang.org
http://jsfiddle.net/ondras/hYfN3/
https://news.ycombinator.com/item?id=6725387
You can compare it to the readable 67 lines of code in red-lang
For the "no library", well, you have tons of libraries included in a ~100MB runtime (browser) required to run and render that demo, while Red's one runs on the OS directly (our runtime is 0.6MB uncompressed and entirely written in Red, not a single 3rd-party library). ;-)
That said, that JS demo code is very nice, and its slickness impressive.
[1] https://gist.github.com/dockimbel/b0a413342dc39568696207412a...
What I do see is that the JavaScript does all of this much more cleanly and intelligibly, and has an honest line count.
Incidentally, I also think that cleanly separating presentation from logic is an advantage of the JS / CSS divide, even is JavaScript if far from perfect and CSS is actively horrible.
https://gist.github.com/greggirwin/8d0b1c02ccdbd5520d9c77d49...
The reactive logic is all lifted from the original. Around line 40 you can see where styles are defined inline. Originally I had them just defining visual aspects, but then moved the actors into the cell style as well.
With native widgets, you don't get complete control, and they won't match across platforms. Rebol had its own GUI system, and I wouldn't be surprised to see something similar done by a clever Red...we don't have a name for folks who write Red yet. Racket got the best name, with Racketeers.
Folks who use Red could be referred to as communists ;-) If it takes off, you'll be Big Red.
More VID demos and the type of FRP in RED would be more enticing to me. But truth be told, I stumbled upon Red when looking at short programs translating text to morse code. The Red example (from Rebol actually) was very short, yet easy to read. I program in J, so I know what short, and unreadable means to others; I personally like J.
I realize browsers are ubiquitous, so in essence you just need to count the size of browser, JS engine and code. What would be the bare minimum JS setup to provide core libs, GUI, and other helper libs and a way to run it/distribute it sans relying on pre-installed browsers. Would that be Chromium or Electron? Can you choose the best engine with them, or are they attached to the browser or minimal browser?
I am rather a fan of both Tcl's and Rebol's GUI DSL.
Edit: I'll explain how the Tcl/Tk spreadsheet works. I am not sure I understood Red's reactive framework quite enough to compare and contrast the two implementations correctly, so if you do understand it, I would love to read your comparison.
The spreadsheet cells are ::ttk::entry widgets comparable to <input type="text"> that are created in a loop and laid out using the built-in [grid] geometry manager. When a cell is created its value is bound to a variable like "A2" by two-way data binding. We then add a "trace" to that variable so that when it is read the command [recalc] runs to update its value based on the formula for the cell before the read completes. This triggers update cascades that resolve chains of dependencies between the cells' formulas. The formulas are plain Tcl expressions mangled by a regexp to allow you to reference the values of variables like "A2" without the "$" prefex.
While I feel that expressiveness is good to an extent, I can't help feeling that there's a certain point beyond which increasing expressiveness is detrimental to productivity and overall code quality. While it's certainly elegant and satisfying, in order to read or understand the code you have to 'unpack' it mentally, requiring much more work than if it had been written at a lower level of abstraction. This seems to me to be related to something I read recently (I wish I could find the link), saying that all human languages tend towards a fairly predictable word entropy which allows a good balance between efficiency and error correction capability.
(Obviously this was a demo to highlight the language's power, and not how you'd write real-world code, but still.)
Golang looks at very cursory glance to be yet another entry in the "modern C-like" column. If you could recommend one link to read to convince me that it's worth learning, what would it be? My main dev work is native Windows/Linux GUI, Linux command line utils/servers, and embedded development.
- super-fast compilation, so much so that you can write Go "scripts" that are compiled and run from the #! line every time you call them, faster than it takes the Python interpreter to start;
- static binaries: this eliminates an entire class of problems, such as DLL hell and OS version dependencies;
- great concurrency model, easy, powerful, and safe, based on CSP;
- implicit interface implementation, which makes it easy to integrate different libraries (I'm not sure what the academic name is for this feature, but it's taken straight from Common LISP, Haskell, etc.)
Highly recommended. Easy to learn and very comprehensive standard library.
The mental unpacking to read does improves over time, as you get familiar with frequently occurring patterns. But what I find more interesting is the "write" side of the story, not the "read" side. I have encountered many who think just because the code is short and succinct it must have taken no more than a jiffy to write. It takes mental effort to distill a complex idea to a short idiomatic string.
What you get rewarded with after that exercise is less space for subtle bugs to hide. It is quite difficult to write very short pieces of code with non-obvious or subtle bugs.
I would have written a shorter letter, but I did not have the time.
Provincial Letters : Letter XVI (4 December 1656)
via https://en.wikiquote.org/wiki/Blaise_PascalUnpacking ability certainly improves over time. The problem is, so does packing, such that they tend (at least in my experience) to balance out. The time taken to write, and read, code is dominated by the per-concept costs. So you end up with the writer and the reader of the code still taking the same amount of time per concept, but they're also doing a bunch of translation steps alongside. Since these steps are fallible, you've reduced the overall efficiency.
There's not less space for subtle bugs to hide. The space is just folded up, and bugs can also hide in between the folds.
However, how can you call it 17 LOC and then put in a link to a "readable" version with 67 LOC on the same page.
You make a good point, though, in that examples benefit from being readable.
Also, maybe it made you look. ;)
[1] https://gist.github.com/dockimbel/091cc787b366a3d88972b8cb9e...
That doesn't mean that this is nothing.
But it seems like a great language for making GUIs (possibly), and this seems an excellent demonstration of that, so it has plenty of merit.
I do relate to the over use of "n in x LOC!" posts. Like we get it list comprehensions are cool.
>Yeah, we still count in KB.
Sadly, no one cares about such things nowadays.
Maybe web developers don't care, but nobody really cares that web developers don't care. /s
[1] https://code.facebook.com/posts/1365439333482197/how-we-buil...
However. At one point reading and deconstructing a tangled mess of characters outweighs the "expressiveness" of the language.
More than "expressiveness" a language needs docs, community, tools.
Haskell is virtually unreadable to me, however, I do understand that it's a quite powerful language. I would imagine that if I took the time to learn Red / Haskell the code would make a lot more sense.
I had the same experience with ruby, initially ruby code looked very foreign to me, however, now it's quite easy for me to read.
And of course, you will show us same capabilities, gui, reactiveness in J/K, won't you?
S..t:".[`D;(;);{. y};S[]];S[.;`f]:9$D[]"
S:D:.+(`$'_ci 97+!26;26 99#,"")
`show$`S
This K (K2/K3) version of a simple spreadsheet (so demoing GUI, "reactiveness") is also mentioned in the original post's comments. =alert("whatever")
Still, pretty cool thoughBut my feeling on "fast" is generally; how fast does the solution need to be? I have a co-worker who complained that more business logic client-side would slow down our application (it won't, of course). Our application gets on average about 2 requests per second for any given customer. It is by all human perception plenty fast. It doesn't need to be any faster and even being a little slower would go unnoticed. Its all behind a login and isn't intended to be crawled so SEO isn't an issue. Yet once again the ultra-vague benchmark of "fast" gets bandied about needlessly.
But back to Red. From what I've seen its pretty fast but its also early days for the language and they're not focused yet on optimization. Looking at how it is designed I can see how it will be eventually VERY fast once optimized.
There are 2 levels in Red. Red is the high level language (think scripting level) while Red/System is the low level dialect (think C). In general, because the compiler is new and non-optimizing, Red/System will probably be half the speed of C from an optimizing compiler right now. As always, algorithms are the big win.