4 ms·
There were some problems I noted: first example, the package statement is redundant. That would make the java example much shorter, and apparently shorter cod
by Stormbringer 16y ago
There were some problems I noted:
first example, the package statement is redundant. That would make the java example much shorter, and apparently shorter code is inversely proportional to e-peen length or something like that.
XML comments sounds like an interesting feature, but isn't the real feature that C# treats XML as a native type (or something like that??)
decimal as a type sounds interesting, does that let you do high precision financial math and/or math for large amounts of dollars?
object: C# capitalisation looks really random to me. I worked on a Java project once with a guy who learned on something that was almost, but not quite proper Java (Jada?) and reading his code was an exercise in going wtf? Because he didn't follow (or know, or understand) the first letter capitalisation rules.
For pi, you should of course use Math.PI not 3.14
I think the enum syntax is wrong in Java, don't you need to spray angle brackets all over it in a mad orgy of generically making it much harder to read?
Also, I don't think his println will do what he says it will do as he hasn't defined a toString method??? Or is the enum magical enough to figure that out on its own?
I knew his capitalisations were buggered up, Math.Pow does nothing in Java, should be Math.pow
Converting an int to a string should be: String s = "" + x;
Converting the string back into an int should be longer, you need to catch the possible conversion exception NumberformatException
If you're converting doubles to whole numbers, you should probably put them into either a long or a BigDecimal, rather than an int.
For string concatenation I think he's missed += I know a lot of people don't like it because they think it is slow or bad form, but the smart guys at Sun optimised the buggery out of it, so it goes like a greased rattlesnake. Check the bytecode that is produced if you don't believe me.
From the article:
throw up;
I just about did. Sorry, I had to stop, I couldn't continue.
import pounding.headache;
- viraptor 16y agoFirst package was for a comparison only. C#'s 'namespace Hello' wasn't necessary either. XML comments are more of a convention. Compiler won't prevent you from makin incorrect xml there. Yes, that's what decimal is for. Capitalisation is pretty simpl(e/istic) http://msdn.microsoft.com/en-us/library/ms229043.aspx http://msdn.microsoft.com/en-us/library/ms229043.aspx Enums -> yes, they's that magical: http://download.oracle.com/javase/1.5.0/docs/guide/language/enums.html http://download.oracle.com/javase/1.5.0/docs/guide/language/...
- contextfree 16y agoNative XML literals are a feature in VB, not in C#.
- michaelcampbell 16y ago> Converting an int to a string should be: String s = "" + x; "should" is rather subjective; there are a variety of ways to do this, and the usage of the overloaded "+" operator with an empty argument has always felt hackish to me. String.valueOf(int_var); is equivalent, but (also subjectively) more cleanly shows ones intent.
- Stormbringer 16y agoI was reading through some Python the other day (could have been "learn Python the hard way") and it struck me that one of the things that people like about it is the way it handles Strings, or the 'power' it gives you over strings or something like that. Objecting to using + or += overloading on strings in Java seems to me to be cutting off your nose to spite your face. In Objective-C for instance I dearly wish that there were better ways of slapping strings and integers together. But no, everything seems to be a call to some oddball class method with optional formatter classes and other magic constants tossed around with gay abandon. Or alternately, sometimes you can use C-style format strings, and sometimes you can't. Enjoy. In Python would you object to nesting "s and 's because it feels hackish? In Lisp would you avoid Macros because they are hackish? In Perl would you avoid regexs because they are hackish?
- michaelcampbell 16y ago> Objecting to using + or += overloading on strings in Java seems to me to be cutting off your nose to spite your face. Nowhere did I say you shouldn't use them; I said your assertion of "should" was subjective at best and "clever" in a bad way, since you're only using it for the side effect of auto-boxing the int INTO a string; not its intended purpose of concatenating strings. > In Python would you object to nesting "s and 's because it feels hackish? In Lisp would you avoid Macros because they are hackish? In Perl would you avoid regexs because they are hackish? No, because none of them are.