Re: [ljc] Return types

From: Colin V.
Sent on: Tuesday, February 12, 2013 8:57 PM
I'm interesting in the thought processes behind a method that explicitly returns nothing having to state that it returns null and deviates from pretty much every piece of Java I've ever seen.  Given the points you've stated:

> this is best because:
> - everything should be an object (Integer instead of int, and so on)

Why?

> - it's type-safe

Why is it anymore type-safe than "void"?

> - allows multiple calls on one line (saving vertical space, e.g. return runStuff(doTask()))

Is vertical space at such a premium? In the example you've given, this seems like you're relying on the side-effects of doTask() but don't actually ever give that result to runStuff().

Apologies if I seem harsh, but you really have me bamboozled on why you'd want to do this.


On Tue, Feb 12, 2013 at 8:14 PM, Jonathan McNealy <[address removed]> wrote:
Hi guys,

We've been debating this for a while here, and we can't decide between the following two development methodologies with respect to the return statement.

It's currently policy to write functions that don't return a value like this:

public Void doTask() {
  ...

  return null;
}

this is best because:
- everything should be an object (Integer instead of int, and so on)
- it's type-safe
- reflection is more consistent, as the primitive/object difference api is a pain
- allows multiple calls on one line (saving vertical space, e.g. return runStuff(doTask()))

however some of the newcomers to the company are rather dismissive of the benefits of Void, and insist of the following nasty and inconsistent way of doing it:

public void doTask() {
  ...

  return;
}

and some deviants even insist on removing the return statement:

public void doTask() {
  ...
}

!!

I'm currently in the process of writing up a JSR to only support the Void/return null pattern, as it's clearly the most consistent and only having one way of doing something is the best approach, however I'm curious as to what the community thinks about the issue.

Please don't cheat by casting your vote more than once!

Kind regards

J.





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jonathan McNealy ([address removed]) from LJC - London Java Community.
To learn more about Jonathan McNealy, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]



--
Maybe she awoke to see the roommate's boyfriend swinging from the chandelier wearing a boar's head.

Something which you, I, and everyone else would call "Tuesday", of course.

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference, in collaboration with the LJC 12/13 Jun 14

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • Packt Publishing

    A publishing company specializing on specific technologies and solutions

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy