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
Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Ratty posted:

At my old job some one once wrote:

code:
  for(int i = 1;i < 3; i++){

    if(i == 1){
      
      //the code did something here
       
    }


    if(i == 2){
      
      //the code did something here
       
    }

  }
The guy that wrote it had a good sense of humour so we printed it out and started a wall of shame.

-- Ratty

He was SO close to independently developing the FOR-CASE paradigm

-- Ratty

Adbot
ADBOT LOVES YOU

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

pokeyman posted:

Found this in the PHP manual. It's like the guy knew he wanted some kind of conditional execution, but forgot about the "if" keyword.

code:
switch (TRUE)
{
 case ($phlen < 7):
   $ext = $ph;
   break;
 case ($phlen == 7):
   sscanf($ph, "%3s%4s", $pfx, $exc);
   break;
 case ($phlen > 7 AND $phlen < 10):
   sscanf($ph, "%3s%4s%s", $pfx, $exc, $ext);
   break;
 case ($phlen == 10):
   sscanf($ph, "%3s%3s%4s", $area, $pfx, $exc);
   break;
 case ($phlen == 11):
   sscanf($ph, "%1s%3s%3s%4s", $cty, $area, $pfx, $exc);
   break;
 case ($phlen > 11):
   sscanf($ph, "%1s%3s%3s%4s%s", $cty, $area, $pfx, $exc, $ext);
   break;
}
:aaaaa:
Sometimes if{} else if {} just isn't elegant enough.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

standard posted:

I found this in one of our apps this week.
code:

for (int i = 0; i < collection.getDetails().size(); i++) { 
       SomeObject object = (SomeObject)collection.getDetails().elementAt(i);
       count++; 
} 

if (count < 1 || count> 10) { 
       isValid = false; 
} 
what the hell
Maybe they don't trust the collection.getDetails().size() method?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

chocojosh posted:

Stack: I tend to code regularly like this:

code:
if(!isset($bravo))
   $blah = here($something)
elseif(isset($charlie)) 
   $blah = here($charlie)
else
   $blah = nothere();
My logic is I hate wasting an entire line just to show a brace.
Unless you're using an 80 line monitor for some terminal from the '80s, there is no such thing as "wasting a line."
That being said, not putting in braces for single line conditionals is probably OK, though I almost always put in braces so that I'm never caught doing something like
code:
if(!isset($bravo))
   $blah = here($something)
elseif(isset($charlie)) 
   $blah = here($charlie)
else
   $blah = nothere();
   somethingelse();
when I change my mind later.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Randomosity posted:

I want to kill the people whose code I now maintain. And wtf is an 'appaplexy'
I would assume it's a misspelled apoplexy.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

ashgromnies posted:

Just ran across this while adding on some functionality to a project...

code:
my $id        = $req->param($unique_id);
That $id is an identifier given to us by one of our third-party integration partners. We also have different identifiers for users on our side and we map the two to eachother.

So that line grabs the user's third-party ID from the CGI request. Nothing weird, but then 20 lines below that in the same method...

