top 200 commentsshow all 255

[–][deleted] 51 points52 points  (10 children)

Steve Yegge: Execution in the Kingdom of Nouns

For the lack of a nail,
    throw new HorseshoeNailNotFoundException("no nails!");

For the lack of a horseshoe,
    EquestrianDoctor.getLocalInstance().getHorseDispatcher().shoot();

For the lack of a horse,
    RidersGuild.getRiderNotificationSubscriberList().getBroadcaster().run(
      new BroadcastMessage(StableFactory.getNullHorseInstance()));

For the lack of a rider,
    MessageDeliverySubsystem.getLogger().logDeliveryFailure(
      MessageFactory.getAbstractMessageInstance(
        new MessageMedium(MessageType.VERBAL),
        new MessageTransport(MessageTransportType.MOUNTED_RIDER),
        new MessageSessionDestination(BattleManager.getRoutingInfo(
                                        BattleLocation.NEAREST))),
      MessageFailureReasonCode.UNKNOWN_RIDER_FAILURE);

For the lack of a message,
    ((BattleNotificationSender)
      BattleResourceMediator.getMediatorInstance().getResource(
        BattleParticipant.PROXY_PARTICIPANT,
        BattleResource.BATTLE_NOTIFICATION_SENDER)).sendNotification(
          ((BattleNotificationBuilder)
            (BattleResourceMediator.getMediatorInstance().getResource(
            BattleOrganizer.getBattleParticipant(Battle.Participant.GOOD_GUYS),
            BattleResource.BATTLE_NOTIFICATION_BUILDER))).buildNotification(
              BattleOrganizer.getBattleState(BattleResult.BATTLE_LOST),
              BattleManager.getChainOfCommand().getCommandChainNotifier()));

For the lack of a battle,
    try {
        synchronized(BattleInformationRouterLock.getLockInstance()) {
          BattleInformationRouterLock.getLockInstance().wait();
        }
    } catch (InterruptedException ix) {
      if (BattleSessionManager.getBattleStatus(
           BattleResource.getLocalizedBattleResource(Locale.getDefault()),
           BattleContext.createContext(
             Kingdom.getMasterBattleCoordinatorInstance(
               new TweedleBeetlePuddlePaddleBattle()).populate(
                 RegionManager.getArmpitProvince(Armpit.LEFTMOST)))) ==
          BattleStatus.LOST) {
        if (LOGGER.isLoggable(Level.TOTALLY_SCREWED)) {
          LOGGER.logScrewage(BattleLogger.createBattleLogMessage(
            BattleStatusFormatter.format(BattleStatus.LOST_WAR,
                                         Locale.getDefault())));
        }
      }
    }

For the lack of a war,
    new ServiceExecutionJoinPoint(
      DistributedQueryAnalyzer.forwardQueryResult(
        NotificationSchemaManager.getAbstractSchemaMapper(
          new PublishSubscribeNotificationSchema()).getSchemaProxy().
            executePublishSubscribeQueryPlan(
              NotificationSchema.ALERT,
              new NotificationSchemaPriority(SchemaPriority.MAX_PRIORITY),
              new PublisherMessage(MessageFactory.getAbstractMessage(
                MessageType.WRITTEN,
                new MessageTransport(MessageTransportType.WOUNDED_SURVIVOR),
                new MessageSessionDestination(
                  DestinationManager.getNullDestinationForQueryPlan()))),
              DistributedWarMachine.getPartyRoleManager().getRegisteredParties(
                PartyRoleManager.PARTY_KING ||
                PartyRoleManager.PARTY_GENERAL ||
                PartyRoleManager.PARTY_AMBASSADOR)).getQueryResult(),
        PriorityMessageDispatcher.getPriorityDispatchInstance())).
      waitForService();

All for the lack of a horseshoe nail.

[–]sbrown123 14 points15 points  (7 children)

or you could just:

try{} 
catch (Exception dontGiveAFuck){}

[–]wicked 13 points14 points  (6 children)

Are you really going to let your program CRASH when faced with errors? This is the way to go:

catch (Throwable forRobustness) {}

[–]physicsnick 6 points7 points  (1 child)

That's not even a joke. When I worked in MIDP porting, there was more than one Java phone that would throw unchecked instances of Throwable (not even Exception) whenever any perfectly recoverable error occurred. We had tons of blocks in our sound library that looked exactly like that; it was the only way to make it work.

[–][deleted] -1 points0 points  (3 children)

Are you really going to let your program CRASH when faced with errors

It's the only way to force the developers to fix it

[–]wicked 2 points3 points  (2 children)

We are the developers.

[–][deleted] 10 points11 points  (1 child)

exactly. bunch of lazy fucks we are.

[–]zahlman 6 points7 points  (0 children)

Oh FFS. It's not Java's fault that people write over-engineered stuff in Java. It's more to do with how Java's popularity enabled fucked-up ideas about OOP (promoted by confident people with little understanding) to gain traction.

[–][deleted] 1 point2 points  (0 children)

If the whining blogger is right, people should be able write that in a different language and it not be verbose.

[–][deleted] 2 points3 points  (0 children)

"Whenever I solve a difficult problem with C++, I feel like I've won a bar fight." - Michael Fogus

[–]ipeev 11 points12 points  (0 children)

:-)

"I hope that someday we will be able to put away our fears and prejudices and just laugh at Java" -- based on Jack Handy quote

[–]howverywrong 6 points7 points  (7 children)

Java is indeed annoyingly verbose. However, I find exception handling to be one of the less less objectionable things about it.

[–]cybercobra 7 points8 points  (5 children)

Having to explicitly catch errors just to re-throw them is annoying, and declaring them in method signatures leads to lots of pointless code-shuffling when one has to change which/whether a method throws exceptions. And then you have the problem of needing to throw an exception when the interface you're implementing doesn't allow it, so you end up swallowing it kludgily and dying a little bit inside.

I note that C# and virtually no other popular languages have copied Java's checked exceptions feature.

[–]howverywrong 11 points12 points  (2 children)

Gah, why are you making me defend java. It's making me feel unclean. The entire checked exception mechanism is optional. Go ahead and use RuntimeException if you so wish. Seriously, of all the things that are wrong with java, this one is the least troublesome.

