4 ms·
> P&L research What’s P&L? > Java's verbose semantics Does Java have verbose semantics? I think Java’s semantics are pretty neat and concise. Where’s the ver
by chrisseaton 4y ago
> P&L research
What’s P&L?
> Java's verbose semantics
Does Java have verbose semantics? I think Java’s semantics are pretty neat and concise. Where’s the verbosity?
- mandevil 4y agoNot OP, but someone who has gotten paid to write Java for several years. I would say that isn't that Java's semantics are that verbose, it's that the way Java is traditionally written, with every line actually 3 lines on your screen of public function makeItalicTextBox(String actualTextIWantToBeItalic) { ItalicTextBox itb = italicTextBoxFactoryGenerator.GenerateFactory().buildItalicTextBox(actualTextIWantToBeItalic); return itb; } I think this is actually the pernicious work of Martin's _Clean Code_ which trained a whole generation of Java coders to write nonsense one line functions with a million interior function calls like this, not anything forced by the Java language itself, but it makes for really ugly code, in my exceptionally humble but undoubtedly correct opinion.
- deleted 4y ago[deleted]
- musicale 4y agoThe builder pattern with method chaining is unfortunate and should usually be replaced by named/optional parameters, in any sensible/modern programming language at least. IDEs are an enabler for horriblyLongIdentifierNames because they enter them for you automatically without requiring you to type them on a keyboard.
- becquerel 4y agoCan you explain why you feel this way? I personally hate named and optional parameters, as they inevitably seem to drastically inflate the complexity of the function. I would much rather deal with a builder class that encapsulates doing something over calling a method with fifteen parameters, half of which are optional. And god forbid you have optional bool args! If I need to call a monster like that repeatedly, I'm likely to make my own wrapper that's simpler anyway - so why not start out that way.
- musicale 4y agoOne thing I like is that: foo(a=1, b=2, c=3) is shorter (and, I would argue, clearer) than foo().a(1).b(2).c(3) and requires only one method declaration and one method call. Also for constructors you don't have to worry about partial or out-of-order initialization. Is the above the same as foo().c(3).b(2).a(1) ?? What if one call involves opening a file or allocating some resource that is used by another call? One nice thing that method chaining does give you is being able to differentiate external and internal parameter names. Swift (for example) supports this with argument labels for doing things like insert(something, into: list, at: position) rather than having to use the variable name: insert(something, list:list, pos:position) Of course I wish that Swift supported ObjC/Smalltalk-like syntax so you could just do insert a into: list at: position Note SwiftUI actually uses method chaining for some reason. It's OK but I would have been fine with named parameters. But I do like Smalltalk's method chaining/cascade syntax: robot walkForward; wave; sitDown.
- thirdmunky 4y agoJava idioms are one contributing factor. There's some inherent wordiness too - for example, Hello World in Java is wordier than in most other programming languages.
- chrisseaton 4y agoThat's syntax not semantics though.
- thirdmunky 4y agoagreed, I think everyone under the child comment of yours is talking about the verbosity coming from non-semantic stuff.
- coding123 4y agoThis is one of the reasons I left Java after 30 years. For those that wonder my day to day is now python and typescript.
- badpun 4y agoJava is 27 years old though?
- lumost 4y agoIt’s gotten better over the years. Java originally did not have generics, then there was the factory/uml everything crowd. Recently modern Java has been evolving towards ergonomics with streams/loom/guice/Lombok etc. However we still don’t have something like auto/let from cpp/rust.
- chrisseaton 4y ago> However we still don’t have something like auto/let from cpp/rust. But things like auto are more verbose semantics, not less! And isn’t var in Java like auto in C++?
- kaba0 4y agoThere is type inference for local variables indeed with var in java for a few versions now (from the top of my head it is available since 14?)
- mypalmike 4y agoYes. And you could use Lombok to do the same before that. (Though I'm one of the weirdos who likes Java in it's explicitness, which is related directly to its verbosity. I like reading code where I can see what the local variable types are.)
- kaba0 4y ago(I believe it depends on the exact scenario. In cases where the return type is not obvious I also much prefer explicit types (eg. ConcrType a = someObj.someMethod() ), but I don’t find A a = new A() any more readable than the var version)
- mypalmike 4y agoAgreed. I'm not sure that the shortcut existing in the language is worth the fact that other devs on my team will use it in the former case.
- nemothekid 4y ago>What’s P&L? I meant PL research as in programming language research. Not sure why my brain decided to put an & there. >Does Java have verbose semantics? I think Java’s semantics are pretty neat and concise. Where’s the verbosity? `FizzBuzzEnterpriseEdition` and is a meme for a reason. That said I'm sure Java idioms written today is a lot more sane than they were around the time everyone decided to rewrite everything in Ruby. When I say Java here, I'm talking about an era of Java that probably no longer exists (the JVM also doesn't have 10 second pauses today either and is widely considered the best garbage collector ever built).
- ncmncm 4y ago"Profit and loss"
- bitcharmer 4y agoBeen working in fintech (HFT) for well over a decade. Never seen profit and loss abbreviated to P&L. It was always PnL