|
CeciPipePasPipe posted:Oh ok, wouldn't it be easier to just do "int breakme=1/0;" or something then?
|
# ? Jul 9, 2008 14:16 |
|
|
# ? May 15, 2024 04:06 |
|
why couldn't one do thiscode:
I don't remember the code for error on exit, but i think 1 is it.
|
# ? Jul 9, 2008 14:45 |
|
Entheogen posted:why couldn't one do this
|
# ? Jul 9, 2008 15:05 |
|
TSDK posted:Because we're talking about coding horrors, not trying to create more of them? code:
|
# ? Jul 9, 2008 15:12 |
|
Rottbott posted:You certainly can in Visual C and Visual C#, I do it every day. And on braces. I too am confused by this confusion.
|
# ? Jul 9, 2008 15:21 |
|
We found this in a large J2EE app today. (after it came back from vietnam). During some PDF generation: code:
|
# ? Jul 9, 2008 18:39 |
|
what is so horrible on exiting when exception occurs? For some exceptions it makes sense, and you can print out what the message was before you exit anyways.
|
# ? Jul 9, 2008 18:47 |
|
Entheogen posted:what is so horrible on exiting when exception occurs? For some exceptions it makes sense, and you can print out what the message was before you exit anyways.
|
# ? Jul 9, 2008 18:53 |
|
Entheogen posted:what is so horrible on exiting when exception occurs? For some exceptions it makes sense, and you can print out what the message was before you exit anyways. It will shut down the entire web server/app server, which is probably not what you want to happen if a single PDF report gets screwed up.
|
# ? Jul 9, 2008 18:58 |
|
CeciPipePasPipe posted:It will shut down the entire web server/app server, which is probably not what you want to happen if a single PDF report gets screwed up. This is what happened. We only found the code after the app server mysteriously went AWOL
|
# ? Jul 9, 2008 19:00 |
|
CeciPipePasPipe posted:It will shut down the entire web server/app server, which is probably not what you want to happen if a single PDF report gets screwed up. I think he was talking about his own example, not the java one. It's astonishing how many people don't know exit() will take down the parent app, not just kill the current child process. You'd think with the number of people making this mistake they'd come across it firsthand at some point and realize.
|
# ? Jul 9, 2008 19:45 |
|
Why put it on the brace when you can put it on the catch statement itself? Click here for the full 915x888 image. (untested on earlier versions of VS. This is VS2008)
|
# ? Jul 10, 2008 03:07 |
|
What functionality does this 6500 line code project comprised of over one hundred files provide you? It gets you web page. A single web page with a data grid that lists rows from a table in a database, and lets you approve them. I really really don't know what happened here, other than a Java app programmer decided to learn Visual Studio, C#, ASP.NET, CSS, Model-View-Control design, Test Driven Development, and umm some sort of -on Rails based naming methodology, all at the same time. Best part is it didn't work when it was handed off to me. Faced with understanding and debugging the code, I opted to rewrite it.
|
# ? Jul 10, 2008 04:40 |
|
100 files, 6500 lines. It seems like the author subscribed to the OO philosphy from that blog posted earlier in the thread.
|
# ? Jul 10, 2008 09:27 |
|
JediGandalf posted:Why put it on the brace when you can put it on the catch statement itself?
|
# ? Jul 10, 2008 09:34 |
|
Heffer posted:ungodly project I love how you have titled it OhGod
|
# ? Jul 10, 2008 13:33 |
|
Well, it is best to be *really* sure that absolutely nothing goes wrong when deleting stuff from the database:code:
|
# ? Jul 10, 2008 14:37 |
|
I've been trying to improve my coding, and so I've started a little python project that attempts to parse a filename, then use the information I parsed to find applicable information on websites. I had a lot of the trappings of "professional" programs:
It's the last one I concentrate on in this example. ConfigParser will basically allow you to get a value as a string, given where to look for it. I decided regular old strings weren't enough and I coded a brilliant way to allow a user to specify regular expression flags in a config file. Observe: code:
I have since discovered python's builtin function: eval() that parses a string that contains python code, and then evaluates that python code. Special bonus, later on in that code: trying to turn a configuration option that is of the form: original_text=text_swap_in[,original_text=text_swap_in] into a dictionary. code:
|
# ? Jul 10, 2008 14:49 |
|
I do not want to mock the dude because he obviously did not know better and his compiler did not give sufficient warnings, but trying to free a bunch of dynamically allocated objects with delete foo, bar, baz; is pretty depressing.
|
# ? Jul 10, 2008 15:19 |
|
Good Christ, you took the time to define a bunch of enums and you use them all in switches internally, stop using "long" as the parameter type in all your interfaces! Why do you hate type checking so much?
|
# ? Jul 10, 2008 15:35 |
|
Sebastian Flyte posted:Well, it is best to be *really* sure that absolutely nothing goes wrong when deleting stuff from the database: What's wrong with this? The only weird thing I can see is that db.Open is called after creating the transaction, but that doesn't have anything to do with your comment so I assume that's just the way the API works.
|
# ? Jul 10, 2008 15:38 |
|
LurchDawg posted:yeah, so I was basically trying to parse a string that contained python code, and then evaluate that python code using my personal favorite textual hack "split()". Your way is better - you don't want people to be able to put 'os.system("rm -rf /")' in your config file and have it blindly executed. EDIT: I swear when I hit Quote there I had big plans of copying the quoted text and editting it into my last post to avoid triple-posting, but somehow I just forgot. Oh well. JoeNotCharles fucked around with this message at 15:44 on Jul 10, 2008 |
# ? Jul 10, 2008 15:41 |
|
JoeNotCharles posted:Your way is better - you don't want people to be able to put 'os.system("rm -rf /")' in your config file and have it blindly executed. Eh? As long as it's not running suid or something, there's nothing a user can put in his config file that he couldn't just type into the commandline. It's not a program's job to stop a user from doing something stupid when they go out of their way to do it.
|
# ? Jul 10, 2008 15:55 |
|
JoeNotCharles posted:What's wrong with this? The only weird thing I can see is that db.Open is called after creating the transaction, but that doesn't have anything to do with your comment so I assume that's just the way the API works.
|
# ? Jul 10, 2008 16:34 |
|
JoeNotCharles posted:What's wrong with this? The only weird thing I can see is that db.Open is called after creating the transaction, but that doesn't have anything to do with your comment so I assume that's just the way the API works. I imagine the catch all Exception instead of an SqlException? To be honest though I use catch-all exceptions due to lazyness. I don't really care *why* I can't delete from the DB.. just that it failed.
|
# ? Jul 10, 2008 16:52 |
|
Smackbilly posted:Eh? As long as it's not running suid or something, there's nothing a user can put in his config file that he couldn't just type into the commandline. It's not a program's job to stop a user from doing something stupid when they go out of their way to do it. What if somebody wants to install it with a web server frontend? Or some malicious person sends a complex config file saying, "Here, this'll do exactly what you're looking for!" when it actually has some bad commands embedded in it? Blindly executing anything handed to you is a terrible habit to get into. chocojosh posted:I imagine the catch all Exception instead of an SqlException? Well, exactly - it's rethrowing, so this is exactly what should be done. Otherwise if it can't delete for some reason you haven't considered (any class other than SqlException) your data gets inconsistent. I guess the fact that there's only one statement makes the transaction kind of pointless, but it's still good defensive programming - you wouldn't want somebody to come along and add a second statement (say, updating a log table after every delete) without locking. JoeNotCharles fucked around with this message at 17:16 on Jul 10, 2008 |
# ? Jul 10, 2008 17:11 |
|
Yeah, that's true. I don't know C# but what's the type of the exception being propagated upwards in that code? Because in Java, for instance, if you just blanket catch exceptions and then just do throw new Exception(), you're losing the info about what kind of exception it was, but if you do something like:code:
|
# ? Jul 10, 2008 17:20 |
|
edit: doubelpost
|
# ? Jul 10, 2008 17:21 |
|
Bonus posted:Yeah, that's true. I don't know C# but what's the type of the exception being propagated upwards in that code? I believe "throw" with no parameters means to re-throw the current exception.
|
# ? Jul 10, 2008 17:25 |
|
Bonus posted:
|
# ? Jul 10, 2008 17:30 |
|
Aha, I see, cool. Yeah, like I said, I don't really know C#, I just wanted to know if that piece of code kept the information about the exception.
|
# ? Jul 10, 2008 17:44 |
|
JoeNotCharles posted:What if somebody wants to install it with a web server frontend? Or some malicious person sends a complex config file saying, "Here, this'll do exactly what you're looking for!" when it actually has some bad commands embedded in it? Blindly executing anything handed to you is a terrible habit to get into. If you're allowing untrusted web users (or untrusted ANYONE) to make arbitrary changes to the configuration file for one of your apps, you're pretty hosed regardless. I could send someone a .emacs config file that wipes their hard drive (or at least their home directory), but that's not considered to be security problem with emacs.
|
# ? Jul 10, 2008 18:15 |
|
I also can't figure out why this Qt code keeps using "dialog->setModal(true); dialog->show();" and then connecting the Ok and Cancel buttons to slots in the main window, instead of just using "dialog->exec();" and checking the return code.
|
# ? Jul 10, 2008 18:16 |
|
I'm not a regular poster in this subforum, but I've been reading this thread for a while, and I thought that the current clusterfuck of a program I'm dealing with would amuse people. I'm not a professional programmer, I'm a graduate student in physics. However, for my project, I do a lot of coding, since I'm reasonably competent at it. I'm currently working on an astrophysics project in which my part involves the construction of a star tracker. A star tracker is basically a CCD camera controlled by an embedded system that takes images of the sky and cross-references a catalog to find where the telescope is pointing (it's a little more complicated than that, but that's the important bit). Anyway, my PI was on a project with some guy who had written just such a program for controlling a star tracker, and when it came time for me to build one, he suggested that I recycle the code from the old program since that code had been tested and shown to work. I took a day to look at the code and came back to him arguing for a complete rewrite of the program, but he basically put me off and I got stuck maintaining code written by some dude from a previous project. The problems with this piece of software were legion. Keep in mind that there are probably over 6000 lines of C/C++ code in this thing, which may not be all that much for a serious project, but it's still a lot to go through. Strap yourselves in; this thing contained the following features:
That's what I've been working with nearly every day now for over a year. It's a loving nightmare and I routinely wish for death while debugging this code. I can't scrap it and start over because my PI won't let me, and I've gotten it to more or less a state of functionality, but it's been an uphill struggle all the way. A couple of times I phoned the guy who had written it with questions, and he sounded very apologetic over the phone, so I don't really hold it against him too much. Hopefully my tale of woe is amusing. At the very least, it should serve as a cautionary tale against having scientists develop software.
|
# ? Jul 10, 2008 18:26 |
|
Motherfucking this.code:
|
# ? Jul 10, 2008 18:53 |
|
Found this in the code for an NT service that's actually part of a commercial software package:code:
|
# ? Jul 10, 2008 19:33 |
|
Volte posted:I think it's because there is only one command being executed in that transaction. In other words, it's not really doing anything. Exactly. Doing a transaction with a single SQL command deleting one single row is pretty pointless.
|
# ? Jul 11, 2008 09:11 |
|
Sebastian Flyte posted:Exactly. Doing a transaction with a single SQL command deleting one single row is pretty pointless.
|
# ? Jul 11, 2008 11:57 |
|
ryanmfw posted:I've seen some elegant solutions at programming competitions: God drat, I wrote something in Python that was under 200 lines that could do the same thing, except it went from 0 to 999,999. And it sure as hell didn't take me 6 hours!
|
# ? Jul 11, 2008 13:50 |
|
|
# ? May 15, 2024 04:06 |
|
BattleMaster posted:God drat, I wrote something in Python that was under 200 lines that could do the same thing, except it went from 0 to 999,999. And it sure as hell didn't take me 6 hours! I wrote one in XSLT
|
# ? Jul 11, 2008 14:15 |