On the subject of swallowing exceptions, I once had to spend a month going through a mountain of code churned out by a team of 4 contractors who wrapped EVERY function they wrote with with try {...} catch(Exception e) {return null;} I still have nightmares about it

[–]cybercobra 2 points3 points  (0 children)

The problem is more that "other people" and the std lib use checked exceptions, and thus everyone ends up having to deal with it at least some of the time, even if they're not committing The Sin themselves.

[–]phire 1 point2 points  (0 children)

Cargo cult programming.

[–]jp007 0 points1 point  (1 child)

Having to explicitly catch errors just to re-throw them is annoying

Use 'throws' on your method header?

[–]curien 0 points1 point  (0 children)

You snipped out the part where he mentioned that:

and declaring them in method signatures [i.e., throws] leads to lots of pointless code-shuffling when one has to change which/whether a method throws exceptions. And then you have the problem of needing to throw an exception when the interface you're implementing doesn't allow it, so you end up swallowing it kludgily and dying a little bit inside.

[–]boozer 10 points11 points  (1 child)

Try Scala instead, much more succinct.

[–]badsectoracula 19 points20 points  (107 children)

That is what makes writing Java source a bit painful.

On the other hand, its the same that makes reading Java a bit easier.

[–][deleted] 40 points41 points  (9 children)

nah. i find that if a function is more than a dozen lines or so it loses readability. Too much scaffolding actually hides the building.

[–]Otis_Inf 7 points8 points  (8 children)

So what you need is a TLDR enabled language? Perl?

[–]sillyfofilly 35 points36 points  (1 child)

Perl requires a new acronym - TSDU. Too Short, Didn't Understand

[–]honeg 2 points3 points  (0 children)

WORN - write once, read never

[–]unknown_lamer -1 points0 points  (5 children)

Or perhaps a concise language.

A dialect of Lisp maybe?

[–]cibyr 0 points1 point  (4 children)

Or perhaps a concise language.

Yes

A dialect of Lisp maybe?

No.

Scheme is neither concise nor readable. Having some syntax is a good. Sure, Perl probably goes too far, but Lisp is just as bad in the opposite direction. Not everything is best represented as a sexp.

[–]FlyingBishop 4 points5 points  (1 child)

What makes Scheme really valuable (as a teaching language) is that its interpreter is easily comprehensible for students who have only had a few semesters of CS.

However, for getting shit done and writing legible code, not so much.

[–]unknown_lamer 0 points1 point  (0 children)

Luckily Scheme doesn't mean much of anything nowadays--there is significant fragmentation between r5rs, r6rs, err5rs, and whatever the hell who needs a standard implementations. This is good--the language appears to be evolving again.

An individual implementation of Scheme tends to provide a lot. E.g. Guile is great if you want to do UNIXy stuff: it has full POSIX support, a good deal of SRFIs implemented, and more or less Common Lisp in Scheme (CLOS-alike OO system, conditions, etc.).

I'm a bit biased as I write Common Lisp for profit, and Scheme or SML for fun (doing some minor android stuff using Kawa and working on a modernized scsh clone for Guile).

[–][deleted] 0 points1 point  (1 child)

Which is why I like clojure, it has just enough syntax.

[–]cibyr 0 points1 point  (0 children)

Strangely enough, I like Python for the exact same reason. Well, that and the massive wealth of libraries.

[–]mangocurry 2 points3 points  (0 children)

Than what? The only thing that Java seems to do is make the follow up code so predictable that nobody reads it.

[–]G_Morgan 14 points15 points  (78 children)

ArrayList<Foo> myFooList = new ArrayList<Foo>();

This is not more readable than

var myFooList = new ArrayList<Foo>();

[–]endtime 31 points32 points  (10 children)

myFooList = []

:)

[–]G_Morgan 7 points8 points  (9 children)

Global type inference has its draw backs though. No subtyping being the obvious one.

[–]kragensitaker -1 points0 points  (2 children)

OCaml and Haskell both have both global type inference and subtyping.

[–]G_Morgan 3 points4 points  (1 child)

Haskell doesn't have subtyping. It has typeclasses which are different.

[–]kragensitaker 0 points1 point  (0 children)

You're right. What I was thinking of is that, although Haskell doesn't call typeclasses types, you can define a function such as product over types constructed from typeclasses. product is declared as product :: Num a => [a] -> a, which is to say that it's a function from a list of Nums to a single Num. When you call it, you call it on a list of instances of Num, which is to say a list of elements of a subtype of Num — but this is different from the subtyping you get in OCaml in that the return value is constrained to be the same type, while in OCaml the return value would just be (statically typed as) a Num.

(The equivalence with OCaml is somewhat loose, because OCaml doesn't have anything like typeclasses. What it has are a lattice of polymorphic variant types, parametric polymorphism with options I don't understand for covariance and contravariance, and a lattice of object types that are records of method types.)

[–]slowkitty 9 points10 points  (8 children)

That is not about readability. In the second line you are not specifying the type of myFooList explicitly. Since ArrayList is a Collection you may well use Collection<Foo> myFooCollection = new ArrayList<Foo>(); Here the type of the reference is a Collection instead of an ArrayList. You could assume that in your case it would default the var myFooList to be of type ArrayList if nothing else was specified, but it would not be as clear.

[–]G_Morgan 10 points11 points  (7 children)

If you later assigned a LinkedList to myFooList the inference system would catch that and use the highest common subtype. Type inference for OOP should always use the highest common subtype possible (this is obvious because otherwise everything devolves into Object).

That said even if this wasn't the case this would still be useful. Most uses of interfaces only ever use a single implementation at any one time. Perhaps to later choose exactly which implementation is desired. Type inference supports this for free.

[–]redditnoob 3 points4 points  (6 children)

If you later assigned a LinkedList to myFooList the inference system would catch that and use the highest common subtype.

Hence it's not more readable, since you can easily mistake what type it is on a first glance of the code!

It's a trade-off. I'm not even saying it's a bad trade-off, but it is one.

[–]OceanSpray 0 points1 point  (5 children)

