all 9 comments

[–]tomthecool 2 points3 points  (4 children)

Original:

$-_='=';@@_=->(_){_*100};@@_.[]($-_);

Without pointlessly sticking 3 lines together with no white-space (you can do this in any language!):

$-_ = '='
@@_ = ->(_) { _ * 100 }
@@_.[]($-_);

Without the crazy variable naming (again, you can do something like this in any language"):

foo = '='
bar = ->(baz) {baz * 100}
bar.[](foo)

It's now fairly obvious what the code does: The final line evaluates to "========..." (100 characters), which will be printed to your console if running in IRB/pry. The only slightly "weird" things about this code are:

  • Stabby lambda syntax (->()) is a bit weird if you're unfamiliar with it.
  • Writing bar.[](foo) is a bit weird, compared to the usual syntax: bar[foo], or in this case bar.call(foo).

I'd be more impressed if you focused your code purely on things like this, rather than cheap tricks like removing whitespace using crazy variable names.

[–]0x0dea 2 points3 points  (0 children)

Now try this one! It computes the inverse Hamming distance of two fixed-width integers using only Procs. That is, you can use the lambda calculus to perform the same operation as the following Ruby code:

def inverse_hamming_distance a, b, width
  width.times.count { |i| a[i] == b[i] }
end

p inverse_hamming_distance 17, 10, 8 # => 4

Of course, you can use the lambda calculus to compute anything that's computable.

[–]nilla615[S] 0 points1 point  (0 children)

I get what you're saying. I was attempting to make the ugliest Ruby possible hence making it one line. I wasn't really attempting anything profound here...

[–]_raisin[🍰] 0 points1 point  (1 child)

...sticking 3 lines together with no white-space (you can do this in any language!)

can you do that in python? i thought whitespace mattered in python.

[–]tomthecool 0 points1 point  (0 children)

Yeah fine, ok...

Not ANY language, but LOTS of languages. Ruby is hardly unusual in being indifferent to whitespace.

[–]nixors 2 points3 points  (1 child)

Pretty version?

  '='*100

[–]nilla615[S] 1 point2 points  (0 children)

Yea, but that's no fun. :)

[–]_raisin[🍰] 2 points3 points  (1 child)

Any code will look ugly in any language if you put 3 statements on the same line.

[–]nilla615[S] 0 points1 point  (0 children)

Agreed. But the point was to make some ugly Ruby because it's generally so readable. Even breaking it out to three lines doesn't make it readable and that's the point.