|
I had a similiar situation occur, albeit in Fortran; a variable was declared as a byte, but received as a long...
Took me a while to find out what was overwriting my data in the calling routine. The overwritten data was fixed values that shouldn't change!
Tim
|
|
|
|
|
I would have done it in binary like so:
1101010101001101110010100111010101010011011100101001
1010101010011011100101001110101010100110111001010010
0101010100110111001010011101010101001101110010100110
1101010101001101110010100111010101010011011100100101
1101010101001101110010100111010101010011011100101001
That way there's less confusion
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Someone just gave a database example on the forum using select * and I needed to drop in here and do a brief rant. I realize it was just an example and was unrelated to what they were showing, but still... I just got through fixing an application where this caused problems. I needed to make a small change to the application which required me to to add a few database columns. I added the columns in between related columns in the table. This of coarse broke everything because in addition to select * they also used datareader.getstring(0) ect. for the 60+ fields returned from the table. My additions put the columns in a new order when retrieved with select *.
Of course this wasn't the only problem... the whole thing was a nightmare. MS access backend, which of course means tons of bad inline sql (not paramitized). One big God class that handled everything and no database layer. Every small change I made broke 5 unrelated things. I ended up refactoring the whole thing. I pulled out related functionality into static helper classes, bad coding practice I know, but there wasn't time for proper class design. But I did implement some interfaces and decoupled significant sections of the code so that I could make changes without breaking everything.
Any way that's my coding horror rant... thanks I feel better.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
Ohhhhh, so it's your fault.
|
|
|
|
|
PIEBALDconsult wrote: Ohhhhh, so it's your fault.
Almost always is... still haven't quite figured out how, but I've come to accept it.
|
|
|
|
|
I know this routine… decipher, decouple, rewrite (portions), and etcetera. Then may be you can make a minor change without breaking something else.
Remember this mantra: “Life is wonderful”, just keep repeating through your gritted teeth until your jaw unclenches and you can concentrate once more.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
So, yesterday I received a bug "<blablabla> Explain SQL sometimes (!) does not work on Oracle."
Twist, test, try, WTF of course.
The mistery: Format of a string class (almost any).
So here's how (with comments, bells, and COM follies):
String strDest;
String strUser;
strDest.Format(_T("-u%s"), strUser);
Unfortunately, Format call replaces "%s" with "(null)" when a null argument is passed as string.
So the poor receiver attempted to decode the "-u(null)" into an user name, and he gets "(null)".
Then the string horror (of course yet again not validated and unpacked without any defense) was passed to yet another string statement, so it ended up in
"ALTER SESSION SET CURRENT_SCHEMA = (null)"
Obviously a valid string, but probably the customer does not have an user called "(null)".
I hope.
Nuclear launch detected //
|
|
|
|
|
That's why I like to verify all input before passing it on. A couple "if" constructs looking for NULLs and such isn't a bad thing to throw in from time to time.
if (strUser !="") {
strDest.Format(_T("-u%s"), strUser);
} else {
// Add code to complain here
}
Checking for "stupid user tricks" is half the battle of coding! I tend to be very paranoid about anything "editable" by users, and check the bejezzus out of it before passing it along.
|
|
|
|
|
I like checking all input also
these thumb users always want to hurd me...
Greetings from Germany
|
|
|
|
|
Your check would still not catch the NULL value. A much better way to validate all strings would be:
if (String.IsNullOrEmpty(strUser)){
throw new ArgumentNullException(strUser);
}
else
{
strDest.Format(...
}
Hope this helps.
.leON.
|
|
|
|
|
Yep - it's a better check, assuming one is working in C# or with .NET.
Personally, I tend to do most of my development in C or C++ without ever touching any .NET stuff, and tend to fall into that pattern instead. It's the nature of my apps being low-level stuff for the most part that drives this, plus I like working with pointers!
|
|
|
|
|
String in my hands, pleases we-mean :
String MyHands = new String("Please who-men");
Kochise
PS : Find the "bugs" in my string or my hands...
In Code we trust !
|
|
|
|
|
First time I saw this post I quickly searched Wikipedia what is a "WTF"... (English is a foreign language anyway).
Greetings - Gajatko
|
|
|
|
|
Being young and foolish, I tried to make a game to keep my fingers busy.
Me knowing nothing, I used a workable idea, ruined it with no campaign-ish structure and mistakes like that. The real problem was the graphics.
Nothing fancy, the graphics consisted of (no fewer than) 700 Imageboxes on the form, layered for textures, objects, people, etc. Also, rather than hide them, they were filled with a blank transparent GIF if it was to display nothing. All but the textures were transparent GIFs, and all the images were loaded from the hard drive every time.
Also, rather than update a few boxes, I had the whole thing re-calculated and re-drawn when the unit moved. I had added a counter Typical values to draw the screen (23x17 grid or so and each had 4 boxes) would be: 0.23 seconds. Per draw. And because the loop was so slow, it would take the best part of 5 seconds to move painfully and flickerously across the screen.
Oh, and I nearly tried to write my own DirectX-style code. In VB6. I'd need a bloomin Double to store the framerate (for the minute value).
Thank God I'm not paid to program...
Yet another spam post on yet another forum!
I am the lazy one, who sleeps as it suits him, codes what he wishes, and has many years to look forward to.
I love being a student.
|
|
|
|
|
Ouch. Are you the guy who wrote the copy folder algorithm for Vista?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Ninja-the-Nerd wrote: VB6
I think Chris could as well redirect all Visual Basic posts to the coding horror forum
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
And all VB articles to Purgatory, pending portation to C#?
It's not that bad. It's simple enough for people like me to use it, and there's so many inefficient C based programs it's becoming hard to tell the difference :-P.
I'll have another one soon, I'm porting and completing the VB6 version to VB .NET which should be a right laugh. At least I intend to use GDI for it this time, and use some optimised methods of dropping images.
If any of my future employers see this...[crosses fingers]
"Yes boss, I learned from my mistake"
"No boss, I haven't learned C++"
Yet another spam post on yet another forum!
I am the lazy one, who sleeps as it suits him, codes what he wishes, and has many years to look forward to.
I love being a student.
|
|
|
|
|
C# ones, often, aren't that better.
-- modified at 10:18 Thursday 24th May, 2007
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Gruesome.
Guess that's why we have the ability to write Active-X controls in VC?
|
|
|
|
|
VB6 for a game, isnt it to slow. VB6 is outdated I think you should upgrade yourself at least to VB.net or a real programming language.
"Carpe diem"
Greetings from Germany
|
|
|
|
|
That is just the learning process. If we did not make mistakes then we would not learn anything or for that matter – get anything done.
Programmers point of view:
1) Think.
2) Write something based on ideas.
3) Note possible problems – Think.
4) Rewrite – based on what you learned.
5) Think – are you satisfied (learned enough).
6) Make notes – consider improvements.
Management point of view:
1) Think.
2) Write something based on ideas.
3) Does it work?
4) If yes! You are finished – because it works.
5) Stop thinking – for self preservation of sanity.
6) Recommendation – make personal notes – and go on to next subject.
Note: If you do not inform management until step 4 in “Programmers point of view" is complete then you will have a better (more reliable) product. But if you must show progress based on the “Management point of view” then expect to be cut off at the knees, and learn to live with it.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Today I was looking through the code of
student who is working on some project for our company.
He's trying to make a new user admininstration application.
In his application he is loading the users from the database in a treeview.
Ok, so far so good. Nothing is wrong.
Now I've tried to load the user informations and wondered why the data didn't
match to the selected user.
The following code snippet is the reason.
<br />
string query = "ID = " + this.userTree.SelectedNode.Index.ToString();<br />
DataRow[] foundi = tableAdapterUsers.Select(query);<br />
He's making a Select on the Database expecting that
the TreeViewID is equal the Database ID.
I spend the nearly the whole morning to find this.
I'm wishing everbody a nice weekend
greetings
pdluke
|
|
|
|
|
Youch. When I build TreeNode s from DataRow s I store the original DataRow in the Tag field of the TreeNode for future reference.
|
|
|
|
|
pdluke wrote: string query = "ID = " + this.userTree.SelectedNode.Index.ToString();
It is interesting to see people make sql queries this way and expose themselves to SQL injections. Parameterized queries are not only safer, but also easier, IMHO.
|
|
|
|
|
Nemanja Trifunovic wrote: Parameterized queries are not only safer, but also easier
I'm not suggesting I agree with the method shown in by the OP, but it is much easier to keep a source history if the queries are in the code rather than stored procedures and also less likely to miss an update when releasing a new version of code.
That said, i use parameterized queries
Pualee
|
|
|
|