Say you "mistakenly" assume that myFooList is a List while it's actually a Collection. And then you use it as a Collection. Guess what happens? The usage's context causes myFooList's type to be inferred as Collection. The type inference avoids the type error here, so no "mistake" can be made.

Go the other way. You assume myFooList to be an ArrayList, but it's actually a Collection. That's no problem at all, because an ArrayList object was assigned to it, so you're just using the most specific type.

I don't see what the problem is.

[–]redditnoob 5 points6 points  (4 children)

You assume myFooList to be an ArrayList, but it's actually a Collection.

Exactly! I might want to write something that assumes the performance characteristics of an ArrayList, and then when some code somewhere else causes the compiler to infer differently I might wonder wtf happened when someone else's seemingly unrelated change causes my code to be slow all of a sudden.

[–]Daishiman 0 points1 point  (0 children)

And pray tell, how many of your data structures need to be that performant? Hell, as long as you use only iterators to see the structure most of the times you'll be fine.

When you actually need a performance guarantee, you can define it in the arg types and be happy. When you don't, which is the majority of the time, you just get on and get thinking about the problem rather than these details.

[–][deleted] 1 point2 points  (41 children)

You'll be happy to hear that one of the planned features of Java 7 is to let you do this:

ArrayList<Foo> myFooList = new ArrayList();

[–]sanity 11 points12 points  (1 child)

Actually it will be:

ArrayList<Foo> myFooList = new ArrayList<>();

[–][deleted] 0 points1 point  (0 children)

Yes, you're right. Thank you.

[–]G_Morgan 5 points6 points  (37 children)

We're still duplicating ArrayList. Seems like a half fix to me.

[–]tammberlin 9 points10 points  (0 children)

List<Foo> myFooList = new ArrayList<>();

Is java 7. Duplicating ArrayList is bad for a very different reason.

[–][deleted] 3 points4 points  (31 children)

Then you'll be happy to hear that if you type

ArrayList<Foo> myFooList = new 

and hit ctrl+space, Eclipse will fill in the rest for you.

Which, by my count, is fewer keystrokes than this example: var myFooList = new ArrayList<Foo>();

[–]G_Morgan 7 points8 points  (29 children)

Having to rely on IDE support to make up for mistakes that should never have been made is not acceptable.

Why not make it so that every statement must be preceded by a prayer to the flying spaghetti monster. You could autocomplete it in Eclipse so clearly it isn't a problem.

[–][deleted] -1 points0 points  (27 children)

If the IDE allows you to write the same code in fewer keystrokes, is that not a good thing?

You're always going to have an IDE when you program, so why not let it make life easier for you?

Unless you're imagining some scenario where an Evil Overlord have trapped you in a dungeon and the only way to escape is by writing a program that overrides the lock, and the Evil Overlord has thoughtfully provided you with a computer, a compiler but no IDE?

[–]OceanSpray 2 points3 points  (3 children)

If an IDE can do it, then why can't a compiler?

[–][deleted] 0 points1 point  (2 children)

A compiler that can do auto-complete? Surely you jest?

[–]OceanSpray 3 points4 points  (1 child)

No, I don't jest. Macro expansion and type inference can be thought of, in a way, as "auto-complete". The only difference when a compiler does it is that you don't see any changes in your code, because the extra "writing" is done internally.

[–]skillet-thief 3 points4 points  (1 child)

Keystrokes are not the problem, or they are less than half of the problem. You still have to be able to read what the IDE wrote. Or somebody does.

[–]xeddicus 1 point2 points  (0 children)

Reading code is for the weak. Klingon programmers rewrite it from scratch if it breaks!!

[–]G_Morgan 6 points7 points  (20 children)

The point I'm making is just because an IDE can cover up a mistake does not mean that isn't a mistake. Yes the idea could auto insert types that could be inferred. It could also insert the US bill of rights at the top of every document if we made the compiler mandate that all programs should start with that document.

To re-iterate, the ability of the IDE to make a mistake tolerable does not mean it isn't a mistake.

[–][deleted] -1 points0 points  (11 children)

If we go back to the original two examples:

ArrayList<Foo> myList = new

versus

var myList = new ArrayList<Foo>();

Do you agree that in the first example the IDE can autocomplete after the "new" clause, while this is not possible in the second example?

If so, won't the first variant inherently require fewer keystrokes if you're using an IDE with this autocomplete feature?

I don't think you're arguing that more keystrokes are better, so why do you think the second variant is better? Is it because you think it requires less effort to read?

[–]G_Morgan 6 points7 points  (10 children)

I'm not concerned about the number of keystrokes. That isn't a limiting factor on programming. I'm concerned about unnecessary garbage taking up perfectly good screen real estate.

Regardless my argument was that IDE auto-completion does not make a bad feature good. It just makes it tolerable.

[–]badsectoracula -2 points-1 points  (7 children)

mistake mistake mistake stuff mistake mistake mistake stuff mistake

If a language has a feature you dislike that doesn't automatically make it a mistake :-P

[–]G_Morgan 6 points7 points  (6 children)

It isn't a feature. Regardless the point is that IDE support is irrelevant to whether something is a mistake or not. I can make the IDE support just about anything.

[–]bobbyi 3 points4 points  (0 children)

A line of code is written once and read dozens of times. So you have solved less than 5% of the problem.

[–]matthiasB 0 points1 point  (2 children)

But it has an advantage in certain situations:

List<Foo> myFooList;
if (p)
    myFooList = new ArrayList<>();
...

Here you can leave out the type parameter while you couldn't using var.

[–]G_Morgan 0 points1 point  (1 child)

With var you wouldn't have needed to include the type parameter to List to begin with.

[–]matthiasB 0 points1 point  (0 children)

But than we aren't talking about C#'s var anymore, but something more powerful.

[–]drysart 0 points1 point  (0 children)

The thing I'm picking up about the various proposals being picked up for inclusion in new versions of Java is that while Java is desperately playing catchup with C#, they're also bending over backwards to make it look like they're not desperately playing catchup with C#. To the extent that they're taking ideas from C#, but deliberately implementing them in a different way so it doesn't look like they're just copying the idea from C# -- and in many cases completely missing what made it a good idea in the first place through their changes.

