News for hackers. Stuff that matters.
Re:New IDE: code bubbles by jacquesm on Wednesday March 10, 2010 @05:17PM (#1182156)
IDE's can be neat, but plenty of people seem to use them as crutches to keep on walking through minefields of APIs.

Since the IDE remembers all your parameter sequences and types there is also less incentive for developers of APIs to think ahead of time and plan their interface so it is consistent and easy to remember.

Re:New IDE: code bubbles by pohl on Wednesday March 10, 2010 @05:50PM (#1182237)
I'd like to have a dollar for every time I've seen a NullPointerException on some line that was constructed by someone who loves the list of methods that automagically pops up for the dot operator:

  foo.bar().baz().qux()
...Grrrrr!
Re:New IDE: code bubbles by jrockway on Wednesday March 10, 2010 @06:03PM (#1182278)
If only there was some combinator for sequencing computations... then you could write:

   foo >>= bar >>= baz >>= quux
and there would never be a NullPointerException, because the >>= function could react appropriately when null was encountered!
Re:New IDE: code bubbles by KirinDave on Wednesday March 10, 2010 @06:41PM (#1182357)
You win at the "Most Subtle Haskell Reference" in this conversation.
Re:New IDE: code bubbles by cujo on Wednesday March 10, 2010 @08:01PM (#1182490)
Since I don't know haskell, I'll throw out that groovy does this too.

foo?.bar()?.baz?.quux

What other languages have this kind of shortcut?

Re:New IDE: code bubbles by aquadoctorbob on Wednesday March 10, 2010 @08:55PM (#1182586)
Re:New IDE: code bubbles by grayrest on Wednesday March 10, 2010 @11:51PM (#1183013)
Since coffeescript was mentioned, the Ruby andand library is also frequently mentioned when this comes up. (I only ruby for Rake).
Re:New IDE: code bubbles by doki_pen on Thursday March 11, 2010 @09:16AM (#1183736)

  $ irb
  >> def nil.method_missing *args
  >>   nil   
  >>   end 
  => nil
  >> a = nil
  => nil
  >> a.b.c.d
  => nil
  >>
Re:New IDE: code bubbles by rcoder on Wednesday March 10, 2010 @06:09PM (#1182292)
You know what's even better? When someone who writes that style of code (in C++, no less!) knows that one of the intermediate values could be null, so they use a set of macros involving setjmp and longjmp, and trap SIGFPE, all to implement a fragile sort of try/catch for null de-references.

Clever? Insane? Horribly un-portable and prone to breakage depending on compiler, libc, and OS versions? All of the above!

(And yes, I have seen this coding style used in multiple projects at a major corporation. It was a favorite of a coder-turned manager, which means it tended to sneak in on any project he supervised.)

Re:New IDE: code bubbles by jrockway on Wednesday March 10, 2010 @06:38PM (#1182351)
Clever? Insane? Horribly un-portable and prone to breakage depending on compiler, libc, and OS versions? All of the above!

Yeah, you already said it was C++.

Re:New IDE: code bubbles by logicalmind on Wednesday March 10, 2010 @06:06PM (#1182287)
And thus, the Maybe monad was born.
Re:New IDE: code bubbles by Retric on Wednesday March 10, 2010 @05:59PM (#1182269)
Try catching a block that does that is actually less code than a long set of conditionals. Granted it's basically saying:

  if (foo != null) if (bar.bar() != null) if (foo.bar().baz() != null) {
  ...
  worked = true;
  }
  if (false == worked ) {/*to do*/}
But, staying on the happy path until you can demo something is often useful. I think the problem is how you transition from demo to production worthy code.
Re:New IDE: code bubbles by alttab on Wednesday March 10, 2010 @10:55PM (#1182884)
if (foo!=null && (a = foo.bar()) && a != null && ...

a = foo.bar() will always evaluate to true as the assignment shouldn't ever fail. Of course, in compiled languages I'm sure there will need to be a declaration of 'a' but if there is a possibility to reuse temp variables then could work.

However, if you are coding in C/C++ (and to a similar extent Java, there really is no way around it.

This could be an example of why hybrid functional, imperative, and object oriented languages are becoming popular because the programmer can pick the paradigm that most suits the problem.

Re:New IDE: code bubbles by guelo on Wednesday March 10, 2010 @08:55PM (#1182587)
That's not the same since you are executing the bar method multiple times.
Re:New IDE: code bubbles by sukuriant on Wednesday March 10, 2010 @10:57PM (#1182887)
If you really want to get picky, return foo.bar().baz().qux() * 2;

Could become:

  Bar bar = foo.bar();
  if(bar == null) handleBarNull();
  else { 
     Baz baz = bar.baz();
     if(baz == null) handleBazNull();
     else { 
        //(assuming qux is a value)
        return baz.qux() * 2;
     }
  }
Re:New IDE: code bubbles by guelo on Wednesday March 10, 2010 @09:02PM (#1182603)
That might be the correct way to write that code if the situation is not recoverable.

Say you have

    public int doubleFooBarBazQux(Foo foo) {
      return foo.bar().baz().qux() * 2;
    }
That might throw a NPE, but what's the alternative?
Re:New IDE: code bubbles by jrockway on Wednesday March 10, 2010 @10:09PM (#1182769)
I typed this into Eclipse, and it's super-awesome-excellent auto-code-writer decided that it should be:

   public int doubleFooBarBazQux(Foo foo) throws NullPointerException {
     try {
        return foo.bar().baz().qux() * 2;
     }
     catch(NullPointerException e){
        throw new NullPointerException(e.getMessage());
     }
   }
If only there was a right-click option for "improve quality"...
Re:New IDE: code bubbles by ewjordan on Friday March 12, 2010 @01:11AM (#1185937)
Yeah, the generated code is asinine, but what would you prefer? "Improve quality" in this case would just leave out the try/catch altogether. Is there another behavior that would be better, given that we know nothing about foo, bar, baz, or qux?
Re:New IDE: code bubbles by jacquesm on Wednesday March 10, 2010 @06:07PM (#1182290)
You'd be starting the 'Pohl foundation for old programmers' from the proceeds before long, I gather.

Code like that is really common, and, unfortunately, so are blank 'catch' sections.