WTF was I doing?
-
After graduating college with a history major, and having never programmed before, my job required that someone teach themselves how to program, and I was chosen to be that person. Many WTF's were the result of the first few months, including this wonderful bit of code...
[Quote]
public void CheckErrors()
{
errorProvider1.Clear();
string org = textBox3.Text.Trim();
string email = textBox4.Text.Trim();
string first = textBox5.Text.Trim();
string last = textBox6.Text.Trim();
bool o = false;
bool e = false;
bool f = false;
bool l = false;
if (org != null && org != string.Empty) o = true;
if (email != null && email != string.Empty) e = true;
if (first != null && first != string.Empty) f = true;
if (last != null && last != string.Empty) l = true;
if (o == true && e == true && f == true && l == true)
{
bool ex = false;
ex = nData.Exists("Select * From aztec_Customers Where Organization='" + org + "'");
if (ex == true) errorProvider1.SetError(textBox3, "That Organization already exists. Please provide a unique Organization.");
else
{
panel2.Visible = false;
panel3.Visible = true;
SaveCustomer();
}
}
else
{
if (o == false) errorProvider1.SetError(textBox3, "Please provide an Organization.");
if (e == false) errorProvider1.SetError(textBox4, "Please provide an Email.");
if (f == false) errorProvider1.SetError(textBox5, "Please provide a First Name.");
if (l == false) errorProvider1.SetError(textBox6, "Please provide a Last Name.");
}
}
[/Quote]
-
Don't ride yourself - everyone's beginning code looks like that. Besides, as beginner (or even professional code, if you look at some of the stuff posted) code goes, it's not soooo bad.
-
yeah, if you cut out half the if statements, and move the bool assignments around a bit, it might actually look good. and it seems to function just fine.
-
Well, apart from the obvious injection vulnerability.
-
injection vulnerability
complete lack of comments
use of single letters for variables
about half of the code is unnecessary
among other things...
I went back to fix an issue and I couldnt figure out what I had done for a good while...
-
The worst thing I see here (other than the above mentioned) is that you cram so much on one line.
if ( )
<then...>
Cramming as much code on one line as possible doesn't make it run faster and doesn't make it more readable (even if it makes it all fit on one screen).
I will say that for a beginner programmer, it is good.
-
@frosty said:
The worst thing I see here (other than the above mentioned) is that you cram so much on one line.
if ( )
<then...>
Cramming as much code on one line as possible doesn't make it run faster and doesn't make it more readable (even if it makes it all fit on one screen).
I will say that for a beginner programmer, it is good.In some places you also get paid less for it.
-
@AustinW said:
After graduating college with a history major, and having never programmed before, my job required that someone teach themselves how to program, and I was chosen to be that person. Many WTF's were the result of the first few months, including this wonderful bit of code...
Here's my version:
After graduating college with a CS major, and having programmed a lot before, my job required that everyone teach themselves how to program in {languages}. Many, many, many thousands upon thousands of lines of WTF's were the result of the first few months...
-
I've spent 16 years writing code in C, C++, and various other languages and every now and again when I look back on something I've written in the past, be it a week or a decade ago, I scratch my head and wonder WTF?!?!?! ... Sometimes we just write bad code because of deadlines, or lack of experience on a given topic, or because of the keg hiding under the desk ... Don't worry, throughout the years to come you will have your many WTF moments on your own code.