- 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
This does offer a rather elegent way to ensure data passed is actually a boolean:
make_sure_is_boolean($val) {
return invert_boolean(invert_boolean($val));
}
at least one type of variable won't be the source of your SQL injection!
Admin
<font size="6">M</font>y other half? Is that my mom? Or do you mean "the other half" of our basement where the furnace is?
Admin
In Perl, a scalar variable (int/float/string) is preceeded with $, an array variable is preceeded by @, and a hash table variable is preceeded by %. So it's possible to have a $apple, @apple, and %apple, all of which are separate variables. And calls to functions are preceeded (sometimes) by & (I didn't get advanced enough in Perl to understand why functions I write need the & but library functions don't need it).
The Perl creator (Larry something I think) said he picked $ and @ because they looked like S(calar) and A(rray). But I think he picked the word scalar to start with S so he could continue the unix shell convention...
In PHP I don't think it carries much significance, except maybe to distinguish variables from functions in case they have the same name (maybe?).
Admin
Memo: What business are we in????? We are in the Damnation Business!!!!!
Admin
creating that function was really lame!!!!!!11!!1
Admin
You damn kids ....
The &func is left over from previous verions of Perl.
Wall! Larry Wall. You should know that name. Scalar is a fairly common word to describe a scalar value :)
PHP is a hybrid of the unix shell, perl, and c, with some of the OO parts borrowed from java. PHP variables are always prefixed with '$'.
Admin
Is it just me or are the earlier books way funnier than the more recent ones? Was re-reading the colour of magic and just couldn't stop laughing.
Admin
There are good and not so good books all over the series. I for one thought that the best books were Eric, Soul Music and Night Watch, though I've not read Going Postal
Admin
The $ in PHP will get interesting when you look up the "variable variables" section in the documentation. See some examples:
abc - means the constant defined by define('abc', something) or (of nothing defined by that name) the string 'abc'
$abc - the variable named abc
$$abc - the variable, whose name is in the variable named abc - like $abc = 'foo'; $$abc refers to $foo :)
$$$abc - for really weirdos ;)
And this one will only get tricky when you find that you can use it for function call also: $$abc() is actually working (if memory serves :), so $abc = 'foo'; $foo = 'myfunc'; $$abc(); // will invoke myfunc()
This thing is weird as it is, using reference _by name_. But actually in this context $ has a meaning: something like "lookup-by-name".
Admin
All booleans are ( by nature ) just itchin' to be inverted. This generous function mearly allows them a few more moments of glory in the process. In the fast-paced world we live in, the developer simply reminds us to slow down and let the variables live a little.
Admin
olddog, what does your sig means?
Admin
mean, I mean
Admin
Just a quantum pun about the number line. Do you believe in zero, or do you believe there's always half of a half...of a half?
Admin
I don't understand why the "bone" is in there, but thanks for the reply (the rest makes sense now)!
Admin
And, being someone that programs PHP, there are only 2 uses I've ever found for a variable variable that isn't a WTF:
1. Emailable forms where you want the array key of the post (form item name) to be variable so that it gets inserted into an email in the right spot without always doing a lookup on the array (yeah, this seems redundant, I know...but inserting using an array with keys into a string takes nice annoying curly brackets). Obviously you have to make sure that you use constants, or all variables are defined after the array -> variable conversion is done, otherwise you get emails going to the wrong place.
2. Creating proper validation functions based on a database describe result for dynamic forms designed to fill out an unknown database table (using the ${$fields[$i][validation]}() syntax, or some such). Obviouslly you will want to set these yourself based on the field type from the describe command to make sure nothing wierd gets executed.
Admin
The "bone" is a metaphor. The question is an conversation starter in a room of people smarter than me.
Admin
This guy deserves to be quoted for emphasis.
You're all harping on this as a huge WTF, but <i>the existance of an invert_bool function</i> isn't at ALL a WTF, at least in a language that supports function pointers. (It looks like PHP might not; I don't know it well enough to say for sure, but I don't get any useful hits from a simple Google search.)
The implementation of invert_bool IS a WTF, and that makes me think that the above analysis isn't really applicable in this case, but primative functions such as that are quite helpful for some styles of programming.
Admin
Ahh got to love PHP programmers, my favourite if statement was:
Admin
Then, invert_bool could be:
function invert_bool($val) {
return !return_bool($val);
}
Admin
Yep, you got me. The PET was the first computer I ever programmed on (or used, for that matter). IIRC, the % sign indicated integers. I think there were some other characters that indicated data typing as well. It wasn't just PETs, lots of old versions of BASIC made use of that.
Admin
Ahh. the fun difference between boolean and null is that, when testing, null can be either anything or nothing, while boolean can only be anything or not ( the thing is implied ).
Admin
I was having a problem with Microsoft Word. It insisted on showing me the "Getting Started" task pane every time it started up. My desktop support guy pointed out a KB article on exactly this topic. The solution turned out to be using REGEDIT to, well, I'll let them explain it in their own words:
Yes, that's right, I had to delete a registry entry that was preventing me from making the stupid pane NOT show up. WTF!?
Admin
The WTF is 73 (and counting) responses to a piece of code that does exactly what it is meant to do.
I don't know what the language is.
I don't care.
The programmer is returning the reverse of whatever has been presented.
The code is understandable.
It does what it's meant do do. (oops, I said that before).
It's probably part of a very large system that is making megabucks for the people running the software, with very happy customers.
The bottom line, is, after all, the bottom line.
Admin
The $ in PHP can be a bit of a convenience, although i find the $this->_foo and self::$foo to be poorly-designed. The problem is that it was originally a very simple set of scripts that continued to grow. That said, it can still be a somewhat-decent language.
Anyhow... Given its runtime-interpreted nature, the $ helps signify that what you are referring to is a variable. Go back to that it's runtime-interpreted and you can get things like this:
$obj = new $objClass();
No, it's not ideal, and few will recommend things like that, but it is available, and some people like it. I just hope i never have to maintain their scripts.
Admin
ARGH.<p>
The $ is extremely important in perl5, designating that you are asking for a scalar value (as opposed to an array slice, @, or a hash slice, %.) If you come across perl code that uses 'barewords', as non-sigiled (funny-character prefixed) variables are known, it is more than likely not written with
use strict' or
use warnings' turned on, which lets you get away with such chicanery.Admin
I have a novel interpretation for today's WTF: given that this guy named his function "invert_bool" instead of "negate" or similar, I think he was ignorant of boolean logic. Maybe he thought he has made a great invention. Sounds crazy, but we've seen that kind of ignorance before.
Admin
I aggree, the earlier books were better.
Admin
And could have been replaced by a simple "NOT" operator. May not be the worst WTF ever, but unless someone is paid by lines of code that mentioned piece of code could have been avoided. Only inexperienced or sloppy developers write more _code_ than necessary.
l.
Admin
No.. The WTF today is what the f... is this guy doing coding if he doesn't know about the !-operator? That is really basic knowledge.
Also the naming of the function hints at a lack of understanding of boolean algebra.
Admin
Not only is there an Exclamation Point in that! It is so tall that it has to bend over to fit under the top line...
Admin
Can't speak for PHP but Perl follows the shell convention - foobar could be a literal string, subroutine, object etc depending on context. $foobar is a variable and 'foobar' is always a literal string.
Admin
Erm... well that's what I get for replying to a post on the first page without realising there are 2 pages...
Admin
Well... sure Perl got the $ from UNIX shell (I guess especially from the awk programming language), and PHP inherited it from Perl, but not as some kind of redundant piece, but as a feature.
Everyone seems to forget, that the main point of having variables prefixed with $ is that you can place them inside strings:
echo "My name is $first_name $last_name.";
Admin
Oh my god, tell me this is !true... [:D]
Admin
All you say is !false ( [:D] ) - and I abuse this happily in a bb-code parser I wrote in PHP some years back... [:P] The joy of function-pointers, pointer-pointers and pointer-pointer-pointers in a scripting language. You gotta love it [6]
Admin
PHP: We are talking about a language that follows the C convention of using == for comparison and = for assignment, because it saves a tiny bit of work, assuming that the later is more often used. This philosophy doesn't match at all with the $var style. Things like that make PHP in my eyes one of the ugliest languages ever defin^h^h^h^h^h^h grown.
Admin
Ah hahahahahah
Thats great - I may start implementing things like this myself...
Admin
Admin
Very good!!![;)]
Admin
It there ANY author that isn't true for? Publishers make potential authors sweat out those first books until they can't get better. Once the author has about 6 books published, people know they can write good stuff, and buy anything with their name on it. So publishers start publishing rough drafts - after all rough drafts are easier, more fun, and take 1/3rd the time as a polished book. The latter is most important because as we all know time is money.
I have several wonderful books that I've replaced more than once because I keep wearing my copy out (many of them went paperback when I was a kid so there is no chance I can buy the more durable hardcover anymore). After reading some great book I go to the bookstore and see another book by that author and buy it, thus perpetuating the scam on readers.
I've tried buying first books by unknown authors, but many of them are not worth reading. Anyone with an idea of what readers can do about it?
Admin
You've spelt 'Brillant' wrong mate.
Cheers,
Dan
Admin
The sigil ($) isn't meaningless in perl by any means. It denotes a scalar variable, as opposed to a list (@) or a hash (%). When using a hash element or list slice, you'd also use the $ sigil, because the target is a scalar ( %myHash is an entire hash, but $myHash{$element} is a single entry in the hash, which is always a scalar, hence $).
The sigils ($, @, and %) are how perl handles typecasting and type definition. Once you get used to it, it makes it lots easier to read. No, really. I'm serious.
Admin
Not true. The minimum possible code is often unreadable. Better to have a couple of extra lines to improve readability. Experienced coders, as opposed to prima donnas, know this.
Admin
So did Paula. That's the point of the joke. (See previous WTF).
Admin
Someone suggested that the decline of Piers Anthony occurred after his editor (Judy Lynn Del Rey?) died and stopped sending crap back for rewrite. As for avoiding the scam, I've had a few ideas...
1. After reading a good series (Belgariad, Adept, Amber), avoid a follow up series like the plague. Exception: the Twins was a great follow up to the Dragons
2. After reading a good trilogy (HitchHiker's, Foundation, Robots) don't read the fourth book in the "trilogy". Exception: the summer dragons were a great add on to autumn, winter, and spring.
3. Avoid Quadrillogies.
4. Avoid Prequels (Foundation, the Phantom Menace, the SoulForge). Exception: the Magician's Nephew, Belgarath the Sorcerer
5. Avoid Midquels (Polgara the Sorceress)
6. Avoid Weis without Hickman (the SoulForge)
To give Discworld credit, it went impressively far before diving. I think he even went beyond three good ones for the Rincewind, Witches, Death, City Watch streams. Haven't read any Tiffany Aching.
Admin
Yeah but how many of you don't get flustered?
Admin
You know if you had mentioned the lack of type checking, then he probably would end up with:
Admin
The other day, I see a friend of mine and he says 'I haven't heard from you in a while.' I said, 'I can't call everybody I want. See, I bought an imperfect telephone, and it has no five.' He says, 'Oh my god -- how long have you had it?' I said, 'I don't know -- my calendar has no sevens.'
Admin
Uh, yeah, right, funny how Ruby manages string interpolation without prefixing the fucking variable names eh.
What PHP has is not a feature, it's a damn retarded stupidity, because while it does have a meaning it perl it has none in PHP
Admin
Now WTF would that function return if the parameter wasn't boolean? Nothing? File Not Found? I'm thankful i'm in a land where such nonsense is a lot harder to pull off (C# & Java).