It reassigns $id to $user->get_user_id() which is OUR identifier for users - and it called it on an instance of $user which it reassigns in the next line with the $id it just retrieved - what the gently caress I'm going to cry.
I don't know much Perl, but doesn't the my in front of $id and $user hide those variables within the scope of the if statement? So if you were commenting this, it might go something like:
code:
if ($id) { #If the 3rd party id is set
           my $id   = $user->get_user_id(); #get our id for the current user, and then hide the 3rd party id so we don't have to worry about it
           my $user = $self->get_user( $id, 1 );#get a copy of the current user
Still disgusting, but perhaps "sensical?"

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

willemw posted:

Today I had to do some maintenance on the administration part on one of our websites. You can link some stuff to one of 15 different locations.

:psypop:
So is this the mystical unrolled for-case?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Munkeymon posted:

Just kill the guy who turned that poo poo in and maybe his job could be filled by someone who doesn't leave the # out of C#.
I think he's programing C♭ instead.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Lone_Strider posted:

Holy poo poo, this is like a tell-tale mark for crappy devs. I bet when he was called on it he said "well I'm just making sure"
I'd say it's something more like "well that's how they did it in the on-line tutorial I more-or-less copied that code snippet from wholesale."

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
The only one I see that's worth crying about is the willy-nilly truncation of the XML. I'd say that's a great way to magically create malformed XML. Maybe the fact that he's storing XML in a text field of some sort instead of an XML field, but I guess this is the "coding horrors" thread, not the "critique my dba by looking at 10 lines of application code" thread.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Zombywuf posted:

On an SQL flavoured note, something I saw recently. With a table with an id and sub id, where the pair id, sub_id is unique, and sub_id is guaranteed to be 1, 2, etc... for each id.
code:
WITH cte AS (
  SELECT
     ...
     row_number() OVER(
       PARTITION BY id
       ORDER BY sub_id
     ) AS rownum
  FROM
    ...
) SELECT
  *
FROM
  cte
WHERE
  rownum = 1
What's the horror here? I suppose if you can 100% guarantee that records with sub_id = 1 will never, ever, ever "go missing" then it's a bit redundant.

Or is the horror that he named that column "rownum" since that could possibly be a little bit misleading?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

chocojosh posted:

wrok posted:

code:
    foreach (string item in _ptAttributeDic.Keys)
    {
        string val = _ptAttributeDic[item];
        switch (item.ToLower())
        {
            case "mail":
                if (string.IsNullOrEmpty(base._email))
                    base._email = val;
                break;
            
            case "facsimiletelephonenumber":
                base._faxNum = val;
                break;
            
            case "telephonenumber":
                base._phoneNumber = val;
                break;
        }
    }
So this is such a bad varation of the for-switch that once it matches either "mail", "facsimiletelephonenumber", or "telephonenumber" it's going to exit the loop.

Unless the author meant to only initialize one of them, but then it would just be much easier to use

if(_ptAttributeDic.Contains("X"))
base._X = _ptAttributeDic["X"];
...
The break; in this example only exits the switch statement; it doesn't exit the loop. The one "benefit" to this particular foreach-case is that it replaces checking for the existence of each key, but then of course it does so at the cost of looping through each key of the dictionary. I suppose if the dictionary in question was only going to contain at most the three keys used here it might even count as a clever trick, but other than that it's a pretty standard example of the for-case paradigm.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

rt4 posted:

Professors: fine for theory, always wrong on code.
Well, in this case I find it far more likely that the dude misunderstood what the professor said, or the professor misunderstood what was being asked.

But I guess that's less funny, so forget I said anything. CS Professors = poo poo.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Broken Knees Club posted:

So why is this Epic thing treated like the bubonic plague?

http://thedailywtf.com/Articles/A_Case_of_the_MUMPS.aspx

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

clockwork automaton posted:

An entire class where the only comment is

code:
//?
Thanks guys. That comment is TOTALLY useful.
Sometimes comments are useful for what they tell you about the commenter.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

ColdPie posted:

So you'd argue that the library is small enough to just be memorized? I guess I don't disagree. It just seems harsh to me to call it a horror when someone isn't familiar with non-obvious functions like atan2 and fmod.
No, he'd argue that the library is small enough that one could search through the documentation. Hence his use of the term "use documentation" not "memorize documentation".

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

MrMoo posted:

C99 is ANSI C, along with C90 and C89. What am I missing?

http://en.wikipedia.org/wiki/ANSI_C

quote:

C89
[snip]
This version of the language is often referred to as "ANSI C", or sometimes "C89" (to distinguish it from C99).
[snip]
C99
In March 2000, ANSI adopted the ISO/IEC 9899:1999 standard. This standard is commonly referred to as C99
So C99 has been adopted by ANSI as the current standard for the C Programming language, but it is not "ANSI C".

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Flobbster posted:

I mean that's cool and all, but I chuckled at which of the words they deemed important enough to have special cases, like "buffalo" and "tomato", but "potato" gets left out.
Dan Quayle account found.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

shrughes posted:

Inheritance

"To an external observer, inheritance of T from U is indistinguishable from the presence of a conversion function from T to U."

- Confucious

I was simply saying that from an external observer inheritance of T from U is indistinguishable from the presence of a conversion function from T to U.
This is only true of inheritance without polymorphism.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

shrughes posted:

:words:
So inheritance is just an implicit cast assuming you've designed your types to behave as if they used inheritance.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

baquerd posted:

:words:
The problem was that you kept using the word variable wrong.
code:
int i = 0;
Object foo = new Object();
Object bar;
i, foo, and bar are variables. Variables are not objects. Variables have values. The value of i is 1. The value of foo is a reference to an object with type Object. foo is not the object that we created, it is a variable whose value is a reference to that object. bar has no value, since it is uninitialized, but it can hold a value which is a reference to an object of type Object. It is not an uninitialized object, since it is not an object. If the next line of code was this bar = foo;, then both foo and bar would be variables that contain references to the same (unnamed) object created above.

Jethro fucked around with this message at 21:13 on Sep 26, 2011

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
Except, unless I'm misunderstanding what he meant by "the version of binary search that I wrote for the JDK," the binary search in the Java standard library contained this bug. Furthermore, unless Joshua Bloch is uncommonly stupid for a developer of standard libraries, it is likely that other standard libraries with a binary search had this bug.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

bobthecheese posted:

Speaking of poorly named variables...

code:
SELECT ...
FROM (SELECT ... 
     FROM ... 
     WHERE ...
     GROUP BY ... 
  UNION ALL 
     SELECT ...  
     FROM ...
     WHERE ...
     GROUP BY ...) AS tblFoo 
GROUP BY tblFoo.hour;
It's not a table, the naming convention in the database is to POST-fix 'Tbl' (I have no loving idea why), and 'Foo' describes precisely nothing about the purpose or nature of the data.

Fuckers.
I'm not seeing too much that's objectionable here. When you're joining a bunch of tables together it's nice to have reasonable aliases so you don't have to keep asking yourself "which table is A? Which table is AA?", but if tblFoo isn't being joined to anything, it's not like you have to go hunting for the definition. Heck, probably the only reason it even has a name at all is because T-SQL requires them for derived tables.

As for putting Tbl at the end of table names, sometimes it's nice to know when you're working directly with a table or with a view. It's not like you're going to run into the problem of Hungarian notation where the name is out of sync with the type.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Wheany posted:

Okay, so you're using Lua. These problems are somewhat understandable on a cross-platform language.

But loving Windows Poweshell. How in the gently caress can executing programs from under Program Files be so loving difficult in a shell designed for Windows.

I was tearing my hair out with the equivalent of "c:\Program Files\ImageMagick-6.8.2-Q16\convert.exe" "C:\Users\My Username\Pictures\some file with spaces 1.png" -resize 50% "some file with spaces 1.gif"

Where the number in the file name came from a loop index variable.
I've been using Powershell pretty heavily for about a year now. I have no idea how to call an executable that isn't in the current path, so when I have to do so, I just give up and Set-Alias.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

EssOEss posted:

The same way as you would normally? Or have you found some problematic scenario I have not discovered yet in my mere three months?

code:
PS C:\Users\essoess> c:\tee\tf.cmd help
Team Explorer Everywhere Command Line Client (version 11.0.0.201207250346)

 Available commands and their options:
Well, the problem scenario occurrs when running an executable with a space in the path. I have just now done some research and discovered that the call operator "&" isn't just for running scripts.

code:
PS C:\Users\Jethro> C:\Program Files\Something\program.exe
The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:11
+ C:\Program <<<<  Files\Something\program.exe
    + CategoryInfo          : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Jethro> "C:\Program Files\Something\program.exe"
C:\Program Files\Something\program.exe
PS C:\Users\Jethro> &"C:\Program Files\Something\program.exe"
I am a program that does a thing
So I feel a bit silly. The point still stands that Powershell can be a bit obtuse, even if the design reasons behind that obtuseness often make sense. But I guess this thread is for alternating between feeling silly and feeling smugly superior.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

JetsGuy posted:

Anyway, after a quick look at the git website, it seems like it's a standalone version control program. Is this true? Is it any good?
All your questions can be answered here. Here's a summary: "git is awesome, git is good, please use git like all coders should. mercurial is cool too."

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Steve French posted:

Which would be awfully nice for the compiler to know, but it doesn't.
Whether or a pointer points to an element of an array is something determined at runtime based on what the pointer actually points to. The fact that the compiler doesn't (and can't) know whether the pointer points to an element of an array is why section 6.5.6 is written how it is, and it's also why the behavior in question is undefined, as opposed to an error.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Deus Rex posted:

