Earlier quoted context omitted.
> I don't understand why you think the Ruby code has better SNR. Because they say the same thing, but the Python code is much longer, if you count tokens instead of lines. It has about 28-30 more tokens than the Ruby code does, about three per line. Those tokens don't convey any information. They're just redundancy, i.e. noise. And there are a lot of them; these redundant tokens are something like a third of the code…
Haskell removes not only the () that Ruby does, but also the commas. It also uses a simple precedence trick to remove almost all () in general (not just for functional calls). I wanted to translate the code to Haskell directly, but the idioms don't map that well (self.cellSize would becomes something else entirely, and the comparison would not be fair).
Every language fixes something - a DiGraph - just for fun
91–100 of 102 posts
Re: Every language fixes something - a DiGraph - just for fun
#92Cool =) But who says perl has "no support for Japanese"? Don't think that's true
Re: Every language fixes something - a DiGraph - just for fun
#93Earlier quoted context omitted.
Haskell removes not only the () that Ruby does, but also the commas. It also uses a simple precedence trick to remove almost all () in general (not just for functional calls). I wanted to translate the code to Haskell directly, but the idioms don't map that well (self.cellSize would becomes something else entirely, and the comparison would not be fair).
I'm curious what it would look like.
Re: Every language fixes something - a DiGraph - just for fun
#94Re: Every language fixes something - a DiGraph - just for fun
#95The enhanced version is completely different from the regular version. Not only are the reasons different, but a lot of the languages don't even inherit from the same sources (the regular version had javascript coming from java. wtf?). Just goes to show how arbitrary/silly it all is. Still pretty awesome. Why did haskell come about? "Lazy evaluation is cool, yo."
Re: Every language fixes something - a DiGraph - just for fun
#96Earlier quoted context omitted.
So you agree with the diagram is stating: that JavaScript fixes Java's syntax by using the same C-like syntax? No, the given reason for Java -> JavaScript is completely wrong. I'd understand if the reason was "Java browser applets suck", but syntax?
Have you not noticed that the link you're complaining about is in PG's original essay, and the newer version has no link between Java and JavaScript ?
In fact, I could have also mentioned myself that the link was taken off the second graph to further my case that it was just plain wrong. The only reason I did not was because I thought it was something so obvious it would not be necessary to state it.
Re: Every language fixes something - a DiGraph - just for fun
#97Earlier quoted context omitted.
I'm curious what it would look like.
I'm curious if you would still think of token count as a useful metric if the Ruby version turns out to be twice the size of the equivalent code in J or K due to "redundant" "noise" tokens. Programs should be written for people to read, and only incidentally for machines to execute.
Here's Life in Dyalog APL, from http://dfns.dyalog.com/c_life.htm and http://news.ycombinator.com/item?id=1041500:
life←{ ⍝ John Conway's "Game of Life".
↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ ⍝ Expression for next generation.
}
Unfortunately, my APL is pretty rusty, and Dyalog has added some major extensions to the language, so I'm not quite sure what that means, in particular the juxtaposition of 1 and ⍵ toward the beginning. I think it parses as vertically_rolled = outerproduct(⌽, [-1, 0, 1], ⊂(⍵))
horizontally_rolled = outerproduct(⊖, [-1, 0, 1], vertically_rolled)
neighbor_counts = sum(ravel(horizontally_rolled))
↑(⍵(1, innerproduct(and, or, ⍵,
[3, 4] == neighbor_counts)))
but I'm not even sure of that.The Life rule (which is pretty optimal for being expressed in APL, given its array orientation) is slightly simpler than the Wireworld rule:
def run_wireworld_rule
old_cells = @cells
@cells = fresh_cells
each_coord do |x,y|
# This could be optimized somewhat by only recalculating
# the neighbors of dirty cells.
case old_cells[x][y]
when :electron_head
set x, y, :electron_tail
when :electron_tail
set x, y, :wire
when :empty
# do nothing; fresh_cells are all :empty
when :wire
case electron_head_count old_cells, x, y
when 1, 2
set x, y, :electron_head
else
# Don’t call `set` in this case so as not to mark
# the cell dirty for redrawing.
@cells[x][y] = :wire
end
end
end
end
# This could perhaps be optimized somewhat with a sum table.
def electron_head_count(cells, base_x, base_y)
count = 0
([0, base_x-1].max..[base_x+1, @nx-1].min).each do |x|
([0, base_y-1].max..[base_y+1, @ny-1].min).each do |y|
count += 1 if cells[x][y] == :electron_head
end
end
return count
end
def each_coord
(0..@nx-1).each do |x|
(0..@ny-1).each do |y|
yield x, y
end
end
end
The APL people claim that their programs are more readable because they're shorter, but I'm not sure how much I believe their claim. It's certainly true that other kinds of mathematical notation benefit enormously from brevity and consistency that permits mechanical manipulation, and I don't see why algorithms should be different, but empirically I have a lot less trouble with Ruby or Python (or even C) than with plain-English descriptions of mathematical equations.Re: Every language fixes something - a DiGraph - just for fun
#98I can't respect any chart that describes Java as an evolution and improvement of Objective-C.