Live data from Hacker News

“Did you mean?” Experience in Ruby

yukinishijima.net

141–150 of 187 posts

Re: “Did you mean?” Experience in Ruby

#142
post #105
post #97

Earlier quoted context omitted.

I also work that way. I use the autoreload feature of ipython so that any code I change in my editor is instantly replicated in my ipython objects. I've really never been more productive in development in my life. Contrast with some Java I was doing recently (granted, without a Java IDE) and I found the whole cycle painfully slow. Even things the compiler picked up were a magnitude slower to find than when I was in i…

"without a Java IDE" This was your problem. Programming Java without an IDE that recompiles your changes on the fly is just so arcane and really slows you down as you noticed.

So true. Java was designed for tooling. Using it without tooling is actual using it against its design.

Re: “Did you mean?” Experience in Ruby

#143

Obviously this is a useful tool, and all the power to the author for finding what looks to be an excellent solution, but this line bothers me: >>> Sometimes I wasted hours and hours just because there is one character difference. I hate it. This shouldn't happen. Ever. This should not be a problem anymore. These are the sort of errors that we can catch immediately and should be caught immediately. From looking at the…

You're invoking "IDE" features like it's a panacea. In reality IDEs have only a few limited ways to catch these kinds of errors. With a statically-typed language it can run static analysis at intervals and make sure that all the messages being passed are actually defined on the objects they're being passed to. You can do this precisely because that's what static types gives you.

In dynamic languages you can't do this because you don't know the type that any given identifier is pointing to. The type could be completely arbitrary, I.E. coming from external input. You might think, "oh, well you could just check against all possible methods", and you'd be right, except for Ruby. Ruby allows you to override what happens when you call an undefined method, (method_missing) letting you execute completely arbitrary code that lets undefined methods look just like methods. You could call car.start_and_drive_to_the_bank, and set up the Car type so that it can handle methods like that, (perhaps calling car.start, and then car.drive(bank)) along with .start_and_drive_to_the_mall and whatever. In practice that's bad Ruby, but you still have to be able to handle that, Bad Ruby is still Valid Ruby.

So there's just no way to tell in Ruby whether any given method call is correct or not.

I have an idea to conventionalize method_missing overrides so that they're easier to analyze. Maybe define a regular expression on the class so that the analyzer can sort out what's likely to work at runtime and which messages aren't. Not sure how well it would work until Matz manages to implement static typing as he wants to do in the future. Until you can tell whether any given identifier is likely to be of a type that overrides method_missing, you'd be running the method_missing analyzer for all types on all method calls.

Re: “Did you mean?” Experience in Ruby

#145
post #77
post #40

A lot of people are recommending IDE-like tooling--but in truly dynamic language (one with a "living image" with path-dependent monkey-patched behavior that can't be replicated during static analysis, like Smalltalk--or, sometimes, Ruby) there's a more idiomatic way. In a dynamic language, if you're at all unsure of what code you need to write, then you don't write it in your editor in the first place. Instead, you b…

And with Ruby, especially since you mention Smalltalk, we have a tool that is getting closer to the kind of live introspection and modification that Smalltalk is famous for: Pry [1]. Pry lets you call "binding.pry" anywhere in your program to dump you into a shell within that context, with full access to local variables etc.. And tab-completion and plenty of introspection features. I frequently find myself triggering…

In pry is it possible to return something when I exit the REPL? Like this:

  def do_something
    return binding.pry

    do_something_but_does_not_work
  end

  result = do_something
  process result
It might be very convenient if I put 'return binging.pry' just before the broken code. I can interactively fix the broken code and continue run outside of current method.

Re: “Did you mean?” Experience in Ruby

#146
Blows my mind that IDEs and environments are not better at this. This is something that computers are good at, pattern recognition and scanning the whole file. Of course the it wouldn't work every time, an could make ridiculous suggestions, but I would love the computer to suggest something every time there is an issue. Even if it is wrong 90% of the time, if those guesses don't slow down the programmer the time saved would be huge.

Re: “Did you mean?” Experience in Ruby

#147
post #8

I would love it if instead of quitting my program with an error, it just went ahead and called the method it thinks I'm referring to. This would remove a lot of unneeded friction from web development.

That has been tried before. Results were... poor. http://www.catb.org/~esr/jargon/html/D/DWIM.html

You are correct, but please don't refer to the bastardized version of the Jargon file. Wikipedia has a much better and more accurate article, with actual quotes and citations instead of unsourced politically motivated mythology attributed to "some victims":

https://en.wikipedia.org/wiki/DWIM

>Critics of DWIM claimed that it was "tuned to the particular typing mistakes to which Teitelman was prone, and no others" and called it "Do What Teitelman Means" or "Do What Interlisp Means." - Guy L. Steele Jr., Richard P. Gabriel, "The Evolution of Lisp"

The person who bastardized and maintains the Jargon file is a racist, sexist nut job who built his career on attacking the Free Software movement, and who doesn't deserves anyone's respect or attention: http://rationalwiki.org/wiki/Eric_S._Raymond

Re: “Did you mean?” Experience in Ruby

#148
post #104

Earlier quoted context omitted.

Would you mind making a little screencast demo of your workflow? (Or do you know of any?) That sounds so cool.

Sure. I'm not near my machine for a couple of days but I'll post something when I get the chance. I see your contact info is in your profile so will ping an email when done.

Ping me too, please. Thanks.

Re: “Did you mean?” Experience in Ruby

#149

> Sometimes I wasted hours and hours just becaue there is one charactor difference. I hate it. Haha, humans are much more able to parse meaning, despite a character being off here or there. Well, you've taken computers one step closer to humans. And you've made programming with Ruby friendlier. Great job!

When I read that line you quoted, I wondered "how did the author ever finish the gem, since it didn't exist yet to help them with their typos?"

Re: “Did you mean?” Experience in Ruby

#150
post #104

Earlier quoted context omitted.

Would you mind making a little screencast demo of your workflow? (Or do you know of any?) That sounds so cool.

Sure. I'm not near my machine for a couple of days but I'll post something when I get the chance. I see your contact info is in your profile so will ping an email when done.

Me as well, if you're offering.

I find iPython interesting but haven't figured out how to integrate it into my current workflow of Sublime/Terminal.

Post reply on HN