- 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
When did < and > stop being comparisons?
The phrase you want is "satisfies an equivalence relation".
Admin
And why do you want to store a value type on the heap (to get back to the point of the OP about C# not being Smalltalk).
In other words: Why the separation between value-types and reference-types when Smalltalk already has shown that you can do proper OO without it?
Admin
C#: Console.WriteLine(4.ToString());
IL: .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() .entrypoint .maxstack 1 .locals init ( [0] int32 i) L_0000: nop L_0001: ldc.i4.4 L_0002: stloc.0 L_0003: ldloca.s i L_0005: call instance string [mscorlib]System.Int32::ToString() L_000a: call void [mscorlib]System.Console::WriteLine(string) L_000f: nop L_0010: nop L_0011: ret
I see boxing on line 5.
Admin
I prefer to call it "D-flat", myself.
Admin
It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.
In C#, booleans are indeed 1 (true) and 0 (false), but that's not the case in IL. Not every .NET language obeys that rule, and with IL assembler you can easily cast 2 (or any integer) to a boolean value. A 2-bool (later called b2) is not false, but it is not equal to "True". The most amazing thing is that, !b2 is correctly == false, but !!b2 returns b2 (compiler optimization) and is not == true. Even funnier, the VM and the VS2008 debugger will not evaluate boolean comparisons to the same result :)
Therefore, in a switch-case statement, a value different than 0 or 1, casted as a boolean, will reach the default clause.
In case you want to test it, simply use the PEX automatic unit testing framework... Lovely. Nowadays 2-bools are disabled by default, but back in the days... it wasn't.
Admin
Not knowing C#, I'm not sure I see a problem. Reading it, the programmer understood that depending on the compiler used, a bool value may not evaluate to 0 or 1. Additionally, he understood that a bool value should be a a single bit and thus he could not do b.toString().
Now there are easier ways to write the statement removing the case, (I assume there's a Boolean.toString(b) like in Java) but a "minor" optimization error like this does not appear worth submitting to this website?
Admin
What does boxing have to do with whether System.Object is the base of all objects?
The difference between a Value type and a Reference type is that Value types are allowed to live on the stack (but, they don't have to). When a Value type lives on the heap, it's exactly the same as any other object, including having a reference to it.
In other words, all types have to be boxed when they live on the heap. The magic is that Value types are the only ones allowed to live anywhere else.
Admin
At no point where you taught to think for yourself.
Admin
You could have just answered him without being a dick.
Admin
It is a shame that you were not taught to use the spell checker - or maybe even to spell without one.
tought? (was that supposed to be taught or thought?)
Admin
It's the default case that makes it art.
Admin
This WTF reminds me of something I noticed interviewing people for SDE positions. When I gave someone a coding problem, and then pointed out a bug in the solution, the majority of candidates would add lines to handle the exception. I can't remember a single candidate who dared to change the lines they'd already written.
Admin
Admin
Admin
so good!
Admin
Admin
Smells like defensive programmnig taken a little to far.
Admin
This could have just been code to "nicely" output true and false, but was never ended up being used (replace "true" for "Yes")...... Just saying that there could be a reason for it.
Admin
It isn't C-Pound, its never been C-Pound. Where's the "Pound" anyway - this is a pound symbol "£". So what if some merkins use # as pound, I'm sure a lot more Chinese people use symbols no-one else uses - does that mean we should have to use them as well? No it doesn't. Don't do it again, there's a good boy.
Admin
http://thedailywtf.com/Articles/5_years_C-pound_experience.aspx
Flagged as spam, thanks Akismet.
Admin
That is completely false. A value of 2 converted into a boolean, will evaluate to true inside a IF statement or a WHILE... However, it is NOT EQUALS to "true", and therefore will not behave as you intent in the switch-case.
The .NET Marshalling for interop does a good job and converts Integer to a valid 1-boolean, but the example uses unsafe code to cast 2 into a boolean, and you can achieve the same with 100% safe code in assembler IL, thus involving no marshalling at all.
As for someone patching the switch-case, you might consider
switch(b) { case false: return Boolean.FalseString; default: return Boolean.TrueString; }
Doing the opposite, with a "case true", will yield to incorrect results.
Admin
'equitable'? - don't you mean 'equalable'?
Admin
You're right, it's C-Hash.
Admin
Admin
Admin
Yes, humour - let's run through this for you: equatable - a real word and the one that should have been used (as you point out) equitable - a real word but not the correct one in this case not a real word and...
oh I can't go on, you get the gist :)
Admin
no - sh!t I mean equalable is not a real word - I've been Muphry'd
Admin
No, maybe not, but do blame him for not using common sense. Teachers are wrong more often than not. Especially so when they say always this or never that.
Admin
Admin
I'm not sure that this is a WTF. More like just an F.
Admin
Admin
Even then it's still a wtf. Just one by MS not by the coder.
Admin
Admin
It's nice how VB dumbs down the entire framework.
Admin
Your definition of "recent" amuses me.
Java has had auto-boxing in release versions since 2004 September 30, or roughly 6 years. For a language that was released on 1996 January 23. Which means Java has had auto-boxing for 1/3 of its lifetime.
Admin
Looks like dead code to me that is used to shut up some warning about lack of defaults in a cheap compiler or static analysis tool; the compiler should optimize it away. It looks dumb, but is cost-free.
Admin
I always look forward to a long winded and likely made up story on Tuesdays and Thursdays. Apparently I had nothing to look forward to today?
Admin
The WTF is a component vendor exposing language-specific data types from a commercial component based on a language agnostic runtime.
Admin
And BTW, he's still wrong...
The switch statement in C# does not work for any equatable types. It requires that the type is either an integral type or that the type has an unambiguous conversion to an integral type.
(And for those that don't work in .NET, take note that it does include a concept of equatable types; see, for instance, the System.IEquatable<T> generic interface. But that's not how switch works in C#.)
Admin
Admin
Admin
Admin
Different to Java? Perhaps not a lot (now I look at boxing in Java); the major difference is .Net has no equilivent to Integer (a 'boxed System.Int32' is the only name a boxed integer has.) Boxing was with .net since day 1, it's been grafted in to Java once they saw .net using it. (If anything, it's an automatic promotion/demotion between 'int' and 'Integer'). Because you cannot explicitly declare a boxed-integer in .Net, the possiblity of NullPointerExceptions is somewhat more apparent in your code.
The only reason for storing a value type on the heap that I know of is when you have a system-provided polymorphic list type that works with Objects, and you want to store integers or other value types in it. (At the time, Java people could not just add an int to a List, they had to explicitly "box" it with new Integer(..)) It's the only sane use I know of, and (these days) .Net people use generics instead which don't box.
Oh, you can do proper OO without value types. I'm guessing this is how Smalltalk does it - everything is a reference type. (In C terms, this would mean you use int* instead of int variables exclusively).
However, even there http://www.soe.ucsc.edu/classes/cmps112/Spring03/readings/Ingalls78.html there seems to be some optimisation for integers as a performance boost.
The main advantage of value types is performance, with a certain 'copy on assignment' semantics available if you're dealing with structs.
Admin
TRWTF is "Integers" that don't encompass the entire range of values.
Admin
Admin
TRWTF is "Integers" period. Screw integers.
Admin
A lot of talk about booleans. Can I do -this- in C#?
In where b is a bool.
Admin
It is the thousands of "dumb looking" snippets like that which make the majority of systems "difficult to maintain".
Admin
So I suppose you are one of those people who invite absolute disaster into their projects by using some float type to represent e.g. money values or the like? ;oP
Admin
As a Finn it constantly annoys me how some English-speaking programmer suggests that "Spell checking is easy. Just read the words file into a hash table!"
To spell check Finnish language the open source Voikko library utilizes domain-specific language called Malaga. (Yes. The dictionary file is a computer program, a bit like Infocom games are written in Z-code.)
Remember! Every time you roll your spell checker a natural blonde Finnish nubile babe stops using your program!