- 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
public class types { public enum bool {
} }
Almost like nullable bool in C#
Admin
Java??? with colons for types and "function" keywords??
TRWTF: faking code?
Admin
That's not Java.
Admin
For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.
Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....
Admin
That second example isn't Java.
Admin
Admin
But how can you really check if the result of the isTrue() function is really true?
Oh, I get it!
if (BooleanUtilities.isTrue(BooleanUtilities.isTrue($val))) ...
Admin
Ah, the age old problem...
"Pilate saith unto him, What is truth? And when he had said this, he went out again unto the Jews, and saith unto them, I find in him no file at all."
Admin
The second example looks like TypeScript. Not many languages have colon-delimited types.
Admin
That is not true. David Attenborough would have told us.
Admin
That is not true. David Attenborough would have told us.
TRWTF is the delete button right here !
Admin
The "java" code is actionscript
Admin
That other example isn't Java... its Adobe ActionScript.
It follows this format
variable:DataType
function funcName(arg1:DataType, argN:DataType):returnDataType{ //contents... }
Admin
This was my favorite:
...the original author works now as chief developer for an Austrian company which codes software for medical healthcare...
Admin
Admin
Admin
In before FILE_NOT_FOUND = FALSE
Admin
The difference is == allows for type conversions while determining equality. === does not. Speed isn't a main reason for using it, it's based on whether or not you want to allow a true result if both sides are different types but with the same content.
Eg "0", 0, false, null, undefined are all ==, but not ===.
This only applies to primatives, classes (like Arrays and Objects and so forth) are judged on equality by reference only so there's no difference between == and === in those cases.
Admin
"Sim" is "Yes" in Portuguese.
Pronounced, it sounds close to the word "sing" in English.
All that said, it still doesn't make sense.
Admin
Functions of the form:
public function isTrue(arg:Boolean):Boolean public function isFalse(arg:Boolean):Boolean
do server a useful purpose - you can use them as functors, delegates, etc. a veritable slew of cases where one needs to be able to invoke (explicitly or under the covers).
Now having the if statement inside is wonky, but it does provide a place to put a breakpoint.
Admin
This would make Yoda's head explode
Admin
Not a programmer here; could someone please explain to me what the thought process may have been to create a true/false test for a true/false test? I thought that was the whole deal for boolean logic?
Admin
I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned. I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced... Which then made me replace the whole thing with return boolean1 == boolean2;
But there are pretty much something strange with booleans every week when I'm digging around in code.
Personally I think that being able to handle boolean logic should be a very lowest expectation of someone that is supposed to create software... No wonder every piece of software is crap and bug ridden, because if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?
Admin
Just last week I found a tri-state boolean managed in our application database. If you put true as the value, the code does a check on some subsequent fields. Put false and it doesn't check, but it writes a log entry. Put null and it does nothing. It's mapped to a string property using NHibernate and the getter calls .ToUpper(). There will be blood.
Admin
Pretty much the first thing I do when evaluating software (whether it's a code review sort of thing or third-party) is to try to look at the small things.
Through many years in this industry, I've found that when people can't get the little things right, it's very unlikely they get the big things right.
Admin
I would assume the logic is that "if (X)" might be confusing to read where "if istrue(X)" isn't. I can read either with relative ease, but someone new to programming might find the latter helpful.
A nullable bool might be useful when, to pick an example, processing a true/false set of questions. You will need to deal with the difference between True, False, and Did Not Answer The Question. Assuming a default of 'false' would skew the results.
My personal favourite of these sorts is the classic
if (x == false) {x = true};
Admin
In a similar vein, can anyone explain why
couldn't just be written as ? Because I see the former (and its disjunctive version) too often for it to be an accident.Admin
Because booleans are too damn hard? XD I get those a lot too... And another common ugly boolean construction I see is:
if(boolean == true) return true; else if(boolean == false) return false;
... So much fail.
Admin
There's something missing:
Admin
It depends on whether or not booleanExpression* variables are boolean expressions. In perl, let's say $val1 is the number of files found in directory1, and $val2 is the number of files found in directory2
We want to execute this code if both directories are empty,
or if both directories have files, but not if only one
directory has files.
if ( ($val1 && $val2) || (!$val1 && ! $val2) ) { ... }
In this case, $val1 might be 3, and $val2 might be 5. They're both boolean true, but they're not numerically equal.
Admin
I just took the submitter at face value and assumed one of the many changes in Java syntax had tried to make more convenient parameter passing or something.
Admin
Admin
As Jesus said after healing the insane man, go forth and SIM no more.
Admin
I guess you can say that ActionScript is Java, in the same sense that JavaScript is. (ActionScript is based on ECMAScript, which JavaScript is an implementation of.)
Now then again ActionScript isn't exactly server-side, unless there's a big WTF I don't know about. (To the best of my knowledge, it's only implemented in Flash and Air.)
(Yeah, JavaScript is to Java as Car is to Whatever I've heard it a million times.)
Admin
Unfortunately, there are server-side Flash technologies. Ugh, Flex.
Admin
if(boolean == true) return true; else if(boolean == false) return false;
is prefectly reasonable to do in some languages. I am thing object basic dialects for example. Its actually one of the faster and more clear ways to normalize return codes, in cases where boolean is not actually of type bool but will evaluate to true or false in the expected way. But yes in C,C++,Java its WTF.
Admin
Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.
Admin
Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible. Indeed, had some tyrannical god contrived to enslave our minds to time, to make it all but impossible for us to escape subjection to sodden routines and unpleasant surprises, he could hardly have done better than handing down our present system. It is like a set of trapezoidal building blocks, with no vertical or horizontal surfaces, like a language in which the simplest thought demands ornate constructions, useless particles and lengthy circumlocutions. Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time. ...
It is as though architects had to measure length in feet, width in meters and height in ells; as though basic instruction manuals demanded a knowledge of five different languages. It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion. ...
— Robert Grudin, Time and the Art of Living.
(Quoted in the GNU Coreutils info pages: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html )
Admin
Admin
Admin
FTFY
Admin
If you're a programmer, you need two patent lawyers perched on your shoulder. One to look for existing patents on each line you write, and the other to patent anything the first one doesn't delete.
(This comment patent pending. Go write your own.)
Admin
Authors of dictionaries/thesauruses "poison" their work with fictitious words so that copies are easily spotted. This could be an equivalent behavior among coders :)
Admin
If you're programming, you need the supervision of two patent lawyers. One to check if your written code is patented, and the other to patent anything remaining from the first one.
(Comment made in PRC)
Admin
More boolean weirdness... seen that once:
boolean foo=Boolean.TRUE.booleanValue();
Admin
Admin
I would really like to start a competition on here to see who can make the LEAST efficient re-implementation of boolean logic. I'm sure we could get some intriguing entries.
Admin
Admin
One thing that is still missing from most implementations: catering for incomplete date times, which is necessary in real world systems.
Often you have a date that is YM only (no D), or simply a Y (no MD). But how best to handle it when the programming language or database cannot (as incomplete dates must seamlessly query, calculate and sort correctly against complete dates)?
Anything that is real world historical data will more often than not have this problem (date a photo was taken, date of birth are obvious examples). You can cludge it, but the cludge will always leave a gotcha in the data model.
Admin
In which case it should be if (this == true) { return true; } else if (this === true) { return true; } else if (! this == true) { return false; } else { return false; }