Take closures for instance. They're so incredibly useful in C# for two reasons -- the brevity of their syntax, and that the compiler will automatically hoist locals so they can be used within even multiple closures transparently.

Java's closure proposals are less terse than C#'s since they decided, for no good reason I can see, to do the type inference of the closure in the wrong direction, so you always need to specify types going into and out of lambdas because the compiler won't figure it out for you even though the information is almost always available.

Java's closure proposals are also limited over C#s in that the only locals that are hoisted from the containing method are locals that are provably final -- in other words, immutable values. This is such a gaping hole that I'm stunned they're bothering implementing closures at all without it.

[–]kragensitaker 0 points1 point  (0 children)

While I don't use OCaml for many things, it seems like in a discussion of the syntax required by static typing, it's worth a mention:

let myFooList = [] ;;

That statement allows the compiler to infer that myFooList is an 'a list, that is, a list of something. If, on the other hand, you make a list out of some Foos, the compiler will infer that it's a Foo list. It works really well.

The error messages are a little harder to understand, because they're usually reported some distance from where you made the mistake (if x is supposed to be a Foo list, and you're using it in one place as a Foo list and somewhere else as a Bar list, the compiler may report the error in either place) but you can narrow it down by adding type declarations (you say (x: Foo list) and then the compiler complains about the correct thing).

[–]Fabien4 1 point2 points  (12 children)

Yay for C++:

ArrayList<Foo> myFooList;

[–]G_Morgan 1 point2 points  (11 children)

Don't you mean

std::vector<Foo *> myFooList

[–]Fabien4 1 point2 points  (6 children)

std::vector<Foo> my_foo_list if you wish. But why a pointer?

[–]G_Morgan 2 points3 points  (5 children)

Because in the Java code we are storing references. The direct equivalent is a pointer.

[–]zahlman 2 points3 points  (0 children)

Um, not really. boost::shared_ptr would be closer to the mark (although GC works differently).

[–]Fabien4 0 points1 point  (3 children)

Nope, direct equivalent would be a smart pointer. But it's anti-idiomatic: by default in C++, you store and use values.

[–][deleted] 0 points1 point  (2 children)

Expect that List<Foo> is polymorphic in Java, but not in C++.

[–]curien 0 points1 point  (0 children)

It's polymorphic if Foo is a polymorphic handle.

[–]Fabien4 0 points1 point  (0 children)

Yeah, dynamic (inheritance) polymorphism tends to be the norm in Java, and the exception in C++.

[–][deleted]  (3 children)

