- 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
Fish...Shotgun...Barrel. Must control urge to shoot...Coldfusion, he, he he.
Admin
The <FONT style="BACKGROUND-COLOR: #ffffff" face="Courier New" color=#a52a2a>77</FONT><FONT face="Times New Roman"> tricked me off into believing this must have been a huge program. How else do you get to so many levels?</FONT>
I loved COBOL for it's <FONT face="Courier New" color=#a52a2a>REDEFINES</FONT>. That is the single feature that makes me want to use it sometimes. If I could have that in VB, I'ld be so happy!
Admin
A union in C is mostly the same, isn't it? No reason to use Cobol then.
Admin
As much as people like to blame the compiler when they've written dodgy code, I think you'll find the errors help people not write nonsense.
Admin
(in reference to someone who chimed in that the Java compiler is giving errors where it "should" be giving warnings)
Admin
But then again, from the same manpage:
Reading's hard, isn't it?
Admin
As one example...
<font>In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.
Fron windef.h:
typedef int BOOL;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
isActive isn't of type BOOL of course, cuz "true" wouldn't be a valid keyword.. unless it was typedef'd too.</font>
Admin
grimskunk: "As one example... In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.
Fron windef.h: typedef int BOOL; #ifndef FALSE #define FALSE 0 #endif
#ifndef TRUE #define TRUE 1 #endif
isActive isn't of type BOOL of course, cuz "true" wouldn't be a valid keyword.. unless it was typedef'd too."
No, that equates BOOL with int. C++ is case sensitive, and BOOL (from a pre-standard C++) and bool are not the same thing. Microsoft's BOOL type was one of a number of fudges, none of which completely worked, that forced the addition of bool to the language.
Admin
Try reading previous posts before making remarks 'bout reading.
Admin
I've left junk like that (not this basic, but similar) lying around before. Say, you're testing for a real condition 5 > X, and you write a bunch of conditional code, and then your boss changes something so that the whole conditional no longer applies, but only one branch of it. So then you change it to something stupid, like if(4>5){} or if(5>4){}, so that when the big guy changes his mind AGAIN, you can just shift it back...But then he never does, and it goes off to plague someone years down the line. Bad form, of course, but I'll own up to it.
I don't see why anyone would do that in this case...All he really wants is "if(true){}"
Admin
2005/12/31 23:59:59 TWO!
2005/12/31 23:59:60 ONE!
<font style="color: rgb(255, 0, 0);" size="4">2006/01/01 00:00:00 HAPPY NEW YEAR!</font>
It will be interesting to see if the ball drops a second early.
Admin
Good point, though malicious readers might object that "BOOL" isn't "bool" and "windef.h" isn't standard C++.
Admin
So you don't read compiler warnings, then? I'll tell you what: That's your problem, not mine. The one thing I remember about the Java compiler is that it often pretended to be smarter than me, and turned out to be dumber every single time. In your case, of course, the result may be different.
Java is like forcing grown men to wear diapers.
Admin
Quit your conjecture-based b*tching. Take Java's messages for what they're worth and move on. I guess when you get $hit in the way of intuitive error messages with C++, I can see why you'd hate verbosity.
Admin
Try it out for yourself. Define a class with a non-static, non-virtual member function that doesn't touch any member data of the class itself - maybe just sets a global or something for testing purposes. Call the function from a null pointer (0->func();) and trace the call in a debugger. The function will enter and execute with an implicit this parameter of 0, as required by the thiscall calling convention.
You only get into trouble if A) you call a virtual function on a null pointer or B) the function called touches the object's members in any way (oo err). At a machine code level, a call to 0->func() doesn't technically "dereference" the null pointer until the object itself is touched. This includes calling other member functions that touch members, reading or writing member variables, and calling any virtual function of the object. Basically, where x is a pointer to an object, and func is a nonstatic member function, x->func() is equivalent to func(x) in the thiscall convention. If x is never actually used in func, there's no problem. The chances of useful code not ever touching x, however, are miniscule.
So it's extremely rare that actual code will survive a call to 0->func(), but it is possible - I've seen a couple of really nasty bugs come of it. Yes, it's usually a bad sign if your member function implementations really have to check for a null this, but in some cases it is perfectly valid (such as the GetSafeHWND MFC call mentioned earlier, and certain design patterns that rely on unusual construction methods).
Admin
<FONT face="Courier New" size=2>all striking tributes to diaper fetishism aside, the java compiler is smarter than you. people who make statements about 'dumb compilers' after 1998 are either still programming a lode runner port to FORTRAN 77 or have no idea what they're talking about.</FONT>
Admin
<FONT face="Courier New" size=2>no, that is a not a troll. in fact, it's everything a troll can't be, and more.</FONT>
Admin
Nope, you have to construct the object type.
Admin
* Maurits draws Venn diagram
So... it is a troll?
Admin
Why am I not seeing a IsTrue call in this!? I mean how else could 3 < 4 be false unless we randomly choose true or false to filter out the bias.
Admin
<FONT face="Courier New" size=2>'more' is a set disjoint from the things a troll can't be. the difference of the universal set and the set of things a troll can't be is the set of things a troll can be. the intersection of 'more' and the set of things a troll can be is empty. the comment that was previous to the one i quoted fell in the union of the sets "things a troll can't be" and "more".</FONT>
<FONT face="Courier New" size=2>so when you draw your venn diagram with a red crayola marker, and partition your universe box into "troll" and "not troll", take that marker and draw a circle on your forehead. label it "more". then spin your head around and vomit blood.</FONT>
Admin
Umm...
Let A = everything a troll can be
Let B = everything a troll can Not be = complement A
Let C = everything a troll can Not be and MORE
By definition, C contains an element which does not belong to B (the MORE), thus contains an element which belongs to A. Look ma! a Troll.
Admin
Couldn't it just be everything that is not related in any way shape or form to being a troll?
Admin
<FONT face="Courier New" size=2>the powerful technique of invoking sets that do not exist in the implied universal set is lost on the masses.</FONT>
Admin
Admin
What if the exception handler checked the value of foo?
Isn't this something that all programmers are meant to know? That a computer has only a finite amount of storage?
Hasn't anyone else here paid their dues to C's malloc function, and the need to check for NULL afterwards?
Admin
How about if I learnt to programme with Python; can I think Java has a dumb compiler then?
Dumb as in statically typed, of course. It doesn't seem to produce overly much
of a performance increase, so I can only presume it's there because an assumption was made at some level that programmers need static typing.
As for the "You can't overload operators because..." thing...
I mean, Jython gets on fine with the JVM without static typing.
But, I kid, of course, I just think Java itself is a little dumb at times. ;p
But then, I'm spoilt, and I had a horrid time learning Java and dealing with unhelpful error messages. Took me ages to figure out why static methods can't call non-static methods... or something like that.
Admin
A non-static method in .Net MSIL is just an ordinary method that takes in a "this" pointer as argument 0 under the hood.
You can invoke a method by reflection or interop and pass in a null this pointer and cause null reference exceptions when a field is accessed.
Admin
Hypothesis: couldn't it just be that MORE is the empty set?
Admin
It's the numerical variables that breaks that.
Admin
<FONT face="Courier New" size=2>no. but if you've taken a stab at writing a compiler, then i suppose you could find and understand some valid critiques of the java compiler. this doesn't appear to be the case here.</FONT>
<FONT face="Courier New" size=2>well, if you're using java to write in the object-oriented style, it makes more sense to have static types. if you look at something like ML, it can be a pain in the ass to get the types working together. what you realize after a while is that if you fix the type errors, the program is pretty much correct - your algorithms might be wrong though. then ML sets you free.</FONT>
<FONT face="Courier New" size=2>there's a lot going on there you may not be aware of.</FONT>
<FONT face="Courier New" size=2>yeah, i agree. going from a dynamic to a statically typed language can be hell, if you're learning. </FONT>
Admin
<FONT face="Courier New" size=2>hypothesis: stop watching william shatner.</FONT>
Admin
At the time, did you know the difference in purpose between a Class and an Object/Instance? That difference provides your answer. Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.
Admin
Hmm... yes, especially if the set of everything a troll can be is the empty set. I suppose MORE could simply mean it was disjoint from the previous set and not that it actually contained elements. Ma, can I have more soup? Sure here you are. But Ma, the soup bowl is empty. Ah, but as long as the contents of the soup bowl are disjoint from the soup you previously had, it qualifies as more.
I don't like that. I think more means "it is not a subset of" which means that it cannot be empty as the empty set is a subset of every set.
Admin
Reminds me of my struggles with Java when I was just learning. I think the trouble was I was instantiating my object from within the public static void main of that same class and getting confused. If I had used two classes, one with a public static void main and the other to define the object I was creating it would have been less confusing. Ah - fond memories of the newbie days, like when I stuck junit.jar into jre/lib/ext and wondered why I could no longer run my unit tests....
Admin
Wow, a helpful and concise response! Grab the recordbooks!
Admin
Sorry buddy, but only the garbage collector calls Finalizers and it is only called when there are no references to the object.
Admin
I'll bet you didn't know that the Java compiler (Sun J2SE 1.5, I think that is what it's called) lets you access a private static final variable in one class from a completely different one without any warnings or errors at all. Calling it "dumb" is too kind.
Admin
Were you replying to someone? Where did you hear about this? I'd be quite surprised.
Admin
Here is a special, mainly paranoic rationale for
Imagine it is C++:
where
WTF, you ask? Yes, above is just TF. But more let's see tri-state logic class, boost::tribool...
Yes, yes, there's a conversion from bool to tristate, so we can reduce to isActive = (isActive==true);
But there might be some context: for instance,
looks more clear than reduced nonuniform expressions.
Admin
I think the issue was attempting to programme in Java like I did in Python.
I was using main() like __init__().
Or was I using it like if __name__ == "__main__" ? Either way, I'd forgotten to take my Python hat off.
At the time I was relatively acquainted with the basics of OO, but not Java's variant of it, so I knew the difference between something at class level, and something at instance level, but I'm buggered if Java didn't scare me off OO for about 3 months.
I'd just like to thank everyone who replied for not flaming me in doing so, btw, most refreshing. I've been kicking around with the idea of playing around with Java again for awhile... what sort of project does Java suit?
Admin
Without a doubt, small to large web applications. If you're going to develop a fat client with it, it's Swing components and event model are going to force you to write code you're not proud of. I would hope that .NET is better in this arena.
Admin
actually it does compile.
Admin
strftime was specified by people who had not been able to get an absolute assurance that leap seconds could not be doubled up.
Admin
The last time a triple leap second occurred was on February 29 during the third full moon of the month on a Friday the 13th (which fell on Halloween that year), and this is not likely to occur again any time soon. I remember it well; I was travelling by ship at the time and the ship had just crossed the international date line from west to east (in reverse), and a female passenger who was pregnant with twins had just given birth to the younger of her two children, and was about to give birth to his older brother....
Admin
Yeah. Wouldn't it be great if there was some kind of container, a repository, if you will, that would hold old versions of your code, and let you control it, so that you could pull that code back when you needed it again, instead of just commenting it out or writing a silly condition like that?
Well, we can dream, I guess.
Admin
That was not particularly witty or humorous.
Admin
Actually a constructor can return null. For instance in C++ when you call "new Class();" you are actually making two calls, one to the constructor and the other to the "new" operator. If you disassemble the call you see that new actually calls malloc to allocate the memory required for the new instance of the class (read instance data members). And if for some reason you don't have enough memory left in your heap malloc will return null, which means the call to "new Class();" will also return null.
Granted if you don't have enough memory left to allocate an object you probably have bigger problems like a memory leak. IMHO it's not only reasonable to check memory allocations for success in C++, it should be done as good programming practice to exit gracefully instead of crashing when you dereference a null pointer to a class and end up with "this == null" which can happen in a C++ environment, although it means you should have either initialized your variable, or checked your memory allocation.
In C#/Java I'd imagine that if you are out of heap memory and the gc can't free up more it will also return null, otherwise it would be giving you a bad pointer to memory you don't own. I do believe those languages will throw exceptions if you dereference null so this cannot equal null. In C# reflection it definately throws an exception if you try and call a member method of a null class instance.
Admin
In fact, in Java it will throw an OutOfMemoryError, and I assume C# does something similar, so you would not reach the code that checked for null.
Admin
Generally everything is timed off the chimes of Big Ben. Not that the drunken fun with fireworks in Trafalgar Square is often timed to the second, anyway...