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
shrughes
Oct 11, 2008

(call/cc call/cc)

king_kilr posted:

Not a coding horror the way everything else in this thread is, but a friend of mine hates writing functions. I have no idea why, or what caused him to think this way, but he does. He often asks me things like, "Can I do this without writing an extra function?", and I don't get it. Luckily he's still a student, maybe they can beat it out of him.

That's pretty funny. Is it because he thinks that function calls are expensive?

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007

shrughes posted:

That's pretty funny. Is it because he thinks that function calls are expensive?

Nah, nothing like that (my amusing rationale was API bloating :P), I think he doesn't quite "think like a programmer" yet.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
When I suggest making a new function to a certain non-programmer taking an intro CS course it's always met with groans. This despite agreeing later that the added function makes things clearer and easier. Maybe it's the mental context switch needed, and I just don't notice it after so much practice.

Zhentar
Sep 28, 2003

Brilliant Master Genius
My money would be on a poor understanding of the syntax involved, or not understanding beforehand what values need to be passed. Either way, it means extra work switching back and forth between from the header trying to correctly define the function.

1337JiveTurkey
Feb 17, 2005

Sprawl posted:

Both of those ways are dumb because then you have to change too much should you need to make a change. You should just make an custom generic and be passing that.

That sort of ties into the whole thing about beginning programmers and tools in that it's debating the architecture of an essentially solved problem. Just use an ESB and a data binding API, create a Reservation class and get down to the important parts.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


As a break from the regularly scheduled coding horrors normally posted in this thread, I just wrote a scene for a one-act play about the development of a project that was recently deployed. I hope you enjoy...

Dev1: "We're not sure if our jms messaging infrastructure works. What ever will we do?"
Dev2: "Let's start keeping track of messaging statistics."
Dev1: "Good idea!"
Dev2: "We could also create a centralized service to keep track of messaging stats from every application."
Dev1: "Even better idea! But how will we get the stats to the centralized server?"
Dev2: "We'll use jms, of course."
Dev1: "Surely this is a plan that can not fail!"

*high fives all around*

cliffy
Apr 12, 2002

king_kilr posted:

Nah, nothing like that (my amusing rationale was API bloating :P), I think he doesn't quite "think like a programmer" yet.

Maybe he doesn't like the mental effort of abstracting code into a function versus copy-pasting. He also doesn't have the sting of experience to convince himself how bad things can get when you go down that path.

"Oh poo poo, there's something subtly wrong with this code that I pasted a hundred times. That means I have to... FUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"

qntm
Jun 17, 2009
Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror. What is the thought process that leads to an omission like that? I have severe problems attributing this to malice or incompetence, it has to be literally "I'm writing a program which lets people retrieve files and directories from remote locations. Oh, but not directories. I think I'll leave that bit out."

cliffy
Apr 12, 2002

qntm posted:

Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror. What is the thought process that leads to an omission like that? I have severe problems attributing this to malice or incompetence, it has to be literally "I'm writing a program which lets people retrieve files and directories from remote locations. Oh, but not directories. I think I'll leave that bit out."

Doesn't NLST allow you to get the contents of a directory? You can easily build recursive functionality on top of this, so I'm not sure how the omission is a 'horror'. Network bandwidth was at a premium when the FTP protocol came about in 1985. Recursive directory enumeration could take a long time over a network, not to mention on a local machine. So in fact their 'omission' was probably a good design decision.

such a nice boy
Mar 22, 2002

qntm posted:

This isn't really a coding horror, it's more of an absence-of-coding horror. What is the thought process that leads to an omission like that? I have severe problems attributing this to malice or incompetence, it has to be literally "I'm writing a program which lets people retrieve files and directories from remote locations. Oh, but not directories. I think I'll leave that bit out."

I could see good arguments for making this a client responsibility. You keep the FTP protocol simple: only allow listing files and downloading one file at a time. Given those tools, the client can implement recursively downloading directories.

Shumagorath
Jun 6, 2001

king_kilr posted:

