4 ms·
Whats even better, though, is not needing 200 lines of code in the first place. The thing I hate about java, is that you're required to use an IDE, or you'll ne
by psadauskas 16y ago
Whats even better, though, is not needing 200 lines of code in the first place. The thing I hate about java, is that you're required to use an IDE, or you'll never get anywhere. In Ruby, you just metaprogram in 10 lines what takes 200 in java. Its `attr_accessor :foo, :bar, :baz` in ruby, vs 8 loc for each in Java. Want to change the name? Go change the one word in ruby. No need for an IDE with refactoring support.
- binaryfinery 16y agoOnce you've changed that one word, how do you change all the places that reference it?
- shadowfox 16y agoYou can always fix it after you get the run time error ;)
- mathias_10gen 16y agosed?
- mst 16y agofind lib -name '*.pm' | xargs perl -pi -e 's/.../.../' is usually quite sufficient for purpose if you have a reasonable idea what's going on in your codebase (and if you don't, you probably don't want to be renaming things yet). Doesn't mean a real refactoring tool such as the ones people've been playing with for http://padre.perlide.org/ http://padre.perlide.org/ wouldn't be better, but it's amazing how well a simple brute force replace works on a reasonably tested codebase.
- binaryfinery 16y agoMight work for classes. Good luck with "count" or "item". But I take it from your third paragraph that you agree with the OP and myself that IDEs with good refactoring tools are a good thing.
- billmcneale 16y agoYou need an IDE in Ruby just as much as in Java. It's the easiest way to browse the code, navigate from place to place, get some auto completion and auto imports, etc... Of course, Ruby being dynamically typed makes it impossible to have most of the refactorings that statically typed languages take for granted, but that's a separate topic. Look at it this way: you might think you are productive with Emacs/TextMate/vi, but you would be even more productive with an IDE of the Eclipse or IDEA caliber. An IDE is nevery mandatory, it just makes you more productive.
- ekiru 16y ago"Of course, Ruby being dynamically typed makes it impossible to have most of the refactorings that statically typed languages take for granted, but that's a separate topic." Most of the refactoring tools that Java IDEs have originated in Smalltalk, an extremely dynamic language.
- billmcneale 16y agoMost of these refactorings required human intervention, even for simple refactorings like "Rename". When the IDE doesn't have types, some refactorings are simply impossible to perform automatically. For more details and examples: http://beust.com/weblog/2006/10/01/dynamic-language-refactoring-ide-pick-one/ http://beust.com/weblog/2006/10/01/dynamic-language-refactor...
- ekiru 16y agoThe arguments in your linked article are inaccurate. For example: the Refactoring Browser described in "A Refactoring Tool for Smalltalk"(at http://st-www.cs.uiuc.edu/users/droberts/tapos.pdf http://st-www.cs.uiuc.edu/users/droberts/tapos.pdf ), was capable of determining which sends of a renamed message were to the class on which it is to be renamed by analysis of the program's dynamic behavior. There's of course a limitation on this. To quote the paper: "The major drawback to this style of refac- toring is that the analysis is only as good as your test suite. If there are pieces of code that are not executed, they will never be analyzed, and the refactoring will not be completed for that par- ticular section of code. "
- ekiru 16y agoDoes Java not allow public fields? The biggest difference there is that Ruby programmers frequently don't think twice about exposing their object's state to anyone and everyone. It should be one line of code for each attribute in Java "public SomeClass foo;" if we're going for the same semantics as the Ruby example(admittedly, if you don't want to expose that it's a field, that's not quite as easy in Java, although really, there's no reason to not just do this: private SomeClass foo_; // I don't know if Java allows methods with the same name as fields. public SomeClass foo () { return foo; } public SomeClass foo (SomeClass aFoo) { foo = aFoo; } Yes, that's not what most Java programmers would write, and it's not too concise either, but it's not nearly as bad as you suggest.
- flomo 16y agoThe difference is that in Ruby you can add getter/setter methods at a later date without changing the interface.
- ekiru 16y agoI know. That's why I include the admittedly a bit longer and boiler-plate-y-er code sample. Same effect as the ruby. Unfortunately, 3 lines per attribute. A bit more explicit and quicker to change when you make the getter/setter methods actually do something. I prefer the Ruby. But, frankly, Ruby has too much boilerplate for attributes, too. I have to explicitly add attribute handling code in initialize? Why? No, thanks, I'll use Perl 6: has $.foo is rw; There you go. An lvalue accessor method for an attribute, and the ability to set it in the constructor with the named argument ":foo(someValue)". And, if I want to add a type constraint, it's a simple matter of doing this instead: has Int $.foo is rw; Or even this if I only want even numbers: has Int $.foo where { $_ % 2 } is rw; If I really want to, I can manually implement my own constructor, but often, I won't need to. If I want the attribute to be private, I just replace "$.foo" with "$!foo" and it's only accessible within the class. CLOS also makes this very simple, you just add an entry in the slots list of the class like so: (foo :accessor foo :initarg :foo) You can also do type-checking by adding ":type some-type-specifier", specify that it's either a class or instance(the default) slot with ":allocation class" or ":allocation instance", use :reader or :writer instead of :accessor to only generate a reader or a writer accessor or :initform to give the slot a default value. Ruby is at a nice place on the accessor definition boilerplate continuum, but it's nowhere near the bottom.