4 ms·
Also, information hiding is rumored to be important in real software. Ruby gives you the ability to nominally "hide" data, but it's trivially easy for any late
by timr 18y ago
Also, information hiding is rumored to be important in real software. Ruby gives you the ability to nominally "hide" data, but it's trivially easy for any later programmer to violate the encapsulation. It's DHINO programming -- Data Hiding In Name Only.
Not only isn't this considered a bad idea in the Ruby world, but it's actually a common technique. Use a third-party library, and you may well be re-writing core parts of the language. Sound good? You can't prevent it.
I like parts of Ruby; it's a fun language. But the author is right -- it's not a language for large projects, or projects with more than a few programmers. My alternative to Ruby would allow the fast-and-loose stuff that makes Ruby fun, but also give you a way to make classes immutable and guarantee data-hiding and encapsulation when you need to do real software engineering.
- davidw 18y agoI don't like the "real software engineering is big heavy Java projects" thing (aka "bondage and discipline"). Plenty of "real software engineering" has been done to great effect with dynamic languages. Here's a random idea: rather than strict locks, perhaps transparency would be a good approach. Load up a third party library, and you get informed that it's fiddling with things, and can then find out what. Maybe it really does need to fiddle with things. Or maybe in a given situation, fiddling with things is the most efficient way of accomplishing something.
- aaronblohowiak 18y agoYea, it is fairly trivial to enable logging every time a method is overridden or added to any class in ruby. Dynamic code inspection like in JavaScript would be pretty cool, too.
- timr 18y ago"rather than strict locks, perhaps transparency would be a good approach" Transparency is a great, but you still need rules when you're working with any code that's bigger than what you can hold in your head at any given time. Doubly so when you're working with a team. Programming in a team is hard in the same way that taking care of a room full of toddlers is hard -- obviously, you want everything out in the open, but you also want to hide the sharp objects, put caps over things that can shock, and otherwise make the big, transparent room as soft and bouncy as possible. You need locks on the cabinets full of poisonous chemicals. Obviously, the locks need to be open-able, but only in special situations, and certainly not by nosy toddlers. (Before you criticize me for being paternalistic, realize that I include myself in the "toddler" category. I much prefer code that's written in a defensive style, because it's easier for me to maintain later on -- and that's where any programmer spends the majority of his time. I've developed this attitude because I know that I'm stupid, not because I'm arrogant.)
- Xichekolas 18y agoWhile I agree that writing code defensively is the way to go when a team is involved and/or you plan to have to maintain the code for years, I don't think it's the language's job to take away all the 'sharp objects'. Programmers should be smart enough to know what is sharp and how to avoid it when needed, and they should collaborate enough that no one can sneak through sloppy code. I'd rather have the ability to do certain things and rarely use it than not have the ability at all. If other programmers are constantly doing really dumb things, don't use their code in your projects.
- timr 18y agoEven in strict languages, there's rarely anything that absolutely prevents you from doing what you need to do; they just make it harder to do bad things accidentally. Languages like Ruby actually make it harder to do things correctly, and constantly tempt you with hideous shortcuts. Again, I view programming teams as groups of nosy toddlers. Thus, any sentence beginning with "programmers should be..." is wrong by definition. Programmers are people, and people make mistakes. People also get lazy, try to take shortcuts, and therefore make even more mistakes. The way that people minimize mistakes is by setting up systems that make it harder to do wrong things. This is a fundamental tenet of engineering.
- aaronblohowiak 18y agoBut wait, there's more! You can achieve immutability in ruby: http://scie.nti.st/2008/9/17/making-methods-immutable-in-ruby http://scie.nti.st/2008/9/17/making-methods-immutable-in-rub... You can achieve data-hiding if you really need to in ruby using the same techniques you use in JavaScript.
- timr 18y agoDear god in heaven, that's ugly. I sincerely hope that people voted that up out of a deep appreciation for dark, ironic humor.
- aaronblohowiak 18y ago"Can't" is very different from "can, but is very ugly." Most of the "problems" with Ruby that are often quoted are the result of bad programming and management decisions. Ruby puts a lot of power into the hands of the programmer (not as much as IO [the langauge]) and with great power comes...flexible re-factoring! Thankfully, it should be easy to re-factor the offending code, send a note to the programmer about what you changed and why and chalk it up to a learning experience. Sufficiently typed languages make re-factoring very easy. If you are having a hard time debugging your Ruby, you are doing it wrong. As for ActiveSupport's littering of Object, meh. Rails really changes Ruby. If you stick to the Rails way, then it shouldn't cause a problem in Rails projects, and it isn't a problem outside of rails projects. Don't like it? Well, there are plenty of good Ruby alternatives for the web (Sinatra!!! Also, merrrrrrrrrrrrb,) and you don't have to have everything in one app.
- timr 18y agoThree things: 1) If ugliness isn't a concern, I can do everything I need to do in C++. Arguments in favor of ugliness don't get a pass just because they happen to support your favored language. 2) What does "sufficiently typed" mean? This sounds suspiciously like a tautology: "re-factoring is easy when you've written code that's easy to re-factor." 3) The "you're doing it wrong" response is zero-content. Prove that we're doing it wrong.
- jrockway 18y agoDHINO is not really a problem. We are missing true private methods and attributes in Perl, but it doesn't stop us from writing large maintainable programs. The rule is that you don't call methods that start with an underscore from outside of the class that defines. Sure, you could, but we don't. Java's strict hiding has made my life more difficult in a number of situations. Recently, I needed to change the way URLConnection worked. I could have fixed the problem by changing a private attribute, but no no, you can't do that in Java. Instead I had to write 3 additional classes to set everything correctly for me. This is not good software engineering practice, it is a waste of my fucking time. (This was a one-off script, not a large program. Yes, I know, too many hacks and your app falls apart... but with Java you end up with an app that is falling apart AND a shit-ton of useless code to wade through.) Anyway, if you think Java-style programming is "real programming", that's great. We don't need to work together, so you are free to waste your time however you like.
- dablya 18y agoOut of curiosity, what attribute could you not change in URLConnection? I don't consider Java-style any more "real" as any other, but if something is private in a class and doesn't provide methods for modification, there is either a reason for it, or it is poorly coded... If you mess with private variables, you could be jacking up the way the class works and not know it. If you instead write 3 additional classes, you're at least ensuring your URLConnection state is consistent. > Anyway, if you think Java-style programming is "real programming", that's great. We don't need to work together, so you are free to waste your time however you like. Sounds like you're a lot of fun to work with in any language.
- deleted 18y ago[deleted]