Not a coding horror the way everything else in this thread is, but a friend of mine hates writing functions. I have no idea why, or what caused him to think this way, but he does. He often asks me things like, "Can I do this without writing an extra function?", and I don't get it. Luckily he's still a student, maybe they can beat it out of him.
drat, and I thought I was awful for using nothing but global variables until late in 11th grade.

shrughes
Oct 11, 2008

(call/cc call/cc)

qntm posted:

Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

Have an RPC protocol where the client sends code to be run sandboxed on the server. It's the only option unless you want zillions of useful features.

ToxicFrog
Apr 26, 2008


qntm posted:

Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror.

This isn't a horror at all. As others have pointed out, the protocol has everything you need to easily implement recursive transfers, and any decent ftp client - nsftp, lftp, filezilla, wget, etc - supports them.

The real horror is that the plain 'ftp' command that most operating systems ship with hasn't been updated since the early 80s.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ryouga Inverse posted:

If you think that "because it's a school assignment" is a good reason to stick a bunch of business logic in main, then I don't know what to tell you. Nothing important goes in main.

It really depends on the class' subject matter but expecting students to implement good software engineering practices at every level for every assignment when the whole point of the assignment is likely very narrowly defined is total overkill. Designing this Hotel class is probably the entire project. If someone did this in the real-world you'd be fully justified in telling them their code sucks and they should rework it.

Abstracting away any dependency layers is obviously a best practice but school projects just don't operate at that level.

Were you the guy in class that was pissed no one else did the extra credit assignments?

Dr Monkeysee fucked around with this message at 21:09 on Apr 16, 2010

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

king_kilr posted:

Not a coding horror the way everything else in this thread is, but a friend of mine hates writing functions. I have no idea why, or what caused him to think this way, but he does. He often asks me things like, "Can I do this without writing an extra function?", and I don't get it. Luckily he's still a student, maybe they can beat it out of him.

This is the guy who wrote oscommerce's admin/categories.php:
code:
$ wc -l categories.php 
    3163 categories.php

$ grep 'function' categories.php | wc -l
    16
Well it looks like it has 16 functions, maybe each one is 150 lines.

Too bad they're all javascript functions, and half those lines are comments. :(

I hate working on that file.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Monkeyseesaw posted:

Were you the guy in class that was pissed no one else did the extra credit assignments?

No, I don't care if people want to gently caress off in class, and I don't care how awful the code is.

Maybe I came across a bit harsh, but what I mean is that if you're going to discuss the design of an app, the fact that it's for a school assignment isn't important and doesn't justify a crappy design.

No one expects you to just pull SE best practices out of your rear end. Well, at least I don't. But if I were posting in the coding horrors thread critiquing someone else's code, when my own code isn't really that great either (though certainly better), I'd appreciate critique on it too.

The whole point is to learn and become a better developer, right?

evensevenone
May 12, 2001
Glass is a solid.

qntm posted:

Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror. What is the thought process that leads to an omission like that? I have severe problems attributing this to malice or incompetence, it has to be literally "I'm writing a program which lets people retrieve files and directories from remote locations. Oh, but not directories. I think I'll leave that bit out."

First, remember it was like 1980 and people paid dearly for bandwidth and storage. Hell, people paid for CPU cycles.

Second, they probably didn't want issues where people would get a lot more than they expected, for example if the directory contained subdirectories and one of the subdirectories had a symlink to somewhere else and so on. Plus it would mean the server would be responsible for catching recursive symlinks and resolving it in some way.

Finally, if you, the client author, wanted to implement getting directories, you could do it and all of those hassles would be on your head and you could implement it in a way that made sense for your OS.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ryouga Inverse posted:

No, I don't care if people want to gently caress off in class, and I don't care how awful the code is.

Maybe I came across a bit harsh, but what I mean is that if you're going to discuss the design of an app, the fact that it's for a school assignment isn't important and doesn't justify a crappy design.

