Posts: 591
Threads: 26
Joined: Sep 2016
May-06-2017, 02:19 PM
(This post was last modified: May-06-2017, 02:22 PM by Mekire.)
Been going through this book for kicks:
Mazes for programmers
The book is written in Ruby and I figured, "Hey, why not just pick up Ruby," while I went through it (even though translating the code to python is fairly trivial).
Despite the constant end tags which I think make everything ugly as hell I just ran into this loveliness.
The following is essentially looping over a range in python and assigning each value to the name index ; straight forward:
0.upto(path.length - 2) do |index| A little weird but fair enough.
0.upto(path.length-2) do |index| Yeah, that seems fine too.
0.upto(path.length -2) do |index| Error: `length': wrong number of arguments (given 1, expected 0) (ArgumentError)
... wtf.
Not that I condone the latter's operator spacing, but the fact it means something different is insane.
Posts: 3,458
Threads: 101
Joined: Sep 2016
It's because parenthesis are optional for calling methods in ruby, so for times like this, it isn't obvious whether you're passing arguments to path.length(), or if you're operating on it's result. You can add parenthesis to all three of those, and they'll all do the same thing.
Also, the do loop takes a function, the |x| syntax is ruby's version of lambda. It's been a while since I've ruby'd, but I'd be willing to be the do had an "end" afterward, with some sort of function body that used the index.
Ruby's an alright language.
Posts: 591
Threads: 26
Joined: Sep 2016
May-09-2017, 10:08 PM
(This post was last modified: May-09-2017, 10:09 PM by Mekire.)
(May-09-2017, 09:42 PM)nilamo Wrote: It's because parenthesis are optional for calling methods in ruby Don't get me wrong. I know exactly why and what is happening. I just think it is a terrible design decision.
The fact that function(arg1, arg2) and function (arg1, arg2) are different is awful. Not to mention the implicit function calling without requiring parenthesis means that functions aren't first class. In order to pass them as arguments or put them in containers you need to do silly stuff like wrap them in classes.
Quote:Also, the do loop takes a function, the |x| syntax is ruby's version of lambda. It's been a while since I've ruby'd, but I'd be willing to be the do had an "end" afterward, with some sort of function body that used the index.
Yes, there is obviously a block that uses the index variable I didn't include. This was just the context in which I hit the problem and had trouble finding where the problem was.
Quote:Ruby's an alright language.
I like parts of it but there are definitely some design decisions I think are questionable as hell.
Posts: 2,342
Threads: 62
Joined: Sep 2016
(May-09-2017, 09:42 PM)nilamo Wrote: Ruby's an alright language. https://www.destroyallsoftware.com/talks/wat
Posts: 3,458
Threads: 101
Joined: Sep 2016
Posts: 687
Threads: 37
Joined: Sep 2016
(May-09-2017, 10:17 PM)micseydel Wrote: (May-09-2017, 09:42 PM)nilamo Wrote: Ruby's an alright language. https://www.destroyallsoftware.com/talks/wat
JavaScript takes a more serious beating. Hilarious all along!
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Posts: 2,342
Threads: 62
Joined: Sep 2016
May-11-2017, 09:41 PM
(This post was last modified: May-11-2017, 10:23 PM by micseydel.)
Weak typing seems takes the most serious beating (note: Python 3 became more strongly typed <3). But yeah Ruby and Javascript have issues. Javascript you kinda have to live with right now but Ruby... just why when you have Python?!
Posts: 3,458
Threads: 101
Joined: Sep 2016
(May-11-2017, 09:41 PM)micseydel Wrote: Javascript you kinda have to live with right now Typescript is actually really cool.
Instead of a lot of other languages that transcompile into javascript, typescript is just javascript, but with types added in. Valid javascript is valid typescript. You can also write valid ES6 javascript (let expressions, anonymous functions using => syntax), and compile them into valid ES3 javascript, which can run on ancient browsers like IE6. So using things like modules, classes, private methods, are all possible, without giving up browser share.
The downside, of coarse, being that you suddenly have a stunning number of technologies to learn all at once. "Get Typescript, write typescript. Get gulp, create a gulp file to compile your typescript and move the compiled javascript into a 'build' directory. Then get Browserify, configure Gulp to feed the compiled javascript into Browserify to create a single javascript file called 'bundle.js', and THAT'S what you actually link to in your html." I almost quit learning typescript when I saw that that was what is involved just to get started.
Posts: 2,342
Threads: 62
Joined: Sep 2016
Yeah, reminds me of https://hackernoon.com/how-it-feels-to-l...a717dd577f
I get that alternatives to Javascript are around, and that they might even be kind of standard (for the moment) but I'm disconnected enough from that to just think of Javascript as a necessary evil... for now :)
Posts: 591
Threads: 26
Joined: Sep 2016
(May-11-2017, 10:23 PM)micseydel Wrote: Yeah, reminds me of https://hackernoon.com/how-it-feels-to-l...a717dd577f Heh, I was just reading through that yesterday.
|