Showing posts with label Nits. Show all posts
Showing posts with label Nits. Show all posts

Wednesday, September 24, 2008

Headius and the Elephant

At Cisco we used to have the phrase "No Technology Religion" on our badges and although this is easier said than done, it is the thought that counts (to double up on cliches).

It is the religious fervor (intolerance of diversity and the belief in one path to enlightenment vs. many ways to climb the mountain) that seems to be one of the differences. between between the Python & Ruby communities:

The is illustrated in the The Elephant from earlier this month:

I don't see this in the Python community, for example, which might surprise some Rubyists. Pythonistas seem to have positively embraced both IronPython and Jython. There's no side-chatter at the conferences about the evils of anything with a J in it. There's no mocking slides, no jokes at Jython or IronPython developers' expense. No "Python elite" cliques actively working to shut Jython or IronPython out, or to discourage others from considering them. The community as a whole--Guido included--seems to be genuinely thankful for implementation diversity. Even if one of them does have a J in it.

Tuesday, September 25, 2007

JRuby Enum Constants and my irrational fear of ::'s

So development on PeerTAB is rolling along. Sort of. I am continuing to play with JXTA via JRuby.

So in Java
manager = new NetworkManager(NetworkManager.ConfigMode.EDGE, "HelloWorld");

But of course in JRuby
include_class "net.jxta.platform.NetworkManager"
m = NetworkManager.new(NetworkManager.ConfigMode.EDGE, "HelloWorld")

fails with

irb(main):010:0> NetworkManager.ConfigMode
NoMethodError: undefined method `ConfigMode' for Java::NetJxtaPlatform::NetworkManager:Class
from (irb):10:in `binding'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `loop'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `catch'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `start'
from :1:in `catch'
from /home/jxta/jruby-1.0.1/lib/ruby/1.8/irb.rb:69:in `start'
from :1

So the question then I how do I get these enum constants?

So interestingly enough

irb(main):020:0> NetworkManager.constants
=> ["ConfigMode"]
irb(main):021:0>


But that did get me anywhere and it was only until I ran across this blog post that I figured it out.


irb(main):011:0> NetworkManager::ConfigMode
=> Java::NetJxtaPlatform::NetworkManager::ConfigMode
irb(main):012:0> NetworkManager.constants
=> ["ConfigMode"]
irb(main):013:0> NetworkManager.constants.class
=> Array
irb(main):014:0> NetworkManager::ConfigMode::EDGE
=> #
irb(main):015:0>

And I know part of the problem is I refuse to use :: unless I'm forced to because it seems way too Perl-ish and ugly. And yeah, I've heard there is something called C++.

Tuesday, September 11, 2007

I didn't want indentation to break my code?

I haven't done an "angry" post for a while and since I don't want to close down this blog, so I'll posit there is something unique about the Ruby community which compels folks to write lame defenses of their favorite language the way that doesn't seem to occur for other languages. I never saw this with Python or Perl, but it mostly seems to ooze from converts from Java/C++ or God-forbid PHP.

There, done, filled my quota!

P.S. - for "h3rald" or anyone else, you won't have any problem with Python if you use a decent editor like Vim and have it configured properly.

Sunday, June 17, 2007

More Stupid Ruby Tricks: has_key("hell")

What is missing from the title. The bloody question mark! It serves me right for trying to code when fried from various domestic chores. The "undefined method" exception (like many cryptic Ruby error messages) wasn't terribly helpful either, or at least in my reduced state of competency, but maybe blogging on it will get it through my thick skull that method names that return booleans have a question mark suffix. I really don't see the point. How many (I'm sure some smartass will say TCL or some happy-ass functional language I could care less with that starts with an H or L) other languages have this idiom that confuses idiots. This seems seems unnecessary and certainly violates the "principle of least surprise" or perhaps I'm misapplying the term.
irb(main):003:0> d = {}
=> {}
irb(main):004:0> d[0] = 1
=> 1
irb(main):005:0> d[5] = 2
=> 2
irb(main):006:0> d
=> {5=>2, 0=>1}
irb(main):008:0> d.has_key(5)
NoMethodError: undefined method `has_key' for {5=>2, 0=>1}:Hash
from (irb):8
from :0
irb(main):009:0> d.has_key?(5)
=> true

Wednesday, May 30, 2007

Stupid Ruby Behaviors: Episode 1 (The Injury)

Because only "moon faced" kids like me would ever write a script that both read from STDIN and use ARGV

franz-macbook:~ mdfranz$ ruby moonface.rb
ddddddd
ddddddd
franz-macbook:~ mdfranz$ ruby moonface.rb me
moonface.rb:2:in `gets': No such file or directory - me (Errno::ENOENT)
from moonface.rb:2

mefranz-macbook:~ mdfranz$ cat moonface.rb
print ARGV
moonface = gets
print moonface

What gives? See gets documentation for the answer.

The solution is to use $stdin.gets