Is Postgres the only SQL DB that can do indexes on expressions? I wasn't that surprised to see MySQL was lacking them, but SQL Server is supposed to be good :(
Oracle has Function-Based Indexes

The closest equivalent in SQL Sever is to create a computed column on the table and index that.

Plorkyeran posted:

You can't index the expression directly, but you can create a view with that expression and then put an index on that.
Indexed views in SQL Server are equivalent to materialized views in Oracle or Postgres, so there's a bit more to it than just slapping an index on any old view.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

chippy posted:

I'm just gonna leave this here and let you pick your own horrors

code:
    'snip
Making fun of student projects just isn't fair.

chippy posted:

And this is my first real dev job.
Oh... I'm so sorry.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Nipplebox posted:

Many are afraid of doing something damaging by accident.
This is, from my limited experience on the helpdesk back in the day, one of the biggest things that prevented people from ever getting better at using their computers.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
radium was a great source for TFC maps back in the day.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
If no one will ever see what I'm prototyping, I usually go with butts, lol, and what.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

zergstain posted:

I always thought the reason for mocks was you want to test A, which uses C, but C hasn't been implemented yet.
Or C is your 500 GB database. Or you want to see that A responds properly when C fails in certain ways, so you write a mock C that just behaves like a broken C. Or...

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Bognar posted:

