4 ms·
Lets just take your first example. I read those exactly the same. There's no difference to me apart from taste, and potential for errors. The potential for er
by axod 17y ago
Lets just take your first example.
I read those exactly the same. There's no difference to me apart from taste, and potential for errors.
The potential for errors however, is far higher with the Moose and CLOS versions. Which is why I wouldn't like to use either of those syntax in a large project.
The java version, you can only really typo on the variable name. And even if you do that it likely won't compile unless your variables are similarly named. But with the moose example, you're starting to have silly things like '=>' which can easily be typoed and which can still compile, but completely change the meaning of the code.
Obviously at the extreme of this is regexp. Hugely compact, but a complete bitch if you typo anything. Personally I'd hate to write complete programs in regexp type syntax.
So you can keep your non-verbosity at the expense of sanity.
>> "In conclusion, Java is verbose, and verbosity is harmful."
I'd say Java has longer tokens than some other languages. By my definition that doesn't make it any more verbose. It makes it harder to go wrong with typos etc.
If you look at the underlying programming constructs in your first 3 examples, they're the same... thus for me, those code fragments are the same. No more or less verbose.
I think some of it just comes from having experience of reading code. Once you learn to read code in terms of programming concepts, rather than actual lines of code, you see no real difference.
- jrockway 17y agoThe big issue is having to manually feed data from the constructor into the fields. There is no high-level concept of "attribute" in Java, which is what programmers actually want. In Perl, you say "has foo => ( init_arg => 'foo', isa => Whatever, reader => 'get_foo', writer => 'set_foo' )" and the correct code is generated. In Java, there is no concept of "attribute", so you have to build it every time by manually declaring the field, manually writing the constructor, and manually writing the getters and setters. Anything you do manually more than once has the potential to introduce a subtle bug, and more importantly, is tedious and degrading.
- axod 17y agoIt'd take you 2 minutes to write a java preprocessor to build your constructors if you really care about such things. (I don't particularly. I don't spend much time at all writing constructors, and often want to do nonstandard things, validation etc rather than just passing over variables as they are given). With due respect, surely that's what being a good programmer is about? There's no law against preprocessing java if you really dislike the defaults. How many constructors do you write? Sounds like perhaps too many.
- jrockway 17y ago"Preprocessing Java" is called Clojure and Scala. But then it's not Java anymore, right, and the article is about Java.
- axod 17y agoAny programmer who just blindly accepts the default usage of a programming language, really has a lot to learn about programming. all languages suck for some value of 'task'.
- apu 17y agoBut almost everything in Java is more verbose, and so you'd end up writing "preprocessors" for everything (and the strong, static, explicit typing means that a lot of this preprocessing would have to be rewritten for even slightly different cases). So why not just cut-out the middle man and work in a higher level language directly?
- __david__ 17y ago> I'd say Java has longer tokens than some other languages. By my definition that doesn't make it any more verbose. I don't know, that seems to be the very definition of "verbose" to me.