Has anyone seen this?
-
i just got an invite on myspace from the guy that "created" http://www.bytemycode.com/
i'm sure there's a pile of wtf's in here, not to mention the comments his "friends" have left on his profile:
all i have to say is:
while (($entry = $d->read()) != false) {
-
Aside from that it could be shortened to "while ( $entry = $d->read() )", I don't get it what's wrong with that snippet. Seems like the standard way of pulling things out of a db.
-
[quote user="lindee"]
while (($entry = $d->read()) != false) {
[/quote]
I don't really get it... If it's PHP, then it's good. WTF is that he didn't use !==. And you should check it that way just in case. Some constructs in php are == false, but not === false. For example empty array.
If you can get some kind of that value from database, then you should test (($entry=$d->read())!==false). Or you'll end up getting something, but thinking it was end of records marker.
-
[quote user="viraptor"]I don't really get it... If it's PHP, then it's good. WTF is that he didn't use !==. And you should check it that way just in case. Some constructs in php are == false, but not === false. For example empty array.[/quote]
Ah yes... this is one of the main reasons I'm never touching PHP. In perl, say, you'd do while(defined($x = getSomethingThatMayBeFalse)), which, while doing basically the same thing, doesn't look completely farking redundant. It also appears to be a rare case of perl using less punctuation than another language. *g*
to take a different tack, Ruby, Lua and various others just make the undefined value be the only one interpreted as false in a conditional:
while x = getSomething_ThatMayBeZero_ButNotFalse() do ... end
but
while (x = getSomething_ThatMayBeFalse_ButNotZero()) != 0 do ... end
while (x = getSomething_ThatMayNotBeZeroOrFalse()) and x != 0 do ... endPlease note that I can't remember if this is actually valid Ruby. You get the point anyway. I actually prefer this to perl's method, but then again, it'll be all change for perl6 anyway (
return($variable but True)
anyone?).
-
Not exactly. defined() would be closer to isset() probably. That way or another === and == are ok when you want to compare "42" to 42 as variable and as value... Maybe weird, but it's just whether you're used to the style or not. And array()==false is sometimes really useful - for example:
if(whatever) $error[]="Some error";
if(something) $error[]="Some other error";
if($error) there were count($error) errors;Same for ''==false and 0==false. On the other hand php has "real" boolean, so 0!==false.
Maybe while(read(&row)) would be better - no WTFs here if it only returns boolean (or FileNotFound) and row as ref-arg.
-
The whole site just looks like another unedited code dump for excitable 14-year-olds.
-
thank you for finally seeing my point...
-
Here's my favorite:
void foreach(int a[], int func(int n))
{
for(int i = (sizeof(a) / 4) - 1; i > -1; --i)
a[i] = func(a[i]);
}
-
void foreach(int a[], int func(int n))
{
for(int i = (sizeof(a) / 4) - 1; i > -1; --i)
a[i] = func(a[i]);
}Wow that is amazing. to bad sizeof(a) is going to return 4 because when an array is passed in as a parameter it is just a pointer. my favorit was something like this:
//changes a password from JPasswordField to a string
passwordToString(char[] password) {
String aStr = "";
for (int i = 0; i < password.length; i++) {
aStr += password[i];
}
return aStr;
}
-
That dude needs to learn a little something about photo editing. It's one thing to be ugly in real life, but it's ridiculous to be that ugly on the internet.
-
[quote user="HeroreV"]That dude needs to learn a little something about photo editing. It's one thing to be ugly in real life, but it's ridiculous to be that ugly on the internet.
[/quote]A year or two ago to someone long forgotten...
Me: Hahaha, nice use of photoshop on your picture there.
Him: Photoshop...?
Me: Oh....
-
[quote user="sparked"]
Here's my favorite:
void foreach(int a[], int func(int n))
{
for(int i = (sizeof(a) / 4) - 1; i > -1; --i)
a[i] = func(a[i]);
}[/quote]
This is my favorite too for sheer utter pointlessness, and as a solution supposed to make coding faster that actually makes it slower. I especially like the reasoning given for it:
"I was coding a project that used arrays when the lack of a standard foreach in C/C++ got to me. So, I coded this little function to help me. It applies a function that returns int to each element of the array."
The invalid C++ syntax is probably because it is written in Managed C++. That's must be how sizeof can return the size of the array just from the pointer. The use of a backward iteration in the foreach function only obfuscates when forward iteration would have been fine. Plus why not use a list container instead of an array if you are getting annoyed using (sizeof(a) / 4) in every for loop? Much better than a solution that only works for ints and requires writing callback functions.
-
http://www.bytemycode.com/snippets/snippet/371/
they need a snippet for this ???