spudtater: (Default)
([personal profile] spudtater Oct. 13th, 2006 05:05 pm)
I have finally joined the 21st century and downloaded the Eclipse SDK for Java development. Oooh, luxury. I don't know why I stuck with xemacs for so long!



Also: after worrying about Java generics since Java 5.0 came out, I finally bit the bullet and set to teaching myself how to use them. Result: I had it figured out within about five minutes. Easy!

Non-generic java:
ArrayList a = new ArrayList();
a.add( "the" );
a.add( "quick" );
a.add( "brown" );
a.add( "fox" );
Iterator i = a.iterator();
while( i.hasNext() )
    System.out.println( "Length of string is " + ((String) i.next()).length() );
Which is, for one thing, ugly. (LISPs!) More significantly, it can lead to type conversion errors at runtime, when you'd much prefer to see them at compile time.

Generic java:
ArrayList<String> a = new ArrayList<String>();
a.add( "the" );
a.add( "quick" );
a.add( "brown" );
a.add( "fox" );
Iterator<String> i = a.iterator();
while( i.hasNext() )
    System.out.println( "Length of string is " + i.next().length() );
Which is easy enough to understand — just read ArrayList<String> as "an ArrayList of type String". Iterator<String> means "an Iterator over type String", and so forth.



On another note: have been exposed to the dreaded C#, which Microsoft likes to describes as an updated version of C/C++, with a few influences from Visual Basic and Java. Let's take a look at a HelloWorld program in C#:
public class HelloWorld {
    public static void Main( string[] args ) {
        System.Console.WriteLine( "Hello, world" );
    }
}
Hmmm... not fooling anyone there, Billy. It's Java through-and-through, with a few syntactic differences (for example, upper-case method names) just to piss off existing Java programmers. Teh annoy.

Enough about me. How are you?

From: [identity profile] wee0ne.livejournal.com


The Perl way:

@foo;
push(@foo, "the", "quick", "brown", "fox");
foreach (@foo) {
print "Length of word $_ is ", length($_);
};


ext_79424: Line drawing of me, by me (Default)

From: [identity profile] spudtater.livejournal.com


Yes, but Perl isn't statically typed. Casting's seldom a problem in a dynamically typed language!   8^)

You can argue 'til the cows come home about whether static type checking is a good or a bad thing. I think that the world's big enough for both static and dynamic languages, and myself use both. (Specifically, python):
a = [ "the", "quick", "brown", "fox" ];
for word in a:
   print "Length of word %s is %d" %( word, len( word ) )
Typically, I'd use python for scripting and for quick 'n dirty work, but Java when I want to build a more robust application.

From: [identity profile] figg.livejournal.com


Perl is special:

print "000"+1;
1
print "1" + "2";
3
print "".0+2;
2
$a="001";$a++;print $a;
002


I like the erlang/strongtalk method: The language is dynamic, but you can define types for functions/methods and they are checked with type inference.

From: [identity profile] bassresistance.livejournal.com


I love Generic Java :) I remember it having some weird-ass "features", although hopefully they'll be much better documented these days...

From: [identity profile] yodathedark.livejournal.com


One of the things we had to use when we did Generic Java at Uni was Sahni which was a bitch...

No/incomplete documentation, no comments, having to go into the barebones code to find out what things did, ugly coding... And we had to use it to complete our assessments - that or write all the code out ourselves in our own classes...
digitalraven: (Default)

From: [personal profile] digitalraven


The sad thing is that I've been trying to learn C#. Why?

I don't remember much Java, not having had much to do with it since 2001. I could try to relearn, but there's Java and J2EE and Generics, and I don't even know if the language has proper high-order functions yet, and every time I look at the language I flash back to first year.

I know VBA, which equates to knowing a more-featured set of VB6. Trying to learn the dotNet version of said language is thus Not A Good Thing because I'll mix things up at work.

Apart from VBA, the languages I do know are scripting (Perl, Javascript, PHP - though I'll only admit to that grudgingly) or specialised (SQL, SAS, Mathematica). The others (C and C++ mostly) I don't know well enough for work purposes.

I want another job. In order to get it, I'm going to need more than a scripting language. Nobody's hiring Perl devs, and even if they were I'd be up shit creek for not using it since Uni. I'm going to need a decent, modern language — VBA is almost dead outside of financial institutions — and at present I can probably give $ORK an excuse for learning C#. Once I do, it goes down as part of my job and I get to add it to the list of things I use at work. Which means employers are going to look and see it and I can get out of SAS fairy godmother hell.

I'd go for either Java or C# TBH, but I can likely get training in C#.
ext_79424: Line drawing of me, by me (Default)

From: [identity profile] spudtater.livejournal.com


You've probably heard [livejournal.com profile] gominokouhai ranting about Java, but compared to VB, it's a good language!

C# is almost identical to pre-5.0 Java, and so there's not much to choose between one or the other. I'd suggest learning C#, since the class libraries are more Microsoft-ish, so you should find your VB experience more applicable.

That said, with Java 5.0 the language is suddenly about twice as a) powerful and b) complicated. So perhaps give Java a try after you've got your head round C#.

(Personally, I seem to be growing into that sort of programmer who can alternate between a dozen or so programming languages without much difficulty. I take a perverse sort of pride in that, even though I'm quite obviously turning into the proverbial Jack-of-all-trades.)

From: [identity profile] kropotkin29.livejournal.com


Yeah - welcome to the nineties, and a proper IDE ;-)

Eclipse is massive and contains tons of groovy features.
It will aid you massively in writing high quality code quicker than you could without it.

And yeah, generics make java code much simpler and more readable.

I suggest that you read about the new enums next.
Java has been crying out for them since its inception.... for at least 8 years. and they too have their place in the competent programmers toolbox.

C ya.



ext_79424: Line drawing of me, by me (Default)

From: [identity profile] spudtater.livejournal.com


Oooh, enums. You mean... no more lists of public static final int?! Surely it is no longer Java!

Also: new for-each loop! Hurrah! Far less nonsense with iterators.

From: [identity profile] brucec.livejournal.com


Since you don't want to inherit from HelloWorld, .NET applications live in the single-threaded apartment and since the .NET runtime will call Main so you don't have to make it public, a better HelloWorld example might be:

using System;

sealed class HelloWorld
{
[STAThread]
static Main()
{
Console.WriteLine( "Hello, world" );
}
}

From: [identity profile] brucec.livejournal.com


The C# 2.0 way:


List<String> a = new List<String>();
a.Add( "the" );
a.Add( "quick" );
a.Add( "brown" );
a.Add( "fox" );

foreach (string s in a)
{
Console.WriteLine( "Length of string is " + s.Length )
}
.

Profile

spudtater: (Default)
spudtater

Most Popular Tags

Powered by Dreamwidth Studios

Style Credit

Expand Cut Tags

No cut tags