No need to be a dick about it. I'm well aware of the Parse overloads, but I still don't understand why Parse(string) defaults to converting to local time instead of just setting Kind to Utc.
If you aren't being careful about timezones and whatnot, then you probably don't care about them, so you might as well just leave everything in local time.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

canis minor posted:

What I've done is copied the entire column to notepad and back in - since copy to clipboard copies the displayed value, and not the "actual" value, thus dropping the formatting and preserving what I want, but still - how is that sane?
The vast majority of the time users will enter data into a spreadsheet as a string representation, but then they want it to be treated as data, not a string. So it makes perfect sense to take strings that look like numbers, dates, or times and automatically convert them to numbers, dates, or times respectively. If you want something that looks like a number, date, or time to stay a string, put a ' in front of it.

Maybe it might make sense to have the CONCATENATE function automatically use the formatting of the source column when it outputs the string, but if you're already doing string manipulation with functions, just use more functions to make sure the output is exactly what you want.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

canis minor posted:

Still, as an inexperienced user with Excel this behaviour strikes me as absurd - if I saw "0.416667" in the top bar, but "10:00:00" in the cell, I'd know the matter is with formatting of a specific value. If I see 10:00:00 in both I'm thinking - this is definitely a string. And I know for sure the person that created the sheet didn't apply time formatting to this column, so why should the app in this case try to fix the data for the user?
If the word "string" means anything to you other than twisted plant or synthetic fibers you are probably more advanced than most Excel users. There are definitely some times when Excel's magic data type conversion causes problems (see the examples above). I see it all the time at my company (lots of items with identifiers like 111E-00 that Excel changes to 1.11E+02). But ultimately spreadsheets are about manipulating data, so Excel has to take what users type and automatically turn it into data without much effort on the part of non-technical users to be of any value. If a user couldn't type 1,000 in one cell and 1500 in another and then add them together without having to do anything else, or have 10:00 and 9:00 sort properly, Excel wouldn't be used everywhere. So maybe it is a bad thing :v:

quote:

edit: to clarify - if I open a blank spreadsheet, put in first cell: "10:00:00", second cell "=CONCATENATE("Time is ";A1)" I don't expect it to output: "Time is 0.416667" and I consider it weird that that's the standard behavior.
The magic has to stop somewhere, and a function that depends on you knowing what string means is as good a place as any and probably better than most.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

canis minor posted:

That are great points you're making - especially about sorting "9:00" and "10:00"; still, I'd say I prefer Google's approach - it is, what it is, until user makes a conscious decision about changing it

Where does google do that?

Only registered members can see post attachments!

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
e. no wait, I misread you, you're more or less saying what I said.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Meat Beat Agent posted:

I assume they meant the smallest undefined program that always finishes normally.
Maybe shortest "non-trivial" program.

Adbot
ADBOT LOVES YOU

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
If you try to represent the number 1.0000000001 as a float32, it will be truncated to 1.0. If you then use that 1.0 to do perform operations with a float64, you will get a different answer than you would had you put 1.0000000001 in a float64 to begin with. If the result is a float64, you may think you've got the precision of a float64 when your precision is really only that of the float32 you started with, and any digits outside of that are spurious.

That said, the solution to a programmer making such a mistake is still probably not to silently downcast to float32. Silently limiting the range of possible results and throwing away digits is not a good way to handle the fact that some of those digits might not be correct in some rare circumstances. And it's definitely always wrong when we're talking about integer types.

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