No one expects you to just pull SE best practices out of your rear end. Well, at least I don't. But if I were posting in the coding horrors thread critiquing someone else's code, when my own code isn't really that great either (though certainly better), I'd appreciate critique on it too.

The whole point is to learn and become a better developer, right?

I guess my position is whether the code is crappy or not is dependent on context and in the context of a school assignment doing input processing in main is pretty frickin' low on the list of coding sins.

But whatever. The real answer is do whatever won't piss off the professor :) If she really gives a big poo poo about having the hotel process the input then do that. There's plenty of time to learn best practices.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Ryouga Inverse posted:

Maybe I came across a bit harsh, but what I mean is that if you're going to discuss the design of an app, the fact that it's for a school assignment isn't important and doesn't justify a crappy design.

...

The whole point is to learn and become a better developer, right?

One of the more important things to learn as a developer is that "worse is better". It's a huge waste of time to design some generic, extensible framework if you're never actually going to extend it.

return0
Apr 11, 2007
Hotels don't give a gently caress about reading input, pretending they do is a horror.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Avenging Dentist posted:

One of the more important things to learn as a developer is that "worse is better". It's a huge waste of time to design some generic, extensible framework if you're never actually going to extend it.

yeah, this is something I learned only in the last year or so. instead of actually writing the retarded extensible framework now I just fantasize about how I could design something that far up its own rear end, then go and write whatever I need to write to make it work.

