4 ms·
Not 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
by mandevil 4y ago
Not 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?