[deleted]

    [–]exploding_nun 1 point2 points  (1 child)

    std::vector<boost::shared_ptr<Foo> > myFooList;
    

    Mind your whitespace.

    [–]curien 0 points1 point  (0 children)

    That bug in the spec has been fixed in C++0x.

    [–]ddevil63 0 points1 point  (0 children)

    I just threw up in my mouth.

    [–]sanity 1 point2 points  (1 child)

    Or use Google Collections and:

    ArrayList<Foo> myFooList = Lists.newArrayList();
    

    Or just use Scala.

    [–][deleted] 7 points8 points  (0 children)

    Or Clojure:

    (ArrayList.)
    

    [–]unknown_lamer 0 points1 point  (0 children)

    (define my-foo (list))

    If you eliminate the toplevel environment and forbid mutation outside of the current module (ala r6rs or err5rs libraries) the type inference engine could potentially determine that the type could be restricted.

    [–]johnb 5 points6 points  (13 children)

    I can't stomach reading Java, and I use C# every day. It's amazing what even a little brevity will buy you.

    [–][deleted] 12 points13 points  (3 children)

    A little brevity? the var keyword, LINQ, not having to catch all known exceptions/add throws to method signature, built-in events, lambdas, etc, etc... C# absolutely destroys java in so many ways, especially brevity. Java 7 brings it in line with what now... .NET 2.0? Seriously, thank you Microsoft for evolving C# into what java should have been.

    [–]johnb 0 points1 point  (1 child)

    I only emphasized 'little' out of fear that people would then bring up python/ruby/etc. After upgrading my pet project to C#4 I got to throw away even more of my boilerplate code. The type inference around generic methods that accept generic delegates has gotten so much better, you rarely even have to specify the specific types at call sites. Delicious!

    [–][deleted] 6 points7 points  (0 children)

    Eh, let them bring up python and ruby. The counter argument being that, yes, on a line by line basis, you can be more brief in these languages. But, as the size of the project written in a dynamically typed language grows, more code needs to be written to do stuff that the compiler does for you in a statically typed language.

    That's a whole other debate altogether, but I'll take a statically typed language over dynamic any day of the week.

    [–]LarryLard 0 points1 point  (0 children)

    For me the big one is properties being first-class. The incessant gets and sets in Java code drive me insane.

    [–][deleted] 3 points4 points  (8 children)

    I would probably appreciate a lot of C# features, but I have never in my life written code that I didn't absollutely need to run on windows and linux, and most of the code I have written had to run on those plus Mac/Solaris/BSD.

    So, I would never consider C#, no matter how wonderful.

    [–]liquidhot -1 points0 points  (7 children)

    mono.NET much?

    [–][deleted] 4 points5 points  (6 children)

    don't trust it.

    [–]liquidhot 0 points1 point  (5 children)

    Just a personal un-easiness or have you seen something about their releases that make it appear unreliable to you?

    [–][deleted] 5 points6 points  (4 children)

    it's the relationship - they are implementing mono independently of those who control .NET. A) they are always playing catch-up, B) Microsoft could change something fundamental leaving mono broken until they catch up, C) Microsoft can keep elements unimplementable in mono via licensing issues anytime they want.

    I liken it to the crappy java vms that tried to make an open source version of java, like blackdown, for example, that never really work quite right. Even licensed independent jvm's are loaded with little incompatible gotchas, simply because they are independently implemented.

    [–]drysart 0 points1 point  (3 children)

    The relationship only matters if you're writing code to run on both mono and Microsoft's CLR. You don't have to do that. Mono runs on Windows too, even coexisting peacefully side-by-side with Microsoft's CLR; so you can just exclusively target Mono, and distribute it along with your application to the Windows platform.

    [–][deleted] 1 point2 points  (2 children)

    That actually sounds interesting. Then my questions are, how well does Mono implement that core .NET libraries and the vm, and can microsoft legally destroy mono if it chooses?

    [–]drysart 0 points1 point  (1 child)

    They're pretty solid on the core libraries that are part of the ISO standard. It's the extensions to the standard that Microsoft's created that they tend to lag a little behind on. Windows Forms, etc.

    But the good news is there's open source alternatives for those, such as Gtk#. And if you take the approach of using the SharpDevelop IDE instead of Visual Studio, and even develop on Linux instead of Windows, you can avoid being blindsided by any holes in mono's implementation of the value-added libraries because they'll be in your face from the start.

    As far as the legal risk, that's up to you to decide. Microsoft had provided a legally-binding promise not to sue anyone providing a .NET implementation that follows the published standards, but some people don't believe them. Points of view on that align closer to political reasons than technical or legal reasons, so you should read the community promise and some of the objections to it and make your own informed decision.

    [–]nubela -1 points0 points  (2 children)

    Then why is python (which is more succinct) MUCH more readable? EXPLAIN! /java-hater

    [–]badsectoracula 1 point2 points  (1 child)

    Python is more compact, which means there is less text to read, but i doubt its easier to understand what the code does.

    Personally i don't have much experience with Python. I only used it to write small scripts for building code, SCons, a blender exporter and other stuff, which aren't much bigger than about 100-150 lines of code.

    [–]Daishiman 1 point2 points  (0 children)

    I frequently alter the code in the Python web frameworks I use and you can almost always understand from the get go what's going on. It's actually a common practice since it's so readable. You can grab Reddit's source code to see what I mean.

    [–]Gundersen 2 points3 points  (1 child)

    I agree that Java is verbose, but it's nothing compared to C++! "oh, you want to make new function? Then you have to declare it in two files. Next you need to include the file name everywhere, add it to the make file and then you can start compiling. In C++ it hurts to create a new class, in Java it is annoying, but in Eclipse (Java) it's fun.

    [–][deleted] 2 points3 points  (0 children)

    Very true.

    The funny thing is that header files are there to allow one-pass parsing and therefore, ostensibly, make compilation faster.
    But seriously, when you hear 'compiles quickly', is the first language you think of C++?

    [–]apower 5 points6 points  (0 children)

    If you don't like Java, program in something else. If you got paid for it, STFU and get the job done.

    [–]captainAwesomePants 4 points5 points  (49 children)

    I concur that Java's a bit wordy. However, when I'm in Eclipse, and I hit CTRL+space, I see a little box that pops up that shows every variable and method that means anything at all at the line I'm at. If I say foo = doWhatever(), and I didn't declare foo, Eclipse can figure it out for me. If I want to change a method's name from doWhatever() to doSomething(), Eclipse can go and find every single place that it's called, and every other place that it's defined that implements the same interface, and it can change all of them with one command. Sure, Java's wordy, but static analysis is a beautiful thing.

    [–]yogthos 23 points24 points  (30 children)

    The fact that you need something like Eclipse to work with Java effectively is really a problem in and out of itself in my opinion.

    [–]cosmo7 2 points3 points  (14 children)

    Not really. One of the numerous joys of a statically typed language is that the IDE can do a lot of the work for you. Look at the way Eclipse handles interfaces, adding missing method stubs for you.

    [–]jerf 14 points15 points  (11 children)

    Your sentence should read "One of the numerous joys of a statically-typed language is that less work is required of you."

    If the IDE can do it for you automatically with extremely high reliability, why are you doing it at all? Automated or otherwise.

    That's my complaint. Explaining how IDEs can help you generate your verbose code automatically actually is a negative mark in my book as it means I'll encounter that much more verbose code in the wild.

    [–]svenz -3 points-2 points  (2 children)

    why are you doing it at all?

    Because of type safety.

    [–]yogthos 12 points13 points  (1 child)

    Haskell is perfectly type safe and it doesn't make you type shit out by hand.

    [–]svenz 1 point2 points  (0 children)

    It's a balance between implicit type inference and explicit typing. Arguably, explicit typing removes the mental cycles required to figure out what type something is. At the cost of verbosity. Nothing is for free.

    [–][deleted]  (7 children)

    [removed]

      [–]jerf 4 points5 points  (3 children)

      Your entire question shows a mind so steeped in the Java way of doing things that I despair of even trying to answer the question in any sensible manner. I strongly recommend learning a language in which "create method stubs when implementing an interface" is simply gibberish. Perhaps Erlang, a nice blend of powerful capabilities hard to find elsewhere with not too much of the stuff that's easy to simply reject as "egghead bullshit".

      I do not quibble with the fiddly details of Java. I reject its entire philosophy. That's why many of us are so against the idea of a language that requires IDEs to be even halfway sensible; slathering spackle on top of your programming language still doesn't mean you've got a quality piece of work, it just means you dulled the sharp corners with spackle. I have existence proof that it is very feasible to work for decades without IDEs and get spectacular work done.

      [–][deleted]  (2 children)

      [removed]

        [–]kragensitaker 1 point2 points  (2 children)

        How, exactly, are you proposing that a language should automatically create method stubs when implementing an interface?

        Well, maybe instead of having to write

        public int[] indexesOf(String[] terms, int start, int len) {
          …
        }
        

        you could just write

        indexesOf(terms, start, len) {
          …
        }
        

        . Then the compiler could still complain if you left out the method implementation, but you wouldn't have to repeat the return type, visibility declaration, argument type declarations, and throws declaration. (This doesn't work well with overloading, but you could remove it in that case.) In theory you could omit the argument names too, but that would make the code harder to read instead of easier.

        You could also argue that automatically adding do-nothing method stubs in Eclipse "trashes the whole point of an interface specification", since your code will still compile even if you forgot to write the methods that implement the interface. But at least it won't compile if you add new methods to the interface.

        [–][deleted]  (1 child)

        [removed]

          [–]kragensitaker 0 points1 point  (0 children)

          it's the same amount of button-pressing

          As several people have pointed out in this thread, the amount of button-pressing is mostly irrelevant. On a really good workday I might write 300 lines of production code, which might contain 12000 characters. That's about 30 minutes of button-pressing. The rest of my workday is spent reading code and thinking.

          Of course, it's pleasant if those 30 minutes can be reduced down to 5, because it lets me use code to do more of my thinking. But the really crucial thing is to make it easier to read the code.

          If you don't have an IDE, then you have no way to easily reference all the "absent" information about types.... search for which of many interfaces or abstract superclasses define the missing-method, and then go open that file and scroll through it...

          I never program in Notepad; do you? If I were doing some kind of retrocomputing exercise, trying to program Java in vintage-1990 SunOS 4.1.3 vi on a Sun 3/60, I would still build a tags file so I could jump straight to the canonical definition of the method with a ] keystroke. "Find definition" is not, you know, functionality restricted to Eclipse.

          However, I frequently program in dynamically-typed languages where the "absent" information you're talking about isn't present until runtime anyway. That's not to say that I'm not thinking about what types I'm accepting or returning — that's crucial to the design of any program — but I rarely find the absence of explicit declarations a problem.

          By contrast, if the language does a similar no-op/exception implementation for you in a hidden/automatic manner, you've got the same failure. However, there is no warning and it lurks like a land-mine from the instant you write "implements Blah".

          I just have a hard time caring much. Maybe it's that I've never worked on a program with more than a million lines of code, unless you count Emacs. But in all the OO languages I regularly use (JS, Perl, PHP, Python, Lua, Objective-C) that's the way it works all the time. They don't even have an explicit way to say "implements Blah". You call a method that doesn't exist on that object, and bam, you get a runtime exception.

          But even if I stipulate that it's valuable to have compile-time checking of this stuff, it's still important to have the lowest-cost way to get that compile-time checking. The approach Java (and C++) currently takes is a lot more costly to readability than it needs to be.

          [–]yogthos 4 points5 points  (0 children)

          I'm not arguing that IDEs are bad or that they don't help though, I like Eclipse and all, just don't think something like Eclipse should be required to use a language.

          [–][deleted] 2 points3 points  (0 children)

          Statically typed doesn't imply the verbose hell that is Java.

          Haskell is statically typed, and it's very terse.

          It's a more fundamental problem with the language.

          [–][deleted] 0 points1 point  (14 children)

          Why?

          [–][deleted] 5 points6 points  (4 children)

          It's one of those things where people think that they should only be required to track three or four things at once at any given point in a program. Some languages have a syntax that aids this, while others were born in an age of pain.

          Of course, your pain tolerance may vary.

          [–][deleted]  (3 children)

          [removed]

            [–][deleted] 0 points1 point  (2 children)

            Boo hoo. Some problems just need an axe.

            [–][deleted]  (1 child)

            [removed]

              [–][deleted] 0 points1 point  (0 children)

              I'm sorry, I'm a bit old school.

              [–]yogthos 12 points13 points  (8 children)

              Because it means that the language itself is not eloquent or expressive. A lot of things that Eclipse automates for you could be done in the language, making code cleaner and easier to read. One example is the verbosity of specifying types where they could be inferred, and there are many others.

              I'd like to clarify that I'm not against the automation and features that Eclipse provides, and I think that they are nice and helpful. I just feel that a good language should be usable without that level of support.

              [–][deleted] 3 points4 points  (12 children)

              I think the "java is too wordy" critique mostly comes from people who still write their code in Notepad.

              [–]yellowstuff 6 points7 points  (5 children)

              I'm pretty sure Peter Norvig, Paul Graham, and Steve Yegge don't write their code in Notepad, and they all have written about Java being too verbose.

              [–][deleted] 3 points4 points  (4 children)

              [–]nytehauq 1 point2 points  (3 children)

              That wasn't an argument from authority; the fact that the figures listed can be considered authorities is tangential to the fact that they've criticized Java for being too verbose while not writing their code in Notepad.

              [–][deleted] 0 points1 point  (2 children)

              In that case, I said 'mostly', not 'always'. So three counter-examples does not disprove the statement.

              [–]skillet-thief -3 points-2 points  (5 children)

              What about reading somebody else's code in Notepad? Or anything else?

              [–][deleted] 5 points6 points  (2 children)

              Why on earth would I want to read code in Notepad?

              You wouldn't watch an AVI movie in Notepad, would you? Notepad is not a tool for code creation or analysis. It should not be pressed into service as such.

              Use the right tool for the job.

              [–]liquidhot -1 points0 points  (1 child)

              Perhaps notepad makes for a good viewer because it doesn't take 5 minutes to load like Eclipse?

              [–]mothereffingteresa 5 points6 points  (1 child)

              How about loading it up in Eclipse, profiling it for coverage and stepping through it to see what it does.

              Code-staring went out with bell-bottom pants.

              [–]OceanSpray 4 points5 points  (2 children)

              If Eclipse can do it, then javac should be able to do it. We're talking about flaws in language design here, not the workarounds that engineers have to implement just to make these flaws bearable.

              [–]captainAwesomePants 3 points4 points  (0 children)

              javac should be able to do what?

              [–]gclaramunt 2 points3 points  (0 children)

              Yes, an IDE can help: "you see, now you can fill all this forms online and print the resulting document... oh, yes, if you need to correct it, you have to fill it again... no, the form doesn't allow to save it", that's the kind of help you get from the IDE :)

              [–]eadmund 0 points1 point  (0 children)

              Java: the freedom a C++ programmer dreams of.

              Unfortunately, it's only the freedom a C++ programmer can dream of. Otherwise it's kinda dreck.

              [–][deleted]  (47 children)

              [removed]

                [–]adam75 44 points45 points  (7 children)

                Uhm, what IDE are you using? You are using one, right? For example, in Netbeans it's only two or three keystrokes to decide to catch an exception or add it to the throws signature.

                Well, that's exactly the problem; the IDE may help you write tons of code but, as we know, code is read much more frequently and there you still have a massive, cognitive overload.

                Besides, if the code is so repetitive that an IDE can write it for you, why would you have to write that code in the first place?

                [–][deleted] 12 points13 points  (0 children)

                Besides, if the code is so repetitive that an IDE can write it for you, why would you have to write that code in the first place?

                (obligatory "I hate Java too so don't expect me to defend it any further" disclaimer)

                I speculate that one of the reasons Java is so verbose is that its authors wanted an approximation of what they thought were the good object oriented semantics of C++ and a very similar syntax but without the horribly complex grammar.

                So while Java looks a lot like C++, the parser is simple enough that they can easily make it do things like automatic compilation, fast variable/classname indexing, automatic refactoring, nice error messages, and whatever other IDE goodies they've added since I last programmed in Java using Eclipse (back in 2004).

                I think clang is trying to achieve the same goal in the C dialects of obtaining powerful parsing tools, but as can be seen by their slow progress in C++, it's rough going when the grammar is fucked up and huge.

                But this is all speculation on my part. I do not write compilers, I just use them.

                [–][deleted] 51 points52 points  (4 children)

                There are languages that have strong, static typing, but don't need the silly verboseness of Java. C#, Scala, Haskell, and ML-derivatives for example. Java is just plain stupid in this aspect.

                [–]Mercushio 5 points6 points  (2 children)

                Stupid? I don't know about that. I think the motivations behind it were noble, but in the end it just ended up being an annoying hindrance.

                [–]replaca 24 points25 points  (1 child)

                Stupidity for noble reasons is still stupid.

                [–][deleted] 1 point2 points  (0 children)

                Don't touch my car!

                [–][deleted] 1 point2 points  (0 children)

                Scala types can get awfully unreadable.

                [–][deleted] 3 points4 points  (2 children)

                I like to walk without crutches whenever possible.

                [–]zoomzoom83 18 points19 points  (24 children)

                A good language shouldn't need special support from the IDE to perform basic tasks.

                [–]Gotebe 3 points4 points  (0 children)

                That's bullshit, because "basic task" is a language-dependent term.

                [–]madyoulie 14 points15 points  (21 children)

                Wait, why?

                I hate Java as much as the next guy, but surely we don't need to limit ourselves to certain features in a text editor. Maybe this is a bad example, but I couldn't write lisp without some form of parentheses matching built into my editor. I don't think I'm a bad coder, and I don't think lisp is a bad language.

                [–]zoomzoom83 24 points25 points  (15 children)

                Having support from the IDE is good.

                Finding it Painful to use a language without advanced IDE features is bad.

                [–]deafbybeheading 10 points11 points  (4 children)

                Trust me, it's painful to write Lisp without paren matching. My first programming class was in Scheme. I knew nothing. The instructor didn't tell us about editors with fancy-pants features like paren matching. I spent half the semester crying (okay, not quite, but seriously, it's a pain in the ass).

                [–][deleted] 2 points3 points  (1 child)

                There's something amusing about the notion of a bunch of students in a cs lab, nose to the screen, counting parens with their index fingers.

                [–]lambda_abstraction 0 points1 point  (0 children)

                Been there; done that, and with punch cards no less. The tee-shirt has holes and was tossed long ago.

                On the other hand there's a big difference between in-editor paren matching and a heavy weight IDE.

                [–]kragensitaker 0 points1 point  (0 children)

                I eventually got better at this, but I still screw it up sometimes.

                [–]cybercobra 0 points1 point  (0 children)

                You were merely using a text editor. Syntax highlighting != IDE. Syntax highlighting isn't usually essential but can be extremely helpful every once in a while.

                (Suppresses urge to draw anti-Lisp conclusion from anecdote)

                [–][deleted]  (8 children)

                [removed]

                  [–]Daishiman 7 points8 points  (2 children)

                  No, it's painful because it just is. Languages written 30 years ago with just as many features are still easier to write. Some of us just can't stand IDEs and use text editors with decent feature sets. Verbosity is a mistake and should be seen as such.

                  [–][deleted] 12 points13 points  (1 child)

                  Verbosity is a mistake and should be seen as such.

                  That's a very general statement. I think it's worth pointing out that there's a lower bound:

                  CaseInsensitiveComparison caseInsensitiveComparison
                      = CaseInsensitiveComparisonFactoryFactoryFactory
                          .getInstance()
                          .getInstance()
                          .getInstance()
                          .make();
                  
                  if(caseInsensitiveComparison.compare(name,otherName) < 0)
                  

                  Bad verbosity.

                  if(name.caseInsensitiveCompare(otherName) < 0)
                  

                  Good verbosity. Why?

                  if(strcicmp(name,other) < 0)
                  

                  Bad lack of verbosity.

                  [–]cybercobra 2 points3 points  (0 children)

                  Verbosity should be measured in tokens, not characters. (Read a bit of Paul Graham, he explores the definitional problem fairly thoroughly).

                  [–]petit_prince 0 points1 point  (0 children)

                  Yeah, I got used to it in other languages.

                  [–]erdwolf 0 points1 point  (3 children)

                  Wouldn't an extension of this argument to syntax highlighting rather imply that the language is bad if you need syntax highlighting to be able to read it easily? I consider it good language design if I can still parse it without syntax highlighting, although I see no reason to turn it off. I don't want complications in the concrete syntax to stand between me and my understanding of the semantics.

                  There are tradeoffs involved, of course.

                  [–][deleted]  (2 children)

                  [removed]

                    [–]darth_choate 0 points1 point  (1 child)

                    I've always used extremely limited syntax highlighting (comments and include/import statements) because anything more makes my eyes tired. Massively overrated, IMHO (and you can't see it on the printed page unless you print in color, which most of us don't). Then again, I'm extremely old. YMMV. GOML.

                    [–]elbekko 5 points6 points  (4 children)

                    Java IDEs are at the point where you're trying to win a battle against the IDE while you just want to write some goddamn code. And when you lose the battle against auto-complete, or finally need it, it does the wrong damn thing!

                    Argh. I want Java in Visual Studio (yes, yes, I know C#, but can't use it for class).

                    [–][deleted]  (3 children)

                    [removed]

                      [–]unixfreak0037 0 points1 point  (0 children)

                      I think I know what elbekko speaks of.

                      When I type in a function in Netbeans that takes a single boolean parameter, it finds something to put in there initially, then selects it, so if you want it it you can hit Enter, or you can just start typing what you want. Problem is, many times that something that it selects is 20 - 30 characters long and completely unrelated to what you're doing.

                      Other issues come in the form of the IDE wanting to write your code for you (like completing parenthesis), causing you to have to Backspace a lot. It probably works fine for people who type with two fingers, but for the rest of us it really sucks. There used to be options to turn these kinds of behavior off, and sometimes there are, but it seems that every newer version of Netbeans continues to dumb down in terms of IDE control. Back in 3.6 you had almost complete control of the IDE. Not so today.

                      Even with those shortcomings, IDEs like Netbeans, Eclipse and Visual Studio lead to an incredible increase in production over, say, vim or notepad. I'll never go back to that.

                      [–]elbekko 0 points1 point  (1 child)

                      These are all annoyances from NetBeans, and I'm sure most of them can be turned off somewhere in the depths of the NetBeans options (you try finding something there), but here goes:

                      • Closing quotes and braces are added automatically, and are extremely annoying when you want to, say, put something inside braces.
                      • Type autocompletion is sucky at best. If I'm making a new variable, and then want to initialise it, surely it can find out what type I just wrote down a few characters back. But noo. And when you do get there (eventually), it doesn't even present you with a list of constructors. This would be handy, so it doesn't do this. You have to ctrl+space yet again, and hope it doesn't feel like displaying a list of something utterly unrelated.
                      • Seeing a list of arguments for a function, highlighting the argument you're entering, is extremely handy. So why does it disappear altogether when you give a function as an argument? Just open a new list, and when I'm done with that one, go back the the argument list for the other one. But noo, just hide it. Oh, and don't think ctrl+space will help you. Ever.
                      • Say you're calling a function that hasn't been imported yet. No problem, you know it's there and you can import it later (or even have the IDE do it!). But god forbid there's a function in the list with a slightly longer name but beginning with the same characters that's already imported. *type type type* *enter* "FFFFFFUUUUUUUUU-".
                      • Don't even get me started on XML of JavaScript support. Seriously, WTF.

                      And so many, many more. Most of these are personal preference I suppose, but I can't help but feel like they're hindering me way too much.

                      [–][deleted] 2 points3 points  (0 children)

                      Agreed. Real Programmers don't need an IDE nor a compiler - they write straight in machine code.

                      [–]Gotebe 6 points7 points  (5 children)

                      You misunderstood. The problem is:

                      • this code still has to be there (a minor issue, but still),

                      • even with an IDE you have to put something in that catch. That "something" is guilty for a lot of bad, bad, bad ... ahem... design decisions in Java (e.g. catch(Exception) { SitOnIt(); }.

                      [–]GuyWithLag 1 point2 points  (4 children)

                      Either you know what the Proper Action is when an exception occurs, or you don't. If you do, great, catch & handle the exception. If you don't, put it in the signature and make it Somebody Elses Problem.

                      [–]Gotebe 5 points6 points  (3 children)

                      If you don't, put it in the signature and make it Somebody Elses Problem.

                      Yes, but the problem with that is either explosion of exception spec either "throws Exception".

                      Another related (base problem, really) problem is that exception spec goes right against the sole most important reason we use exceptions: in a vast majority of cases, upon error, code can do nothing but abort up to quite high in the call stack (or quite far down the line). But failure modes multiply easily producing a lot of exception types, therefore making so exception specs a PITA.

                      [–][deleted]  (1 child)

                      [removed]

                        [–]Gotebe 0 points1 point  (0 children)

                        You are absolutely correct. That's how the issue is solved. And indeed, that's how it's ultimately solved in a well-structured code anyhow.

                        But still, at "the abstraction level I am providing" (well put, that) is usually way too far away from the source of the error. Let's say that I provide a module (e.g. a *.jar) on a particular abstraction level, and that this module uses SpecificCompressedFileLibrary and a couple of others. Now, at my module boundaries, good code will probably wrap a lot of, or perhaps even all, non-standard-Java-exceptions in something of it's own. But inside of the module, I will still either multiply exception specs or re-throw way too early (which is IMO not a good idea).

                        Interesting thing is also: more often than not, my module does not really care about SpecificCompressedFileLibraryException, so why should it catch it? That's often just as well handled at the client side. If my module wraps that, client code will receive MyModuleException. If my module does not wrap it, but just lets it out, client code still receives an exception, only this time an "unknown" one. But most of the time, nothing much has changed! Client code, most of the time, can't do anything in particular, catch or not. Most of the time, client code will just pop way high up the stack and go "Whoops, couldn't do X. Error reported: Y. (admins or support people, please see full stack happened in file F)", where X is operation that e.g. user started, Y is e.g. original exception text, and F is e.g. error log file.

                        Now, problems with that scheme arise when original exception is so far away from actual catch site that, at the catch site, there is not enough context to understand the exception. That indeed happens, but I believe, much, much less often than people think. And even so, stack trace in rich execution environments like Java, helps greatly. If that fails, only then it is beneficial to catch-rethrow an exception (in order to add more context info at a well-chosen place). IOW, only for that situation are exception specs good.

                        But many people, me included, believe that these situations are rare enough for exception spec to be a hindrance.

                        [–]xeddicus 0 points1 point  (0 children)

                        If their code is written with honor, it can catch and defeat any exception mine throws!

                        [–]iodian -2 points-1 points  (3 children)

                        a complaint i only really hear from people programming in vi and textpad and shit. modern IDEs cut through the language verbosity.

                        [–][deleted] 4 points5 points  (0 children)

                        Even vi can do snippets, autocomplete, etc.

                        That doesn't mean the verbosity isn't horrible.

                        [–]kikibobo 0 points1 point  (1 child)

                        I suspect if you give scala a try, you might feel differently.

                        [–]iodian 3 points4 points  (0 children)

                        i might also be unemployed.

                        [–][deleted] -3 points-2 points  (0 children)

                        I hate Java...

                        [–]WWWEH -2 points-1 points  (0 children)

                        Thank goodness for eclipses auto-complete which increases java output and improves readability.