Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Victor
Jun 18, 2004
The WTF here is probably writing a logging framework instead of using one -- or did you really need to write your own?

Adbot
ADBOT LOVES YOU

fankey
Aug 31, 2001

Victor posted:

The WTF here is probably writing a logging framework instead of using one -- or did you really need to write your own?
About 50% of this project deals with logging and configuring their logging. Which they probably needed to figure out why their crappy code wasn't working as expected. It seems like every open source project I look at implements their own brand of logging - that means that if my application uses a couple of different libraries I have multiple log implementations. They should really just expose hooks so I can log events when I want to. Regardless, lines like these are priceless
code:
if (logger.GetType().ToString() != "NSpring.Logging.Loggers.StreamLogger")

fansipans
Nov 20, 2005

Internets. Serious Business.
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

:suicide:

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

Richard Noggin
Jun 6, 2005
Redneck By Default

fankey posted:

logging stuff

Christ, are they trying (and failing) to reinvent log4net?

shrughes
Oct 11, 2008

(call/cc call/cc)
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:
public void TestMaze()
{
    // all tests pass!
}
Another wrote his in C++, and half his code consisted of helper functions to handle memory management. (The problem required a single dynamically sized two dimensional array of chars.)

Internet Headache
May 14, 2007
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);



?>
I left formatting intact except for removing 4 levels of tabs.

This is one of the more secure pieces of code.

Internet Headache fucked around with this message at 01:48 on Dec 21, 2008

HIERARCHY OF WEEDZ
Aug 1, 2005

Internet Headache posted:

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);



?>
I left formatting intact except for removing 4 levels of tabs.

This is one of the more secure pieces of code.

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.

MononcQc
May 29, 2007

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.

mr_jim
Oct 30, 2006

OUT OF THE DARK

tripwire posted:

Ulillillia released the source code for a program he designed in C which converts the sampling rate of PCM wave files.
Check it out:
http://www.ulillillia.us/files/WAVFileSampleRateGeneratorV2Source.zip


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. :downs:

code:
$ wc -l WAV\ file\ sample\ rate\ generator.c
1189 WAV file sample rate generator.c

$ gcc -Wall -lm WAV\ file\ sample\ rate\ generator.c
WAV file sample rate generator.c: In function ‘CreateOutputFiles’:
WAV file sample rate generator.c:684: warning: too many arguments for format
WAV file sample rate generator.c:838: warning: too many arguments for format
WAV file sample rate generator.c:1190:2: warning: no newline at end of file

<- After running... ->

$ ls
a.out
C:\My Documents\Songs for MP3\source files\to convert\16K files\050000 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\16K files\051200 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\16K files\055000 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\16K files\060000 Final Fantasy 6 World.wav

<- snip about 80 lines ->

C:\My Documents\Songs for MP3\source files\to convert\48K files\130000 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\48K files\133333 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\48K files\140000 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\48K files\141421 Final Fantasy 6 World.wav
C:\My Documents\Songs for MP3\source files\to convert\48K files\150000 Final Fantasy 6 World.wav
WAV file sample rate generator.c
Edit:

code:
int main()
{
	// main function, required with C, but used to call the related functions
	Settings(); // gets some settings set
	CreateOutputFiles(); // initiate the loop for creating the output files copying 
comment wrapping mine ->     // the data above changing the 8 bytes as needed
	
	return 0; // function must return something, usually 0
}
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.

mr_jim fucked around with this message at 05:48 on Dec 22, 2008

tripwire
Nov 19, 2004

        ghost flow

mr_jim posted:

I think its pretty charming from the "how would a determined idiot make this work" perspective.

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 :)

TheSleeper
Feb 20, 2003

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.

niggaruto
Oct 25, 2007

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.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Whatever makes him happy, I guess. I spent about a half hour reading his site and now I'm all :psyduck:

Rottbott
Jul 27, 2006
DMC

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.

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.
There are several functions over 3000 lines in the C codebase I work with.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Rottbott posted:

There are several functions over 3000 lines in the C codebase I work with.

why

mr_jim
Oct 30, 2006

OUT OF THE DARK

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?

floWenoL
Oct 23, 2002

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.

tripwire
Nov 19, 2004

        ghost flow

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?

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
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.

awesmoe
Nov 30, 2005

Pillbug

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.

Mikey-San
Nov 3, 2005

I'm Edith Head!
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?

shrughes
Oct 11, 2008

(call/cc call/cc)

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.

That Turkey Story
Mar 30, 2003

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.

floWenoL
Oct 23, 2002

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. :eng99:

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

shrughes
Oct 11, 2008

(call/cc call/cc)

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.

POKEMAN SAM
Jul 8, 2004

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.

That Turkey Story
Mar 30, 2003

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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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.

Mikey-San
Nov 3, 2005

I'm Edith Head!

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. :)

Mikey-San
Nov 3, 2005

I'm Edith Head!

That Turkey Story posted:

He's also really freakin gay.

forgot to quote dis here

mr_jim
Oct 30, 2006

OUT OF THE DARK

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.

Zombywuf
Mar 29, 2008

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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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.

Zombywuf
Mar 29, 2008

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.

ehnus
Apr 16, 2003

Now you're thinking with portals!
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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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.

floWenoL
Oct 23, 2002

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!

TheSleeper
Feb 20, 2003

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:
inline void foo (char c) __attribute__((always_inline));
and equivalents?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
__really_fucking_inline_i_mean_it_this_time_mister()

Adbot
ADBOT LOVES YOU

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

TheSleeper posted:

What's the problem with, for instance, GCC's:
code:
inline void foo (char c) __attribute__((always_inline));
and equivalents?

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply