Journal Articles
Browse in : |
All
> Journals
> CVu
> 293
(8)
All > Topics > Programming (877) Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: In Java I Wish I Could...
Author: Bob Schmidt
Date: 06 July 2017 18:01:55 +01:00 or Thu, 06 July 2017 18:01:55 +01:00
Summary: Paul Grenyer wishes for features of one language in another.
Body:
I started programming in BBC Basic on an Acorn Electron in 1985. I then went on to learn and use commercially C, C++ (there’s no such language as C/C++), C# and Java. When I was a C++ programmer, I looked down on Java with its virtual machine, just in time compiling and garbage collector. When I became a Java programmer, I completely fell in love with it and its tool chain. Not so with Ruby, especially its tool chain, a lack of a static type system and lack of interfaces.
However, there are some fantastic features in the language and a few of them I wish I could use in Java. For example, in Ruby, you can put conditional statements after expressions, for example:
return '1' if a == 1 return '2' if a == 2
whereas in Java you’d have to write:
if (a == 1) return "1"; if (a == 2) return "2";
which is more verbose and less expressive.
Ruby also has the unless
keyword, which Java lacks, so in Ruby you can do this:
return @colour unless @colour.nil?
The example shows off another feature in Ruby. To test for nil
in Ruby you can call .nil?
on any object, whereas the equivalent null check in Java is more verbose:
if (colour != null) return colour;
I could go on, but I’ll leave that for a later piece in the series. These features of Ruby may only be, in the main, syntactic sugar, but they are the ones I miss most when I’m developing in Java.
Notes:
More fields may be available via dynamicdata ..