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
_aaron
Jul 24, 2007
The underscore is silent.
code:
#ifndef TRUE
#define TRUE true
#endif

#ifndef FALSE
#define FALSE true
#endif
Good loving god! What could the purpose of this possibly be?

I remember a long time ago seeing something similar on theDailyWTF...
code:
#define true 0
#define false 1
Can you imagine trying to debug an application written this way?

Adbot
ADBOT LOVES YOU

_aaron
Jul 24, 2007
The underscore is silent.
This isn't as bad as some of the trainwrecks in here, but it made me scratch my head for a minute.
code:
 (C#)
for (int i = 0; i < this.publishToClients.Count; i++)
{
   if (this.publishToClients[ i] is PublishToSetting)
   {
      PublishToSetting client = this.publishToClients[ i];
      if (clientStr.CompareTo("") != 0 )
      {
         //add a comma if it isn't the first client in the string
         clientStr += ",";
      }
      clientStr += client.Alias + ":" + client.Ip + ":" + client.Port + ":" + client.TheProtocol;
   }
}
This is for writing out configuration data to a file. First of all, we have no reason here to not be using a 'foreach' loop instead of a counter-controlled 'for' loop. Secondly, "publishToClients" is an instance of a custom collection class (actually just a derivation of list because people on this team didn't learn about generics until recently) that is guaranteed to only hold objects of type PublishToSetting. That first 'if' statement is completely useless. Lastly, and this could be just personal preference, but they have the special first case handling in the loop rather than doing it once before the loop and then not worrying about any handling for that inside.

I swear my coworkers aren't idiots. I think this is just a case of coding something out and then not really looking it over once you're done with it.

_aaron
Jul 24, 2007
The underscore is silent.

Victor posted:

code:
string clientStr = this
    .publishToClients
    .OfType<PublishToSetting>()
    .Select(c => string.Format("{0}:{1}:{2}:{3}", c.Alias, c.Ip, c.Port, c.TheProtocol))
    .Join(",");
(string Join(string delimiter) is a method I made, because MS didn't include it by default, for some odd reason.)
Hahaha, that's pretty awesome. But correct me if I'm wrong here: most of that stuff is .Net 3.5 stuff, right? We are still using vs2005 (but will be upgrading soon), so that doesn't apply to our stuff. When we do make the switch, I will certainly keep this in mind.

_aaron
Jul 24, 2007
The underscore is silent.

Lexical Unit posted:

Sometimes I'll do this like if I'm returning a the boolean value of an expression or using ?: or something, just to bring attention to it. So like return (foo ? "foo" : "not foo"); or return (a && (b || c));. I don't know, it also looks somehow cleaner to my mind. V:shobon:V
These types of things are fine, and I would say almost encouraged, because it really helps with readability. But if you write return (x);, what readability is gained here vs. return x;?

_aaron
Jul 24, 2007
The underscore is silent.
Yeah, you're probably an idiot, because won't s.IsNullOrEmpty() throw an exception is s is null?

edit: Well gently caress me, this is totally incorrect. I just tested it out quick, and this does not throw an exception at all. I'll leave it up in case anyone wants to laugh at me :smith:.

_aaron fucked around with this message at 18:54 on Apr 7, 2008

_aaron
Jul 24, 2007
The underscore is silent.

yaoi prophet posted:

poo poo, if I can get a few people to sleepily stare at my code for a few seconds during a code review, that's a good day.
I must be really lucky; code reviews at my office tend to be very useful. While we haven't recently had time to make sure that every single line is optimized for performance or anything like that, people always come to the meetings with suggestions and ideas.

_aaron
Jul 24, 2007
The underscore is silent.
No space before the comma? Clearly this person doesn't know how to properly use white space.

_aaron
Jul 24, 2007
The underscore is silent.

Jethro posted:

Maybe they don't trust the collection.getDetails().size() method?
That still doesn't explain why they get the element in each iteration of the loop. That same loop where they use collection.getDetails().size().
What the hell indeed...

_aaron
Jul 24, 2007
The underscore is silent.

JoeNotCharles posted:

Can't speak for Java, but in C++ length() would almost certainly be simple enough to inline. That's not the whole story, though, since I don't believe inlining works when length() is in a shared library, which it probably is. (I think you can get inlining to work across library boundaries, but you have to do extra work? I dunno, I should read up on this.)
I think what he was saying was that the code could look something like this:
code:
for(int i = 0; !false && i < word.length(); i++) {
   if (word[i] == '1')
      word = word + '0';
}
Or something simple like that. Basically, the work in the loop could be changing the length of word.

_aaron
Jul 24, 2007
The underscore is silent.

Zombywuf posted:

Words fail me.
No, see, this is great, because then you can do things like:
code:
string boolString = BooleanFormatter.Format(true, "false", "true");
MessageBox.Show(true.ToString() + " is " + boolString);
You don't see the utility here!? Not to mention the deep philosophical implications of subjectively defining "true" and "false"...

_aaron
Jul 24, 2007
The underscore is silent.

Karanth posted:

:downs:
Oh gently caress you that is brilliant and terrible.

_aaron
Jul 24, 2007
The underscore is silent.
A Hotel object should not be dependent on where the registration data comes from, it just needs to know what's required for registration to happen (which is a name and room number, as shown in 'your' method signature).

But yeah, there's a difference between production level code and a school assignment. In reality, some other object would be getting user input and structuring it in such a way that it makes sense for the Hotel object. I would say that doing the input processing in main (or some other method that is NOT part of the Hotel object) would be preferred here.

_aaron
Jul 24, 2007
The underscore is silent.

pseudorandom name posted:

It's doing that for every language right now, although that's probably just it being broken in Firefox.
Yeah, it definitely doesn't work in FF right now. Using IE Tab is an easy-enough workaround, but it's still dumb.

_aaron
Jul 24, 2007
The underscore is silent.

PhonyMcRingRing posted:

BlogEngine.NET's javascript library is littered with this kind of crap. I'm sure glad they managed to parse that date three times.

code:
function formatJSONDate(jsonDate) {
   var date = new Date(parseInt(jsonDate.substr(6), 10));
   var parsedDate = Date.parse(date);
   var d = new Date(parsedDate);
   var m = d.getMonth() + 1;
   var s = m + "/" + d.getDate() + "/" + d.getFullYear();
  
   if(s == "1/1/1001") {
      return "";
   } else {
      return s;
   }
}
jesus christ.

I don't really have a horror, but I'm tired of seeing SVN check-ins where the diff is nothing but extra blank lines. No, we didn't really need three blank lines between the end of the else statement and the end of the method.

_aaron
Jul 24, 2007
The underscore is silent.

ColdPie posted:

What's the commit message?
It's typically part of a bug fix where they changed another file, so the message is for the file where the code actually changed. It's like when they commit a fix, they just commit any changed files without doing a diff beforehand (which is probably the real horror).

_aaron
Jul 24, 2007
The underscore is silent.

Internet Janitor posted:

Oh man I just had a great idea! Instead of using confusing syntax like /**/ and // to add my comments, I could just create a class for commenting:
No god drat way.

_aaron
Jul 24, 2007
The underscore is silent.

evensevenone posted:

it's the end of the quarter, and I already wrote transpose, so why waste time?
code:
GraphRef copyGraph(GraphRef G)
{
	return transpose(transpose(G));
}
Haha, I actually kinda like this. It's bad, but still mildly clever :)

_aaron
Jul 24, 2007
The underscore is silent.

npe posted:

I've also seen "Bug: Square Peg does not fit into Round Hole", which exists solely so that tickets can be closed as a duplicate of it....
This rules. No way it would fly at my company, though :(

_aaron
Jul 24, 2007
The underscore is silent.

Hammerite posted:

I'd like to be able to disagree, but I looked over Alexei's example and couldn't deduce the rules it uses to evaluate that expression to "horse". Still, if I were at all unsure about the precedence, I'd just slap a few pairs of brackets in so as to make it clear what should happen, so I don't really see the problem.
PHP was not the first programming language created. Many other languages use a ternary operator with the same order of precedence. Why should PHP come along and change things?

_aaron
Jul 24, 2007
The underscore is silent.

VerySolidSnake posted:

Ever since I stopped accommodating IE6 I haven't used a single hack. CSS is great and simple if you know what your doing. If you still think tables are a good idea you really need to pick up a new book on website development.

The main problem with CSS is that 90% of the tutorial websites out there give out either outdated our completely wrong techniques.
Not to derail too much, but I'd like to get into some web development, and I'd like to avoid these bad tutorials. Any suggestions for where to start learning? I've been learning Python lately, and I like it, so maybe something where I can put that to use?

_aaron
Jul 24, 2007
The underscore is silent.
Here's google's cached version: http://webcache.googleusercontent.c...any-suggestions

_aaron
Jul 24, 2007
The underscore is silent.

Mr. Crow posted:

The true coding horror: I'm being bitched at for not 'creating a design' for a task that took <30 minutes to implement and fully test.

So now I get to go back and spend probably 2+ hours "designing" the task out (manually mirror the code from source into EnterpriseArchitect, add explanations for stuff in a design doc and potentially add sequence diagrams to EA), getting it reviewed and addressing any 'defects' found.


An effective use of everyone's time.

I've seen a few of your posts in this thread (and maybe others?), and I swear you work at my old job. This process (and, in particular, Enterprise Archtitect) sounds very familiar. Dayton, Ohio?

_aaron
Jul 24, 2007
The underscore is silent.

Illusive gently caress Man posted:

i just loving hate all the code this guy writes. loving full of
C code:
#include <log.h>                                // for logging functions
C code:
    int i = 0;												// simple counter
I cannot stand poo poo like this. I know it's not even a big deal, it's just irrationally annoying.

_aaron
Jul 24, 2007
The underscore is silent.

Soricidus posted:

This is true, but only because the option exists to build an app with an Excel user interface driven by VBA.

I had an "internship" working for an insurance company for a couple summers during college. Their employee time-tracking system (ugh) was an in-house Access application driven by VBA. It was not fun to work on.

_aaron
Jul 24, 2007
The underscore is silent.

WHERE MY HAT IS AT posted:

code:
def sum(a, b):
    if (a == 1 and b == 1):
        return 2

    return 1
Correct code! No worries, I'll just add more ifs for different inputs as I write tests for them.
Well, yeah. You write more tests and modify sum() to ensure they pass. Then maybe you realize "hey, an if statement for every combination of inputs is loving stupid! there's probably a better way to do this..." You can refactor sum() to something cleaner/more efficient and be confident you didn't cause any regressions in your refactoring because you've got this whole suite of tests!

_aaron
Jul 24, 2007
The underscore is silent.

Steve French posted:

Or maybe you choose not to implement your code only considering the narrow circumstances of one test at a time, and you realize from the get go that an if statement for every combination of inputs is loving stupid, and avoid wasting your time.
When you're writing a method that just adds two numbers, you're right. It's fairly simple, not many edge cases, etc.

What if you're writing something that you don't fully understand when you sit down to write the method? Well, you know about cases A and B, so write tests for those, then write code to make them pass. Maybe in doing this, you think of another case C that you hadn't thought about before. Well, write a test case for it, and write code to make that test case pass. But wait, handling case C as an extension of what you've already written might be messy. So now you refactor. And you're confident that this new refactored code still works for the old A and B cases as well as the new C case that prompted the refactoring.

Which part are you having trouble with here? The use of addition as an example, or the idea that you would ever write a method without a full understanding of all of it's edge and corner cases up front? If it's the former, then I agree; addition is not a great example here. If it's the latter, then we have had very fundamentally different experiences as software developers.

Adbot
ADBOT LOVES YOU

_aaron
Jul 24, 2007
The underscore is silent.

Steve French posted:

To be more specific, I'm referring to the idea of intentionally writing and repeatedly revising an incomplete/incorrect implementation of a method to pass successive tests, rather than starting with a best effort of code and tests (regardless of which is written first), and then tweaking the code/tests and adding more tests as necessary to handle unforeseen edge cases.
Gotcha, I'm on board with this. I may have just misunderstood you earlier in the thread (or conflated a whole bunch of posters into one).

_aaron fucked around with this message at 01:05 on Jan 1, 2015

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