(and probably still overengineer the solution, but who doesn't really)

return0
Apr 11, 2007
Resisting speculative generality is great, but it's not an excuse for lazily writing bad code.

public void register(String name, int room)
public void register(Scanner scan)

Which is easier to write unit tests for?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
I just think about how I might make an extensible framework and then make sure that what I actually write doesn't unnecessarily make it difficult to write that framework One Day.

shrughes
Oct 11, 2008

(call/cc call/cc)
Both are pretty easy, you're talking about easily transformable code that doesn't really create some kind of framework trap that will ruin your life for the rest of the project.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

return0 posted:

Resisting speculative generality is great, but it's not an excuse for lazily writing bad code.

public void register(String name, int room)
public void register(Scanner scan)

Which is easier to write unit tests for?

If you have both, and all the one that takes a Scanner object does is parse the input and then pass it to the one that takes the string and int, then there isn't a problem with unit testing.

In fact, sticking the parser code in main is a good way to make sure that your app is impossible to fully unit test. In C# I would make it take a StreamReader, and then in a unit test I would give it a MemoryStream that had known values in it. Wow, it's so hard to unit test this (incredibly trivial) code!

I think this discussion has become the coding horror. It's like FizzBuzz for design instead of code.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Unit testing does not require (or even want) full code coverage so having logic in main really doesn't do anything to detract from that.

qntm
Jun 17, 2009

ToxicFrog posted:

This isn't a horror at all. As others have pointed out, the protocol has everything you need to easily implement recursive transfers, and any decent ftp client - nsftp, lftp, filezilla, wget, etc - supports them.

The real horror is that the plain 'ftp' command that most operating systems ship with hasn't been updated since the early 80s.

Yeah, it's the ftp command that I'm complaining about, not the protocol itself. If it's so easy to implement clever recursive transfers on top of ftp, why hasn't it been done and incorporated into ftp?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Because who the hell uses ftp?

ToxicFrog
Apr 26, 2008


qntm posted:

Yeah, it's the ftp command that I'm complaining about, not the protocol itself. If it's so easy to implement clever recursive transfers on top of ftp, why hasn't it been done and incorporated into ftp?

It kind of has.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ToxicFrog posted:

It kind of has.
You know what he means.

Scaevolus
Apr 16, 2007

The real horror of ftp is that the file list format isn't specified in the RFC, so clients have to implement multiple parsers to handle the different ways ftpds present information.

shrughes
Oct 11, 2008

(call/cc call/cc)

qntm posted:

Yeah, it's the ftp command that I'm complaining about, not the protocol itself. If it's so easy to implement clever recursive transfers on top of ftp, why hasn't it been done and incorporated into ftp?

Features are bad. Consider the ASCII transfer mode, or EBCDIC mode. Consider how many different modes of operation one would need for the different ways of doing directory hierarchies, symbolic links, and such. Hey, back in the day, some computers didn't even have directory hierarchies. Also, bandwidth was lower and disks were slower, so lag wasn't as important.

They probably just implemented the features they needed first, and then implemented other stuff in the client. And then they wrote that in the RFC. Which is from 1971. And that was the end of it.

shrughes fucked around with this message at 21:31 on Apr 17, 2010

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Ryouga Inverse posted:

yeah, this is something I learned only in the last year or so. instead of actually writing the retarded extensible framework now I just fantasize about how I could design something that far up its own rear end, then go and write whatever I need to write to make it work.

(and probably still overengineer the solution, but who doesn't really)

Does anyone remember that parody article about the guy who keeps making his solution more and more general, until he has created basically a whole new language that's loaded from an xml file? I'd love to find a link to that again.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Avenging Dentist posted:

Unit testing does not require (or even want) full code coverage so having logic in main really doesn't do anything to detract from that.

Yeah you're not going to be able to unit test the actual input processing anyway so as long as it's not wrapped up with the stuff you do want to unit test it really doesn't matter.

This is largely moot anyway. He's not writing unit tests for a drat school assignment.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Monkeyseesaw posted:

This is largely moot anyway. He's not writing unit tests for a drat school assignment.

If I'd known about unit tests it would've made some assignments sooooooo much easier...

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

HappyHippo posted:

Does anyone remember that parody article about the guy who keeps making his solution more and more general, until he has created basically a whole new language that's loaded from an xml file? I'd love to find a link to that again.

Isn't this basically Joel Spolsky? :rimshot:

hirvox
Sep 8, 2009

HappyHippo posted:

Does anyone remember that parody article about the guy who keeps making his solution more and more general, until he has created basically a whole new language that's loaded from an xml file? I'd love to find a link to that again.
So it was basically the (il)logical conclusion of the Hello World joke?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Monkeyseesaw posted:

This is largely moot anyway. He's not writing unit tests for a drat school assignment.
Why? I wrote unit tests for nearly every school assignment I did.

HappyHippo posted:

Does anyone remember that parody article about the guy who keeps making his solution more and more general, until he has created basically a whole new language that's loaded from an xml file? I'd love to find a link to that again.
This?

Plorkyeran fucked around with this message at 07:23 on Apr 19, 2010

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?
When resourcefulness goes horribly wrong.


code:
Below code help you get database backup simple:

function backupDatabase($file){
  $tables = array();
  $result = mysql_query('SHOW TABLES');
  while($row = mysql_fetch_row($result)){ $tables[] = $row[0]; }
  //cycle through
  $return = "";
  foreach($tables as $table){
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);
    $return.= 'DROP TABLE '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";
    for ($i = 0; $i < $num_fields; $i++){
      while($row = mysql_fetch_row($result)){
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++){
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }
  //save file
  $handle = fopen($file,'w+');
  fwrite($handle,$return);
  fclose($handle);
}
http://webwhiz.info/mysql-backup-on-demand-with-php.html

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

A A 2 3 5 8 K posted:

When resourcefulness goes horribly wrong.


code:
Below code help you get database backup simple:

function backupDatabase($file){
  $tables = array();
  $result = mysql_query('SHOW TABLES');
  while($row = mysql_fetch_row($result)){ $tables[] = $row[0]; }
  //cycle through
  $return = "";
  foreach($tables as $table){
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);
    $return.= 'DROP TABLE '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";
    for ($i = 0; $i < $num_fields; $i++){
      while($row = mysql_fetch_row($result)){
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++){
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }
  //save file
  $handle = fopen($file,'w+');
  fwrite($handle,$return);
  fclose($handle);
}
http://webwhiz.info/mysql-backup-on-demand-with-php.html

quote:

04/19/2010 at 4:20 am
but this for only basic and small database.

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