- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
You didn't by chance take 1104 with JAN Lee did you? I remember those quizzes...
Admin
I have a serious case of Tool Blame, but it's not about coding specifically. It's about a tool that I like to call 'Visual SourceUnsafe', or 'Visual Shoot-Yourself-In-The-Foot'.
It's like a hammer that requires you to hit your thumb, each time you use it.
Admin
By "constant", you mean "literal", right, not "const int"? As in, if you have the following function (C++ syntax as I don't know Fortran):
you could issue changeToFive(0), and after doing this future uses of 0 would actually compute with 5 (e.g. 0 + 0 would evaluate to 10)?
I know there was some old language where this was true, but I don't know for sure it was Fortran.
Admin
It is "PIC BASIC", and your computer has a dedicated PIC controller, which PIC BASIC is the interface. The fact that you don't know this leads to the conclusion you have little room to speak.
Admin
Admin
I believe you are right. Enums are meant for representing static requirements. If you need to create dynamic data with a fixed structure you would usually use... (wait for it)... classes!
The only real difference between a Java class and enum, is that enums require you to specify a finite number of objects for that class. This is extremely convenient if you want to add a little bit of extra information or functionality to your enum type. This makes Java enums much more powerful then C++ enums, for example.
Admin
Yes, you could actually change any literal value. I dimly remember this feature working in Fortran II and Fortran IV, on both the Univac 1108 and IBM 360 mainframes. I think that they fixed this some time around 1972, about the same time that the default value for uninitialized variables in Control Data Fortran changed from zero to some random value.
The good old days - Actually, they sucked....
Admin
Anyone who has ever been forced to work with Rational Rose and its clumsy and horrid code generation knows that sometimes the tool is to blame :-)
Admin
Admin
Admin
I made a nifty c program that would write over its own code to change a constant... it was the start of a really nasty virus i wrote (never in the wild).
Admin
Err..... how did my nick go there? I didn't say that!
Admin
I lol'd
captcha: smile
Admin
Until Java either removes the operator overloading for String class, allows user-defined classes to have operator overloading too or changes String class to a primitive datatype, Java's a flawed language in my book.
How can you say that operator overloading is a bad language feature, then go and overload the operators on one of the most basic Java classes?
Admin
Yeah, but Microsoft's APIs still suck. That's a law of nature, not tool blame ^^
Admin
Hehe, there are few tools I love to hate. Namely the GNU open sores development tools. For example the error messages CVS spits out, I mean wtf?
Admin
How's that? In C++ you can for example represent an anonymous enum in a struct with arbitrary functions.
struct Week { enum { Monday, Tuesday, Wednesday, }; // functions be here };
Or then one could just have global functions taking an enum as an argument.
void blah(MyEnum eval) { // code be here }
Admin
Its the forum softare's fault
Admin
I just realised, I can't find anywhere in the comments where someone has simply said: variables.
Admin
"Tool Blame is that final, last-ditch act of desperation where one simply refuses to admin that he’s wrong" Had to read it three times before i realized that it should say "admit" instead of "admin". Looks like an ultimate geek-typo to me :)
Admin
Admin
I can't think of any good reason why arrays use a length field and Strings a length() method, but the size() method of Lists is inherited from Collection and while it would make sense to talk about the length of a List, that is not the case for a Set or Map. Hence, size() as a consistent methode for obtaining the number of elements in any kind of collection. Criticizing it for being inconsistent with Strings and arrays only shows one's lack of understanding, I'm afraid.
Admin
I used to work for a large insurance company and we printed customer letters on various different types of paper. One day, not long after the new system went live, they introduced a new type of paper for a new letter.
Not a problem we thought as we had a flexible system that simply allowed us to add a new paper type in the paper types database table and then associate letters with that paper type.
All was well until we found that the system was throwing exceptions whenever we tried to print the new letter. After some investigation it was discovered that a developer had decided in their wisdom to create an enum for paper types in the code, thus meaning our new wizzy, flexible system had to have the code changed every time the business decided they wanted to have a different sort of paper on which to print.
Admin
Admin
what is the Java equivalent of .NET's Reflection API? It can prove very useful here :)
Admin
Why can't C++ have full-fledged enums like this? Then I realised that it does; they're just not called enums. (Because in fact neither the Java version, nor the C++ version, is anything that a normal programmer would recognise as an enum.) What you'd do in C++ is something along the lines of
The syntax is a little botched, but you get the idea.
Why Java 1.5 sees fit to splodge yet more syntactic sugar into the porridge is beyond me. It's not as if the guys at Sun haven't pitch-forked the equivalent of generics in, thus allowing a slightly more sane approach such as the above ...
Admin
J2EE == Dumb
Admin
Admin
Admin
obiously you are one of the experts
Admin
Now it's getting really stupid
Admin
Err, you are taking the piss I assume? In JSP it's as simple as wrapping the string in fn:escapeXml{}.
Admin
java.lang.rflect - where do you think .NET copied it from?
Admin
The String class is special in Java; you can write string literals. I guess you can argue that + shouldn't mean concatenation.
But personally I appreciate that I can add floats, ints etc. with + instead of having a different operator for each.
Operator overloading only a real problem when you allow everybody to use it (look at C++ stream << and >> plus Boost::Spirit for horrendous examples).
Admin
Ahh.... I once did a purposely-FUBAR'd code that did some interesting overloads:
Hm... maybe I would've been able to send that to the IOCCC, except it was C++ and not C.
Admin
Admin
Admin
Admin
I was once bemoaning the fact that strlen() doesn't actually return the length of the string (well it does, but if you're going to malloc()...) and thought that was "stupid." When I mentioned this to a fellow for whom I now hold little or no respect, he said, "There are no stupid languages, just stupid programmers." While what he said has some truth, being called a "stupid programmer" in so many words certainly did not ingratiate him to me in the least. And besides, there ARE stupid languages, English being one of them.
Admin
Hope you've already graduated--you do know that Tech's CS profs read this site regularly, right?
Hope mruhlin isn't your PID if you're still a student...
Admin
Disclaimer: I am not a programmer.
Or not really, unless you count bash as a programming language. It's the only thing I am fluent in.
I am a Unix guy, who just believes that unix admins should know at least a scripting language and a machine language. At least vaguely.
So I picked Java because I could work it on every single of the (rather obtuse and strange) platforms I work with, and it was pleasant to work with. And the Java experience knowledge would be appreciated when working with J2EE servers. (I hate JRun. Not related, but I just felt like saying).
Reading through this: http://mindprod.com/jgloss/gotchas.html
Which was commented on a few time so far, save for a few gotchas, I kept thinking "Uh.. why are you even mentioning this.. I mean, why would I try to do this?".
For instance he somewhat expects the foreach implementation (which I didn't know about, that was useful, i've always complained about the lack of foreach, just like I deal with the fact that Perl has no case/switch) to be able to iterate over a String object? I mean, why would I think that, considering I like to think I understand to concept?
I have now come to the conclusion that people who fall into these gotchas and complain about them have been tainted by other programming languages and feel the need to complain since it doesn't work like they are used to. And the original thing-that-works-in-C-but-not-in-Java seems to usually be a gotcha in itself that just happens to work.
I don't judge which is better, I just felt the need to share that tool blame seems to be common for these reasons.
Admin
Why? The STL treats strings as collections, and std::string has a size() method just like every other collection.
I'll admit it's a weaker comparison than the .length thing, but it still would be more consistent.
Of course, the reduced power of generics as compared to templates means that a consistent interface is rather less important in Java than it is in C++.
I thought they copied it from here, or maybe here.
(Okay, I'm being a bit facetious; I don't actually think that MS designed a language that was almost the same as Java except for some rather nice syntactic sugar improvements from first principles or earlier languages. My point is that people shouldn't fault MS for copying Java because Java's a copy of what came before it too.)
I personally appreciate that I can use + in C# or C++ to add BigInts or Complexs instead of having a different operator for both.
I can't speak to the Spirit example, but I will vigorously defend the << and >> overloading. What's the alternative to operator overloading? Function calls. Which means that you can have this:
or this:
Thank you, but I'll take the former. (And I can defend cout over printf too.)
Another example that probably some people would consider an abuse of operator overloading is using them to build ASTs for expressions. In other words, given some classes that represent literal values, operations, etc., overload the operators so that something like "Tree1 == Tree2 + Tree3" will evaluate to the following tree:
Then you can assign it to something, like say "Formula = (Tree1 == Tree2 + Tree3);".
Some people would consider this an abuse. But which of the following is easier to read:
or
The former is a simplified version of what I started with, the latter what I was able to refactor it into.
It may be an abuse of the operator overloading system in some sense of the word, but I would be very very hard pressed to say that it didn't dramatically increase the code readability where it's used, and isn't that really what syntactic sugar like that is about?
(Though actually in C++ operator overloading is absolutely critical to generic programming in some instances, so it's actually more than syntactic sugar. But my contention is that it's well worth dealing with the abuses even without that.)
Addendum (2007-03-07 11:56): Actually I think I have to do a better point-by-point comparison. I also added some conversion operators (which are much more questionable than the op overloading) and pulled some other tricks (for instance, x is a string holding the name of a variable in the code instance, but a pre-built identifier node in the latter) to clear up the second one. So the non-op overloading one would look like this with the equivalent modifications:
So this looks rather better, but it's still a far cry in my mind from the op overload case.
And actually, looking at this again, I'm not even comparing the same code examples. The op-overload case is more complicated than the refactoring of the non-op-overload case.
Here is what it should have been:
Sorry for screwing up that post so badly.
Admin
I'd put it like this: there are languages that give you copious amounts of rope to hang yourself, and the people who vigorously defend such languages for their "power" usually vastly overestimate their ability to avoid hanging themselves as well as underestimate the need for code to be maintainable by people other than the original author.
Admin
Java enums are fun. They're just regular instance classes. It's literally syntactic sugar.
Is (almost) literally the same as:
Now I left out a lot of the additional methods that get added, but the important thing is that enumerated values are simply objects.
Which means that they can be null.
So, to reuse an old DailyWTF - er, WTF - tradition:
We now have a set of three values for instances of Bool: Bool.TRUE, Bool.FALSE, and null.
Real enumerations do not allow any value outside their enum, Java enums are not in fact really enums. The fact that null is allowed can cause issues.
Also, the real WTF is that the code BBCode tag is
Admin
Admin
An array's length is a final field, not a method. A String's length is a method which takes into account more than just the length of the implementation array.
List.size = standard throughout the entire Collections API Also I wouldn't exactly call the "number of elements" a "length". Either "size" or "count" would make sense.
Also remember that Java has had many incarnations, each supporting as much backward compatibility as possible. .NET had the advantage of being designed from scratch, taking all the new stuff from Java and weeding out deprecated stuff.
Disclaimer: I'm not a Java fanboy, I just don't think it deserves the crap people throw at it.
Admin
Admin
It still would be better consistent IMHO.
So? Why should I care about that? It's an implementation issue. Why doesn't a string use a final field, or an array a method? Strings are immutable, so a final field would work.
There seems to be no rhyme or reason here at least.
Admin
Also, if you want consistency in a GUI toolkit, go look at SWT. Every widget is created the same way and there are pretty much NO convenience constructors. setText is standard across everything (iirc).
Admin
wait
are you calling the guy a tool or java a tool???