|
The WTF here is probably writing a logging framework instead of using one -- or did you really need to write your own?
|
# ? Dec 16, 2008 18:40 |
|
|
# ? Apr 29, 2024 00:04 |
|
Victor posted:The WTF here is probably writing a logging framework instead of using one -- or did you really need to write your own? code:
|
# ? Dec 16, 2008 18:54 |
|
So one of our applications at work is slow. OK. It's responsible for managing access control for about 2000 users. OK. So the first time it was reported as acting slow, I looked at the source. Every time the main page is loaded, all users are selected from the database, and any filtering/sorting is done by Java embeded the the JSP page. OK, that's probably the problem. Nothing much you can do about it without a rewrite, so I don't worry about it. The complaints persist. I take another look. It turns out that the information for each of the 2000 users is loaded into the "AdmUser2" object. Which queries the database upon instantiation to find out more info about the user So. 1 query that fetches ~50kb of information needlessly, and then almost always filters it all down to a dozen records, and 2000 queries to find out what databases people have access to (so we can ignore all but about a dozen of them) And how is database access checked by the JSP filtering code? By comparing the desired database name against a generated HTML list of databases from the user object Final Exam Question 13: Given the algorithm above, describe the scalability in big-O notation. O( Hindenburg^Titanic ) Edit: Sent this post to a friend and double-checked the link in a non-logged in browser - HOLY CRAP are the non-logged-in ads obnoxious!! Has it always been that bad? fansipans fucked around with this message at 19:09 on Dec 16, 2008 |
# ? Dec 16, 2008 19:03 |
|
fankey posted:logging stuff Christ, are they trying (and failing) to reinvent log4net?
|
# ? Dec 16, 2008 21:01 |
|
We give applicants a coding test and we've gotten back some interesting responses. One guy asked, "Could you send me some test files?" We answered no. Then he invented his own input file format. The instructions are very clear what the input will be. Another made a project (in twice the typical time) that contained only a test class, with one method that said: code:
|
# ? Dec 17, 2008 06:17 |
|
This is what happens when a company contracts a PHP application to a company that subcontracts an Indian company.php:<? $c = md5($newpassword.$saltdb); $pass_comparison = $c.':'.$saltdb; //echo $pass_comparison; if($_POST['txt_oldpass']=="" && $_POST['txt_newpass']=="" && $_POST['txt_verifypass']=="") { $account="UPDATE {OMITTED} SET name ='".$_POST['txt_firstname']."',lastname='" .$_POST['txt_lastname']."',email='".$_POST['txt_email']."' WHERE id='". $userID ."'"; $Accountinfn = $db->query($account); ?> This is one of the more secure pieces of code. Internet Headache fucked around with this message at 01:48 on Dec 21, 2008 |
# ? Dec 21, 2008 01:39 |
Internet Headache posted:This is what happens when a company contracts a PHP application to a company that subcontracts an Indian company. I wonder if a language can reach a point where it simply becomes too great a threat to the average level of security on the internet to ever be used again. If it's at all possible, PHP is the only language on that map.
|
|
# ? Dec 22, 2008 00:25 |
|
Panic! at the Fist Jab posted:I wonder if a language can reach a point where it simply becomes too great a threat to the average level of security on the internet to ever be used again. If it's at all possible, PHP is the only language on that map. Remove PHP and it's well possible that most of the lovely part of its user base will just flock to another language and find ways to make code as bad, unclear and insecure.
|
# ? Dec 22, 2008 01:47 |
|
tripwire posted:Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files. I looked at the code. I think he's Rainman. But it does compile with only a few warnings on linux, and doesn't crash when run. code:
code:
mr_jim fucked around with this message at 05:48 on Dec 22, 2008 |
# ? Dec 22, 2008 05:28 |
|
mr_jim posted:It's weird because his diction and tone seem to indicate some level of understanding and comprehension, probably enough to grasp why mountains of global variables are bad if he was taught. Part of me wants to just email him and help him out, but another part of me knows it would be an effort in futility because of how set in his ways he seems to be. Either way, very amusing code
|
# ? Dec 22, 2008 05:56 |
|
mr_jim posted:This is all the way at the bottom of the file. I'm guessing from that first comment that C isn't his first language, so he has no clue about good style. Hence the three pages of global variable declarations at the top of the file, and the 560 line void FindNextSampleRate() function. You think that's bad? I once went to take a look at a program that was designed to parse one poker site's hand history format and output another's. Nearly all the work was done in one function: the "go" button's _click. The function starts on line 234 and ends on line 1020. I initially wanted to fix a small bug that should have been easy to find but eventually gave up because there was so much crap in there it wasn't worth my time.
|
# ? Dec 22, 2008 07:48 |
|
mr_jim posted:This is all the way at the bottom of the file. I'm guessing from that first comment that C isn't his first language, so he has no clue about good style. Hence the three pages of global variable declarations at the top of the file, and the 560 line void FindNextSampleRate() function. I've seen quotes from him saying he just finds it more convenient to make everything global and enjoys playing with the settings that way and recompiling.
|
# ? Dec 22, 2008 08:12 |
|
Whatever makes him happy, I guess. I spent about a half hour reading his site and now I'm all
|
# ? Dec 22, 2008 09:29 |
|
TheSleeper posted:You think that's bad? I once went to take a look at a program that was designed to parse one poker site's hand history format and output another's.
|
# ? Dec 22, 2008 11:07 |
|
Rottbott posted:There are several functions over 3000 lines in the C codebase I work with. why
|
# ? Dec 22, 2008 19:58 |
|
Rottbott posted:There are several functions over 3000 lines in the C codebase I work with. But do they all have a "void funct(void)" type signature and do all their interaction though global variables?
|
# ? Dec 22, 2008 20:48 |
|
Mikey-San posted:why Some things are just complex and wouldn't benefit from trying to artificially split it up. That and C is pretty low-level so it can get verbose.
|
# ? Dec 22, 2008 21:18 |
|
floWenoL posted:Some things are just complex and wouldn't benefit from trying to artificially split it up. That and C is pretty low-level so it can get verbose. I guess I should qualify this by saying I'm a complete programming noob, but I've never seen a huge function that couldn't benefit in terms of legibility and ease of maintenance by being split up in an appropriate way. Whats an example of something for which this doesn't apply?
|
# ? Dec 22, 2008 21:26 |
|
Two jobs ago I used to write server-side code for online casino systems. The multiplayer poker server codebase regularly had .cpp files that ran to 50k lines, with some functions being at least a few hundred lines, if not breaking the thousand line mark.
|
# ? Dec 22, 2008 21:31 |
|
beuges posted:Two jobs ago I used to write server-side code for online casino systems. The multiplayer poker server codebase regularly had .cpp files that ran to 50k lines, with some functions being at least a few hundred lines, if not breaking the thousand line mark. Yeah, the stuff I work with has some parts like this. It's amazing how good an indicator of quality the incredibly-long-function rule of thumb is.
|
# ? Dec 23, 2008 00:26 |
|
Don't get me wrong, I've seen really long functions in C programs before, but 3,000+ lines for one function? What's the weird case here that makes such a beast necessary?
|
# ? Dec 23, 2008 01:26 |
|
tripwire posted:I guess I should qualify this by saying I'm a complete programming noob, but I've never seen a huge function that couldn't benefit in terms of legibility and ease of maintenance by being split up in an appropriate way. Whats an example of something for which this doesn't apply? floWenoL is just wrong.
|
# ? Dec 23, 2008 01:26 |
|
shrughes posted:floWenoL is just wrong. This. Take whatever floWenoL says with a grain of salt, he's not very smart and he loves to mislead people by giving purposely false information. If all of your functions aren't less than 10 lines you probably made a huge mistake/are a terrible programmer. He's also really freakin gay.
|
# ? Dec 23, 2008 01:58 |
|
That Turkey Story posted:This. Take whatever floWenoL says with a grain of salt, he's not very smart and he loves to mislead people by giving purposely false information. If all of your functions aren't less than 10 lines you probably made a huge mistake/are a terrible programmer. He's also really freakin gay. It's...true. Edit: Okay, 3000 lines *is* a bit much. But splitting up functions just for the sake of bringing per-function line count to some arbitrary maximum isn't a good idea. floWenoL fucked around with this message at 02:41 on Dec 23, 2008 |
# ? Dec 23, 2008 02:13 |
|
That Turkey Story posted:This. Take whatever floWenoL says with a grain of salt, he's not very smart and he loves to mislead people by giving purposely false information. If all of your functions aren't less than 10 lines you probably made a huge mistake/are a terrible programmer. He's also really freakin gay. Well regarding 3000 line functions, they're only sensible when the level of complexity is very low, like when 2975 lines are used to fill a static array.
|
# ? Dec 23, 2008 02:16 |
|
shrughes posted:Well regarding 3000 line functions, they're only sensible when the level of complexity is very low, like when 2975 lines are used to fill a static array. Maybe you should be reading in your static array in some other fashion then? I mean I do know of reasons for having that data in code, but there are often times better solutions.
|
# ? Dec 23, 2008 02:33 |
|
shrughes posted:Well regarding 3000 line functions, they're only sensible when the level of complexity is very low, like when 2975 lines are used to fill a static array. Metaprogram that poo poo, bitch.
|
# ? Dec 23, 2008 03:09 |
|
Mikey-San posted:Don't get me wrong, I've seen really long functions in C programs before, but 3,000+ lines for one function? What's the weird case here that makes such a beast necessary? Language interpreters regularly end up like this, although "large functions" tends to be the least of the craziness. But if you're worried at all about interpreter performance, you really can't afford to make a function call per instruction or AST node.
|
# ? Dec 23, 2008 04:14 |
|
quote:Okay, 3000 lines *is* a bit much. But splitting up functions just for the sake of bringing per-function line count to some arbitrary maximum isn't a good idea. Agreed. 3,000 just struck me as whoa, slow down partner in most situations. quote:Language interpreters regularly end up like this, although "large functions" tends to be the least of the craziness. But if you're worried at all about interpreter performance, you really can't afford to make a function call per instruction or AST node. Sounds reasonable. quote:Well regarding 3000 line functions, they're only sensible when the level of complexity is very low, like when 2975 lines are used to fill a static array. I certainly hope you don't need to do this very often.
|
# ? Dec 23, 2008 05:34 |
|
That Turkey Story posted:He's also really freakin gay. forgot to quote dis here
|
# ? Dec 23, 2008 05:36 |
|
That Turkey Story posted:Metaprogram that poo poo, bitch. Quotin' dis. It would take some pretty unusual circumstances for me to feel comfortable having a 3000 line function without trying to factor out any of it into helper functions.
|
# ? Dec 23, 2008 08:23 |
|
rjmccall posted:Language interpreters regularly end up like this, although "large functions" tends to be the least of the craziness. But if you're worried at all about interpreter performance, you really can't afford to make a function call per instruction or AST node. Your compiler should decide when to inline the functions. It's probably better at it than you are.
|
# ? Dec 23, 2008 18:29 |
|
Zombywuf posted:Your compiler should decide when to inline the functions. It's probably better at it than you are. This is excellent advice for general programming, but it's not so hot for core interpreter loops.
|
# ? Dec 23, 2008 20:27 |
|
rjmccall posted:This is excellent advice for general programming, but it's not so hot for core interpreter loops. Get a better compiler or write it in asm. If you're second guessing your compiler's interpretation of instruction cache usage, you have a problem.
|
# ? Dec 23, 2008 21:49 |
|
I found a coding horror today:Zombywuf posted:Get a better compiler or write it in asm. If you're second guessing your compiler's interpretation of instruction cache usage, you have a problem. If you don't have a healthy paranoia of the code your compiler generates then you probably haven't been developing for very long. Not every platform has the luxury of being able to switch to a potentially better compiler either, not to mention that writing it in assembly because of it's C/C++ line count is just dumb.
|
# ? Dec 23, 2008 22:21 |
|
Zombywuf posted:Get a better compiler or write it in asm. If you're second guessing your compiler's interpretation of instruction cache usage, you have a problem. "Large functions are hard to maintain, so interpreters should be written in assembly." Thanks, that's very helpful. And which compiler would you suggest? I need one that can calculate the occurrence rates of different cases in an arbitrary switch statement; sadly, my current inliner just uses sophisticated heuristics about calling context and callee size and behavior. I'm really not sure why you're arguing with me here; all I'm saying is that portable interpreters sometimes need to sacrifice cleanness for performance. I would absolutely agree that second-guessing the optimizer is usually just shooting yourself in the foot, especially when moving to different platforms and compilers.
|
# ? Dec 23, 2008 23:13 |
|
Zombywuf posted:Your compiler should decide when to inline the functions. It's probably better at it than you are. Oh, how cute, it's someone who hasn't ever needed to program for performance!
|
# ? Dec 23, 2008 23:27 |
|
rjmccall posted:"Large functions are hard to maintain, so interpreters should be written in assembly." Thanks, that's very helpful. And which compiler would you suggest? I need one that can calculate the occurrence rates of different cases in an arbitrary switch statement; sadly, my current inliner just uses sophisticated heuristics about calling context and callee size and behavior. What's the problem with, for instance, GCC's: code:
|
# ? Dec 23, 2008 23:47 |
|
__really_fucking_inline_i_mean_it_this_time_mister()
|
# ? Dec 23, 2008 23:49 |
|
|
# ? Apr 29, 2024 00:04 |
|
TheSleeper posted:What's the problem with, for instance, GCC's: A few things, some minor, some major. First, it's a gcc-ism without equivalents on a lot of compilers; if you're worried about compiler portability, that's a big issue, particularly if you start relying on inlining to get good performance out of re-used code (passing "invert the logic" flags to comparison functions, that sort of thing). Second, it restricts the data used by each case, which can make it slightly more awkward to redesign the core data structures; but that's not that important. Third, it's more awkward to implement control flow. Overall, though, it's a good approach if you can rely on it.
|
# ? Dec 24, 2008 00:35 |