View Full Version : Your stupidest coding goofs
techno_race
07-04-2008, 08:57 PM
One time, I had to add 12 hours to the current hour and display it on screen in 12-hour time. My first instinct was, believe it or not, to do this:
var hour = new Date().getHours();
var hours;
switch(hour) {
case 0:
hours = 12;
break;
case 1:
hours = 13;
break;
case 2:
hours = 14;
break;
case 3:
hours = 15;
break;
case 4:
hours = 16;
break;
case 5:
hours = 17;
break;
case 6:
hours = 18;
break;
case 7:
hours = 19;
break;
case 8:
hours = 20;
break;
case 9:
hours = 21;
break;
case 10:
hours = 22;
break;
case 11:
hours = 23;
break;
case 12:
hours = 0;
break;
case 13:
hours = 1;
break;
case 14:
hours = 2;
break;
case 15:
hours = 3;
break;
case 16:
hours = 4;
break;
case 17:
hours = 5;
break;
case 18:
hours = 6;
break;
case 19:
hours = 7;
break;
case 20:
hours = 8;
break;
case 21:
hours = 9;
break;
case 22:
hours = 10;
break;
case 23:
hours = 11;
break;
default:
hours = "NaN";
}...
Ack.
I am now using this:
var minutes = new Date().getMinutes();
var hour = new Date().getHours();
var hours = hour + 12;
if (hours > 23) {
hours = hours - 12;
}...
techno_race
07-04-2008, 09:05 PM
Oh, dang it.
hours = hour... :p
I unlinked() an array once. :o
jscheuer1
07-05-2008, 12:24 AM
I have a terrible habit, that I think I'm finally starting to break, of forgetting to include the '[i]'s (highlighted below) or whatever the var is (usually it's 'i') when looping through something like:
for(var b = some_collection_or_array, i = 0; i < b.length; ++i)
if (b[i].something == 'some_string')
b[i].something_else = yet_another_thing;
I think the reason is that in my mind it should just be understood what I'm referring to, though computers rarely work that way.
I always catch the error(s) sooner (usually) or later, but if I had a nickel for every cumulative hour wasted on this, I'd probably be in a higher tax bracket. :cool:
Are you kidding? In that the i is my favorite part!
rangana
07-05-2008, 01:34 AM
I'm always get pissed by this:
<script type="text/javascript">
window.onload=function()
{document.forms[0].onsubmit=function()
{var str=document.getElementById('email');
if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(str.value))){alert ("Please enter a valid email address.");
return false;}
}
return;
}
</script>
<form action="http://www.google.com">
<label>Email:</label><input type="text" id="email">
<input type="button" value="Submit">
</form>
Of course, the only mistake was the highlighted, which took me almost an hour to debug the script.
jscheuer1
07-05-2008, 02:01 AM
Are you kidding? In that the i is my favorite part!
Mine too, but that doesn't prevent me from too often forgetting it in the evaluation phase of the loop. Though, as I say, I'm getting better at it.
djr33
07-05-2008, 12:53 PM
I'd say I tend to type function(something(), and always forget that close parenthesis. Obviously that causes many problems. :)
allahverdi
07-05-2008, 01:43 PM
Writing js after php:
(variables and almost ALWAYS forgot document.)
$myvalue = getElementById("thisis").value;
Writing PHP after js:
<?php
var $myvariable = $_POST['value'];
?>
benslayton
07-25-2008, 07:53 AM
Last year I was redesigning our schools website. I had to use asp for the server side language... After that I would go to a C# class later on in the day. Then go home and program using php...
YOU CAN ONLY IMAGINE THE JUNK I WENT THROUGH...
I often freeze the browser with this one (although since using FF freezing doesnt happen)
while($n < 100){
echo $n."<br />";
}
I often seem to forget to increment n++ :D
TheJoshMan
07-26-2008, 09:52 PM
I once coded an ENTIRE site, (all 18 pages of it) using the following code:
<image src="http://www.thissite.com/images/dumb.gif" />
Anywhere there was an image on the site which wasn't used as a background image, I called it with <image>. The funniest part about it is, it took me like 3 days to figure out what in the world I did wrong!
I had several of my friends come over to help me out, (dumb idea) and when they found my mistake... Let's just say I still haven't lived it down.
jscheuer1
07-26-2008, 11:14 PM
<image src="http://www.thissite.com/images/dumb.gif" />
That actually works in at least some browsers (just tested in FF 3 and IE 7, worked in both).
But it isn't valid code.
var minutes = new Date().getMinutes();
var hour = new Date().getHours();
var hours = hour + 12;
if (hours > 23) {
hours = hours - 12;
}
var d = new Date(),
minutes = d.getMinutes(),
hours = d.getHours() % 12 || 12;
I keep on getting mixed up when I'm linking an external file to the document. I do this:
<link rel="stylesheet" type="text/css" src="file.css" />
<script type="text/javascript" href="file.js"></script>
techno_race
07-27-2008, 05:07 PM
I just coded a website in PHP and tried to run it client-side. It took me 10 minutes to figure out why my browser was printing my PHP.
magicyte
12-26-2008, 03:37 AM
Perhaps the most common thing I do in programming is making everything harder than it is. Once I programmed a whole dec2hex function- while it could have been 5 lines or fewer, I just had to make it 90 lines... (http://www.dynamicdrive.com/forums/showthread.php?t=34021) :o.
Another thing that I do in HTML is I type out the whole tag (kind of like Josh):
<script type="text/javascript" source="myJavaScript.js"></script>
<image source="pics/myImage.png" width="20" height="20"></image>
Yet another is typing out really long functions:
document.getElemenById("we").value = "we";
// where is the t??
and then there's this:
document.getElementByTagName("input")[0];
// whoops - I forgot the 's'
I've been doing this lately:
Document.getElementById("myEl").style.display = "block";
// I capitalized the d in document
Sometimes I'm in such a rush to write some code that I forget to write a function I wanted to call (that also happens when I'm coding late at night). In C++, I usually forget to include the libraries that I need... :o.
Yeah. There's a bunch of stuff I forget to do and it happens every time I compile or save. It happens to all of us, I'm sure...
thesource
01-07-2009, 03:48 AM
I honestly don't remember any ;)
Medyman
01-07-2009, 05:46 PM
I honestly don't remember any ;)
Same here. I'm too perfect to make mistakes. :p
Just kidding, of course.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.