Atlas · Details
Blogger's Block #4: Ruby and Java and Stuff
Author’s note
Solid piece, but dated and (as is oft the case) 20% too long.
Pretty much only interesting reading if you are a hardcore language geek.
AI Notes
The closing post in the four-part 2006 Blogger's Block series — a medley of small observations. The lead bloguette is a Sunday walk through the Barnes & Noble tech section: eleven Ruby/Rails titles where a few months earlier there had been almost none, against thirteen for Python. The admission underneath: Steve uses Ruby for everything he can, and isn't even sure he likes it. Liking and using are "mostly orthogonal dimensions." He has 3× more Python experience and 10× more Perl, and uses Ruby anyway because it's the path of least resistance for almost every scripting task. Bloguette #2 is a long detour on Java's biggest failing — the lack of literal syntax for hashtables, lists, objects, and functions — and how that drives Java programmers into XML and YAML for data they should be able to write inline.
Related listings
-
2006
Blogger's Block #3: Dreaming in Browser Swamp
The same week's #3, on JavaScript as the most important language in the world. The two posts sit together as the latter half of the four-part bloguette medley.
-
2007
The Next Big Language
Five months later, Steve sketches the language he wishes existed and which Java/Ruby/Python are each only half of. Read together: this post is the diagnosis, NBL is the prescription.
-
2005
Choosing Languages
The earlier, longer version of the same conversation Steve has with himself here about which language to use and why. The Drunken-blog form is the deeper essay; this one is the bookshop sketch.
From the peanut gallery
Read the rest of the thread · 28 more
-
Regarding first-class Java functions, have a look at http://gafter.blogspot.com/2006/08/closures-for-java.html .
-
Even though it sounds like you'll never get a chance to use it, C# is actually picking up some of the things you've wished for. For one, you can do the anonymous method thing easily now. Furthermore, C# 3 (coming next year?) gives you a better syntax for that (lambdas), extension methods (kinda like degenerate mixins if you squint), and better object initialization. You don't get the hash stuff, but you can easily create new objects with their properties set to specified values.
Something like:
Customer c = new {Name = "Rob", State="Texas"};
Better type inference is coming too so there's less Customer c = new Customer crap all over the place. -
Python has them too, but unfortunately they can only be one line, so Python folks prefer to pretend anonymous functions aren't very important.
I prefer to pretend that the "anonymous" part of "anonymous functions" isn't very important. Yeah, there's no good way to directly pass a function literal. But you can define the function with a name and pass the name, and it works just about as well. It is a tradeoff, as you say, but I don't think it's as big of a tradeoff as you make it seem, in exchange for the good structure provided by the whitespace.
This is one of the 10 or so big problems caused by Python's whitespace policy.
Could you list them? Because I keep seeing people talking about the "big problems" the whitespace policy causes, but I can never find one that actually impacts me. Could be I'm programming in the wrong fields or haven't been programming long enough, but I'd still like to see what they are. -
tassos: Thanks for the link. Looking forward to it. I think they actually have some great stuff up their sleeves for Dolphin and beyond.
If this makes it through, Java will get a lot of new steam. Tons. Oodles. It would be huge.
Then all they need is literals. Collection literals, yes, but also BigNumber literals, regexp literals, multi-line strings with variable substitution, at the very least.
Oh, and indexing and concatenation operators for collections, and maybe a limited form of continuations, and we'll finally be getting pretty close to a good language.
Combine that with a great platform, and I can probably declare my language-ranting closed for a while. I'm guessing it'll all come together by around JDK 9. -
>>Tassos said...
>>
>> Regarding first-class Java
>> functions, have a look at http:/
>> /gafter.blogspot.com/2006/08/
>> closures-for-java.html
Well, of course in any Turning-complete language you can accomplish basically anything you want to do (namely, implement a Lisp interpreter in Java), but why not save yourself trouble now (and in the future when you're fixing bugs and trying to figure out what's going on) by using a respectable language? -
Please disregard the previous comment; I have made a misinterpretation.
-
Until I read this article, I thought Java and C# were relatively (*very*) similar. I haven't worked in Java since 2000, so I just assumed the stuff I saw in C# was in Java too. For example, C# has limited support for operator overloading ([],+,etc.). In .NET v2.0 C# picked up generators, anonymous methods, generics and partial classes. [Side Note: I believe partial classes to be a big win because you can code generate part of a class and then custom write the other part in another file. The result being that you can regenerate the generated file without hurting your custom code.]
In terms of your literals discussion, I completely agree with you, and it's obvious you have been programming in Ruby lately, since it has syntactic sugar for everything that you mentioned. I would throw in that they should also steal regular expression syntax from Ruby/Perl/Python as well. Having spent about six months working on the side in Ruby, I understand your frustration. I feel the same way about C# when I have to go back to it from Ruby. -
The ol' "Ruby's sellin' a lot of books" argument could be dangerous.
I mean, I never had to buy a book to learn Python. ;)
/troll.
Just kidding, but I'd recommend watching out for those oversimplifications.
Out of curiosity Mr Yegge, when you were porting your Python to Java to make it run faster, what was Python's threading lacking?
I'm not too au fait with what Java offers in that department, so I'm having trouble following your train of thought.
Also - a query on lambdas in Ruby, does it offer anything like Lisp's labels? -
The invisible element with ruby and python though is speed (lack of). You touched on it with your example of converting an app from python to java.
It means Sun adding a scripting language isn't enough. We want to have our cake (ruby) and eat it too (fast, static type inference). It would be nice to see a language like boo or C# 3.0 for the jvm. Scala and Nice are the closest candidates I believe.
And I agree with code monkey, some of what you said sounds like C# 3.0. That's one language I don't think you've tried out much (also vb.net), not that you need to or should.
But they for example are adding support for xml literals in the language (javascript too i believe, E4X). That doesn't make much sense to me. I also think XPATH is a very clear and succinct syntax for navigating structured data like xml, and would like to see better xpath integration in a language.
I should mention too I did see a paper on type inference for javascript. Maybe that's a direction Sun should head now that it has adopted Rhino. -
Hi Steve,
All good stuff, but to be honest, the only time where I hardcode literals inside maps or lists is when I'm setting up tests with dummy values. For production code, I pretty much never need it.
My number one feature request for Java is still a concise notation for accesssors, because even now, I use these all over the place (#2 is closures, of course, but we're working on that).
--
Cedric -
"Not only is the latter bloated and ugly and error-prone (can you spot the error in mine?), it's also butt-slow."
No, I can't! Is something wrong with me? I even coded it and it works fine. What am I missing? -
I don´t see why a tab based language can´t have anounimous methods. Boo (boo.codehaus.org) has a tab based style like python, and has closures that can take more than one line, and literals for hashs, arrays, all that been a static language, but with type inference. I think that the greatest problem with java is the idea that only OOP can be used, all need to be a object, in python it don´t need to be this way, and in ruby, all methods live in objects, but it don´t force the concept.
An interesting thing is that many of those features are coming to C# 3, (and are already in Boo, and of advertising ;) ) -
Some kludgy solutions you can use to initialize a list, using varargs:
List foo = Arrays.asList("1", "2", "3", "4"); // using varargs
// Lame, but works for strings
Properties foo = new Properties();
InputStream is = getClass().getResourceAsStream("hash.properties"
foo.load(is);
I know there are others... -
amen on the need for literals for common data structures like hashmaps. sigh, i still miss NeXT's property-list (plist) syntax -- a version of which is still in use at Amazon... and, of course, still survives on NeXT Step, I mean OS-X.
-
the "error" is the 'w' was capitalized as 'W'. (Or I think that was it.)
-
Regarding your comments on java.nio, I absolutely agree with you that the API is gross. The problem is that java.nio implements the Reactor pattern from Pattern-Oriented Sofware Architecture vol 2 by Douglas Schmidt et al. without the possibilty of using select in a way you would do it on UNIX.
About your complaints about a layer on top of java.nio, I actually think you can almost do the task you described, it is just burried in the grossness of the API. I vaguely remember doing stuff similar to what you described with the DataInputStream when I wrapped my head around the API (I might remember wrong, though) and all the abstract classes etc (java.nio beats every creational pattern on steroids: "how the .... do I get an instance of this class grrr"). Java.nio is close to incomprehensible if your only source is the Javadoc.
A small note on missing data structures in the Java lib: there has actually been a java.util.PriorityQueue implementation since 5.0.
I've noticed you are beginning to mention the relatively unknown language Lua. Has anything special about Lua caught your attention? I think the language and its implementation is great, but I've only used it for embedding into C programs, which makes low level coding in C tolerable because you don't actually have to code in C. -
Just to re-iterate what some other's have said, it really is worth investigating .NET. The fact that Unix based companies don't use it is a bit of a self-fulfilling prophecy. (Yeah, Windows has a way to go before it can be an acceptable platform for Google, but it does alright for Dell.)
My own take on the JVM changes is that basically Microsoft have forced them into it. Lots of languages seem to target .NET, because the VM developers listen and have a high quality product.
Other features worth mentioning:
there's no hashtable initialisation, but anonymous classes in C#3 are well worth looking at. There's an expression model similar to LISP's. Co-routining has been there since C#2. It's actually usable, too...
On the other hand, I'm coming to the unpleasant conclusion the ASP.NET is actually an anti-productivity tool. -
Why isn't that
blog.addChild(
new BloggersBlock()
.setFinished(true)
.tieOffAndStuff());
(except for API stupidity)?
By the way, I even experienced the comment dread on my previous comment. Took me a week to check if there was any followup... -
Steve,
>It's the browsers' fault: they START with three languages (HTML, CSS, and JavaScript), rather than having just one language to control the entire presentation, and it only goes downhill from there.
Since this is maybe the third time you have brought this up in your blog, maybe it is worth an action.
1. Come up with new language specification that satisfies the above.
2. Update firefox or some other open source browser to support it.
Probably non-trivial, but might be worthwhile for the potential impact and others might jump in to help.
Amit C -
Just to re-reiterate. Try c#.
I tend to make a similar comment to linux-only freaks. If you dont take a look around, you may miss out on good things.
it's unfortunate mono isn't farther along. -
> Thank God they didn't bundle Groovy. What a catastrophe that was, and still is, and would have been for Java if they'd bundled it.
Why not? I've been monitoring Groovy's mailing list and have been playing with it for a while. It seems like supurb language, especially for JVM (to compare with 'just ports' like JRuby or Jython). Any particular reason you think Groovy is so bad? -
vlad: Try to 'google' for "jvm shootout groovy" and select the cached archive as the site is currently unavailable. There you'll find your answer...
-
Another (fairly dirty way) to have smaller initialization blocks for complex data-types is using an anon. inner class with initializer. So the list [1,2] can be initialized as:
List<int> list = new ArrayList<int>() {{ add(1); add(2);}};
We have a literate testing framework which is essentially a DSL embedded into Java for web app testing, do you have any thoughts on it? -
I have a blog that has rapidshare links and tutorials on various topics like ERP, programming languages, networking and ecrtifications etc.. Would you like to exchange links
You can checkout my blog
Please visit
http://arbizaa-softwareworld.blogspot.com -
One of the most important aspects of acne prevention is to keep the skin clean at all times or as much as possible. Regular bathing is essential. While bathing, be sure to scrub the skin until it is well exfoliated. Be careful not to scrub too hard, as this may irritate and dry out the skin, leading to more outbreaks. You may be better off getting a gently exfoliating product, such as Proactiv skin care when washing to prevent over exfoliation. The skin must remain as dry as possible and not be exposed to excessive perspiration. If you participate in strenuous activities, you will want to remove a sweat soaked shirt after you are done. There is also the factor of what clothes you wear in regard to acne outbreaks. Tight clothing or carrying heavy materials such as backpacks will chafe and irritate the pores and lead to flare-ups by rubbing across the hair follicles. It is advisable to alternate tight fitting clothes with loose fitting ones occasionally and to try alternating backpacks with side packs or handle bags.
-
This comment has been removed by the author.
-
Acne is a systemic inflammatory disease affecting the skin. Current statistics estimate that it is endured by 90% of adolescents, almost 50% of all adult women, and 25% of all adults, either chronically, or at some point during their lives. Acne is the most common skin affliction in the world, yet quality acne treatment is still a mystery to many sufferers. Although there is no absolute cure for acne, the treatment options available in today world make it a far more manageable condition than ever before.
Check for more Acne treatment information and products.
http://www.acne-treatment.net -
The Google Collections API has some of the extended collections you're interested in.
What's even worse is that Java array initializations are really the same old Swing-style code under the table. When I wrote a large initialized static array in my early days of writing Java, the code in the hidden "<clinit>" method had one call for each element! I rewrote the thing to be a big String instead of a big Array, and the class shrank to a reasonable size.
cynos, the problem with Python threading (and Ruby, and most flavors of Scheme) is that it's what Java folks call "green threads". Each thread is much more lightweight on a single-processor machine, but the program as a whole can't take advantage of multiple processors at all. This problem is going to come up and bite the dynamic languages in the butt Real Soon Now.
— John Cowan · 2:03 PM, September 27, 2006
I wrote more about language expressability in The Ex Factor the other day.
(I also think the Ruby book sales statistic is very misleading on a quarter-by-quarter basis; most of the analyses I've seen fail to take into account the relative freshness of books in the channel, the number of books sold-through historically on a subject, and the publication ates. Those are all important factors.)
— chromatic · 2:59 PM, September 25, 2006
The Ruby book surge is not because of Ruby's language features, it's because they finally got a killer app: Rails. Without RoR you wouldn't see 80% of those books.
— nyenyec · 6:07 PM, September 28, 2006
holy smack you write a lot
— Charles Finkel · 11:29 PM, October 02, 2006