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
Optimus Prime Ribs
Jul 25, 2007

Strong Sauce posted:

Do you think those programmers ever wonder, "drat I wish there was an easier way to do this. If only there were some sort of thingy that can hold all these similar items!"

Funny thing is that in AS2 (which that is written in) the _root variable is essentially an array.
He could have written that like this:
code:
success = true;

for (i = 1; i < 36; i++)
{
	if (_root["pic_"+String(i)].hitTest(_root["hit_"+String(i)]) == false)
	{
		success = false;
		break;
	}
}

if (success)
{
	gotoAndStop(6);
}

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



^^^ I'd start with success = false though, much cleaner that way. ^^^

moynar posted:

The latest software scandal in Norway is a pretty big horror.

So at some point in time the Norwegian government decided that the country needed to move parts of the paper mill onto the internet. The result is the monolithic Altinn (literally "everything in") software which was developed by consultants, mostly Accenture/Avanade for about 1000 million NOK. Or about 170 million USD if you will. This handles taxes for all citizens and a lot of other important stuff.

Each year about this time the estimated taxes are released on Altinn, which is a big deal because it tells you if you have to pay extra, have money waiting for you and if you have to do excessive paperwork because someone hosed up in the paper mill when calculating your income.

Last year the system collapsed immediately when the tax returns were published. Afterwards the admins worked out that a single server was responsible for login services which is an horror in it's own right (Norway has 5 millions inhabitants) but this year they promised it would be better. It didn't go down this year, it just switched to serving a static PLEASE WAIT page for most users. And then something wonderous happened. The people responsible turned on caching in a desperate attempt to get it up and running again and suddently everyone who tried to log in got logged on as some random dude from Oslo, showing his tax returns, SSN and other personal information. Cue everything being shut down for a few days, leading to enormous losses in productivity for every single accounting firm and company using Altinn in Norway.

If I hadn't paid for it as a taxpayer I would be laughing pretty hard right now.


Reminds me of every time I hear about all the crap software the government has here in Denmark. I guess it's just a perfect storm of wrong specs and terrible consultants. Has there ever in the history of computing been a success story?

One day I'll start a consulting firm and sell lovely software to governments.

Carthag Tuek fucked around with this message at 20:51 on Mar 23, 2012

Optimus Prime Ribs
Jul 25, 2007

Carthag posted:

^^^ I'd start with success = false though, much cleaner that way. ^^^

I definitely agree with that, but then the for loop would need something like this:
code:
if (_root["pic_"+String(i)].hitTest(_root["hit_"+String(i)]))
{
	success = true;
}
else
{
	success = false;
	break;
}
Which just seems silly to me.
Not that it matters since this is a coding horror no matter how you write it.

qntm
Jun 17, 2009

Carthag posted:

Reminds me of every time I hear about all the crap software the government has here in Denmark. I guess it's just a perfect storm of wrong specs and terrible consultants. Has there ever in the history of computing been a success story?

One day I'll start a consulting firm and sell lovely software to governments.

The tax website in the UK works really well as far as I can tell. Taxes are insanely complicated but it does a much better job than the paper forms of hiding fields which don't need to be filled in, making it impossible to continue if you've omitted critical information, telling you what you've missed, and you can even bounce back and forth in the process and if you change something at step 2 that affects a field you already filled in at step 6 it'll warn you about that too (and even restore what you originally filled in at step 6 when you change it back!). I was actually really pleasantly surprised by the competence on display.

I suppose this is the wrong thread for that, though.

Opinion Haver
Apr 9, 2007

Strong Sauce posted:

Do you think those programmers ever wonder, "drat I wish there was an easier way to do this. If only there were some sort of thingy that can hold all these similar items!"

I had something similar when I worked at company a few years ago. My company was expanding and hired a guy without ever asking me if I wanted to talk to him

Anyways, we don't interact much since his projects aren't the projects I'm working on for the site. But finally, I had to take over for one of his projects and as I'm browsing through the code, I see some code that outputs html like this.

code:
for ($i = 0; $i < $num_fields; $i++) {
  echo "Field " . $i . "<input name='field_" . $i . "'> ";
}
and then to process it
code:
for ($i = 0; $i < $num_fields; $i++) {
  if ($_GET['field_'.$i] == "BLAH") {
    // do stuff
  }
}
:stare:

Needless to say, I ended up fighting constantly with him.

I've never even touched PHP, what's the proper way to do this?

Optimus Prime Ribs
Jul 25, 2007

yaoi prophet posted:

I've never even touched PHP, what's the proper way to do this?

The only horror that I can see is that the input fields are being named field_1, field_2, field_3, field_4, et cetera.
Though doing this:
code:
echo "Field " . $i . "<input name='field_" . $i . "'> ";
Is really redundant since variables are automatically inserted into strings when double quotes are used:
code:
echo "Field $i<input name='field_$i'> ";
There's also no checking being done if the elements even exist in $_GET:
code:
if ($_GET['field_'.$i] == "BLAH")
In the end, as usual, the real horror is PHP.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
If you name the fields "field[]" PHP will automatically turn them into an array for you.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Optimus Prime Ribs posted:

I definitely agree with that, but then the for loop would need something like this:

Which just seems silly to me.
Not that it matters since this is a coding horror no matter how you write it.

Actually I'm not too fond of naming vars "success", I prefer something semantic, it'll also make the code more like sentences.

You could do something like this. Granted, it'll keep counting in all cases, but after the first false, lazy evaluation should keep the rest of the loop from taking too much time.

code:
shouldProceed = true;

for (i = 1; i < 36; i++)
{
	shouldProceed = shouldProceed && _root["pic_"+String(i)].hitTest(_root["hit_"+String(i)]);
}

if (shouldProceed)
{
	gotoAndStop(6);
}

Strong Sauce
Jul 2, 2003

You know I am not really your father.





yaoi prophet posted:

I've never even touched PHP, what's the proper way to do this?

The problem is that you want fields as an array, so there are two ways to accomplish this. Either have the inputs be named, "field[0], field[1], field[2], field[3]" or do it the easier way if you know that $arr[] = "blah" appends a new element to the end of the array you can do this:
code:
for ($i = 0; $i < $num_fields; $i++) {
  echo "Field " . $i . "<input name='field[]'"> ";
}
And it will grab all the inputs with that name and stuff them into an array accessed by $_GET['field']

And the second part is just part of the pain from the first part, but also what Optimus Prime Ribs said. I think PHP only returns a warning if an element you are referencing doesn't exist in an array so you can just surpress it but it's always good to actually check that an element actually exists using array_key_exists.

Strong Sauce fucked around with this message at 21:59 on Mar 23, 2012

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

senrath posted:

Those comments make me wonder if it was auto-generated code.
I'm pretty sure there are IDEs that maintain comments like that automatically. I don't know why anyone thinks it is useful.

That Turkey Story
Mar 30, 2003

Aleksei Vasiliev posted:

I'm pretty sure there are IDEs that maintain comments like that automatically. I don't know why anyone thinks it is useful.

Agreed. The only time I've ever found notation like that to be useful is with nested namespaces. Sometimes I'll be 2 or 3 namespaces deep and close out back one or two for a declaration or specialization or something. In most other cases, blocks are so small that you can easily see exactly what they correspond to, unless you have some gigantic, several hundred line block of code... in which case you should probably split it up anyway.

gonadic io
Feb 16, 2011

>>=
In one of my first year programming courses we lost marks if we didn't comment each of our closing braces. Needless to say I saw a lot of
code:
} // end block

Optimus Prime Ribs
Jul 25, 2007

AlsoD posted:

In one of my first year programming courses we lost marks if we didn't comment each of our closing braces. Needless to say I saw a lot of
code:
} // end block

Wonder what would have happened if you did this:
code:
} //this is a curly brace that is closing a block that I started at least one line above this one, because if I didn't this program wouldn't work and then I would get a zero. :(
Though speaking of stupid requirements in school, one of my professors said we were not allowed to do while(1) or while(true) when a constant loop was required.
We had to create a variable instead:
code:
bool someStupidBool = true;

while (someStupidBool)
{
    // bleh
}
And a different professor would take off marks if we didn't use curly braces with if statements that only had one line in them:
code:
if (someVariable)
    bool gonnaLoseMarks = true;

if (someOtherVariable)
{
    bool gonnaLoseMarks = false;
}
I do not miss college at all.

shrughes
Oct 11, 2008

(call/cc call/cc)
If you had to deal with all the stupid poo poo mistakes students would make, you'd have those rules too.

Optimus Prime Ribs
Jul 25, 2007

shrughes posted:

If you had to deal with all the stupid poo poo mistakes students would make, you'd have those rules too.

That is a fair argument, but I didn't like writing code a way that I wouldn't have normally without being given a reason as to why I should.

Zorro KingOfEngland
May 7, 2008

We asked our contractors to clean up the log files so there wasn't so much junk in it. Their solution? Replace all System.out.println with //System.out.println

The problem with this is a few if statements were written like this:

code:
if(butts > 0)
    System.out.println("The butt is > 0");

butts = performCalculation(butts);
Any time one of these would come up we would get some really weird output because of the comments. So the horror is either replace all, no braces after if statements, or contractors who just don't give a drat.

tef
May 30, 2004

-> some l-system crap ->

moynar posted:

If I hadn't paid for it as a taxpayer I would be laughing pretty hard right now.

If it makes you feel better we're (uk, london) about to roll out new software for ambulance dispatch. The last time people died. It's pretty likely to happen again

http://www.computerworlduk.com/news/public-sector/3346117/london-outsources-999-fire-control-service/
http://en.wikipedia.org/wiki/London_Ambulance_Service#2011_CAD_failure

baquerd
Jul 2, 2007

by FactsAreUseless

Optimus Prime Ribs posted:

And a different professor would take off marks if we didn't use curly braces with if statements that only had one line in them:
code:
if (someVariable)
    bool gonnaLoseMarks = true;

if (someOtherVariable)
{
    bool gonnaLoseMarks = false;
}

I like him, seeing if statements without curly braces makes me angry because it's always an if statement I want to add a line to and then I need to add them anyway. Also it just looks plain wrong when braces are in the language.

That Turkey Story
Mar 30, 2003

baquerd posted:

I like him, seeing if statements without curly braces makes me angry because it's always an if statement I want to add a line to and then I need to add them anyway. Also it just looks plain wrong when braces are in the language.

Sorry, but you are a spergy little baby.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Aleksei Vasiliev posted:

I'm pretty sure there are IDEs that maintain comments like that automatically. I don't know why anyone thinks it is useful.

The most popular Flash decompiler inserts comments like that, and also uses that exact indentation style and unnecessary _root reference, so I'm going to guess that that's where that came from.

DeciusMagnus
Mar 16, 2004

Seven times five
They were livin' creatures
Watch 'em come to life
Right before your eyes
This is relatively minor compared to stuff I've seen in other AMXModX, but indicative of the code you get from the AMXModX community. It's been a while since I've written Pawn, but I'm pretty sure I remember a != operator (considering it's been used multiple times in this plugin). Since this is Pawn, I don't expect this to be optimized away, not that performance is the issue here.

code:
if(id==i)
{
        // Do nothing
}
else
{
        if(is_user_alive(i)&&is_user_alive(id))
        {
                new Float:origin_i[3]
                pev(i,pev_origin,origin_i)
                new Float:origin_id[3]
                pev(id,pev_origin,origin_id)
                if(get_distance_f(origin_i,origin_id)<=650.0)
                {
                        new halfspeed=floatround(float(speed[i])/2.0)
                        new iPlayers[32],iNum
                        get_players(iPlayers,iNum)
                        iNum=iNum*50
                        new luck=random_num(1651-iNum,4200+dist[id]+dist[i]+halfspeed)
                        if(luck>4200)
                        {
                                set_user_health(i,get_user_health(i)+1)
                                if(get_user_health(i)>health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                {
                                        set_user_health(i,health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                }
                        }
                        luck=random_num(1651-iNum,4200+dist[id]+dist[i]+halfspeed)
                        if(luck>4200)
                        {
                                set_user_armor(i,get_user_armor(i)+1)
                                if(get_user_armor(i)>health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                {
                                        set_user_armor(i,health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                }
                        }
                        if(dist[id]>=40)
                        {
                                luck=random_num(0,1000+dist[id])
                                if(luck>1038)
                                {
                                        set_user_health(i,get_user_health(i)+1)
                                        if(get_user_health(i)>health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                        {
                                                set_user_health(i,health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                        }
                                        set_user_armor(i,get_user_armor(i)+1)
                                        if(get_user_armor(i)>health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                        {
                                                set_user_armor(i,health[i]+starthealth+60+dist[id]+medals[i]+halfspeed)
                                        }
                                }
                        }
                }
        }
}

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I don't know if I'd care if that was the only thing 'wrong' with the code.

etcetera08
Sep 11, 2008

That Turkey Story posted:

Sorry, but you are a spergy little baby.

"you have a different preferred style than I do? You are an autistic child."

:rolleyes:

Dicky B
Mar 23, 2004

No, feeling strongly one way or another about it is retarded.

baquerd
Jul 2, 2007

by FactsAreUseless

Dicky B posted:

No, feeling strongly one way or another about it is retarded.

I like consistency in my code, I don't think that's a crime. Anyways, I let my autoformatter do the sperging for me.

That Turkey Story
Mar 30, 2003

Dicky B posted:

No, feeling strongly one way or another about it is retarded.

Exactly this. If you are sperging out over little subjective stuff then I don't know what to say.

baquerd
Jul 2, 2007

by FactsAreUseless

That Turkey Story posted:

Exactly this. If you are sperging out over little subjective stuff then I don't know what to say.

Come on, I bet you have at least one little thing that doesn't effect functionality that you greater prefer. Braces style? White space? Variable or function name convention?

I'd go as far to say that if you don't have something like that you're weird.

That Turkey Story
Mar 30, 2003

baquerd posted:

Come on, I bet you have at least one little thing that doesn't effect functionality that you greater prefer. Braces style? White space? Variable or function name convention?

I'd go as far to say that if you don't have something like that you're weird.

Sure I'm consistent in my personal work with my preferred style, but I'm not going to get angry when I have to work with different coding conventions.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
An excerpt from Ledorf's Opus Number 4
code:
<?php
    if ( ($selection[$i]['id'] == $payment) || ($n == 1) ) {
      echo '                  <tr id="defaultSelected" class="moduleRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
    } else {
      echo '                  <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
    }
?>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td class="main" colspan="3"><b><?php echo $selection[$i]['module']; ?></b></td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td class="main" align="right">
<?php
    if (sizeof($selection) > 1) {
      echo tep_draw_radio_field('payment', $selection[$i]['id']);
    } else {
      echo tep_draw_hidden_field('payment', $selection[$i]['id']);
    }
?>
                    </td>
                    
                  </tr>
<?php
    if (isset($selection[$i]['error'])) {
?>
                  <tr>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td class="main" colspan="4"><?php echo $selection[$i]['error']; ?></td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
<?php
    } elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
?>
                  <tr>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td colspan="4"><table border="0" cellspacing="0" cellpadding="2">
<?php
      for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
?>
                      <tr>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main"><?php echo $selection[$i]['fields'][$j]['title']; ?></td>
                        <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main"><?php echo $selection[$i]['fields'][$j]['field']; ?></td>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                      </tr>
<?php
      }
?>
                    </table></td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
<?php
    }
?>
                </table></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>

Look Around You
Jan 19, 2009

baquerd posted:

Come on, I bet you have at least one little thing that doesn't effect functionality that you greater prefer. Braces style? White space? Variable or function name convention?

I'd go as far to say that if you don't have something like that you're weird.

I have personal preferences, but if I'm working with code I didn't write, I'll follow their convention.

Basically I don't care all that much as long as it's consistant.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Look Around You posted:

I have personal preferences, but if I'm working with code I didn't write, I'll follow their convention.

Basically I don't care all that much as long as it's consistant.

I just install StyleCop and do what it tells me to do. Get everyone else to use it, no more formatting issues.

Optimus Prime Ribs
Jul 25, 2007

baquerd posted:

Come on, I bet you have at least one little thing that doesn't effect functionality that you greater prefer. Braces style? White space? Variable or function name convention?

I'd go as far to say that if you don't have something like that you're weird.

Everyone has their preferred way to write code.
But why should I be penalised for not conforming to the professor's preference?

Plorkyeran
Mar 22, 2007

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

Optimus Prime Ribs posted:

Everyone has their preferred way to write code.
But why should I be penalised for not conforming to the professor's preference?

If you let them, 90% of the students will turn in something that is entirely unreadable and has to be reformatted before grading.

If you penalize only completely retarded formatting and accept anything vaguely sane, you'll waste a bunch of time arguing with students who think that zero whitespace anywhere is ideal.

If you set a single required formatting standard and take points off for anything else, there is no ambiguity and when students whine about losing points for failing to follow simple instructions you can just tell them to actually read the assignment next time.

pigdog
Apr 23, 2004

by Smythe

Optimus Prime Ribs posted:

Everyone has their preferred way to write code.
But why should I be penalised for not conforming to the professor's preference?

It's not the biggest deal in the world, but the professor does have a point. You or some other dev might comment out or flat out delete the if statement, while forgetting about the bool gonnaLoseMarks = true;.
code:
// if (someVariable)
    bool gonnaLoseMarks = true;

if (someOtherVariable)
{
    bool gonnaLoseMarks = false;
}
The code would still be valid and compile, so it could introduce a hard-to-notice bug. If the curvy braces weren't used in such dumb style and start at the same line as if, that would make it harder to accidentally break it.

edit: Actually, depending on language it could make an even bigger mess if bool gonnaLoseMarks = true; was commented out instead. Something like

code:
if (someVariable)
    // doSomethingMeaningless();

doReallyImportantStuff();
The behavior of the code changes completely.

pigdog fucked around with this message at 22:04 on Mar 24, 2012

Dicky B
Mar 23, 2004

I've never understood this argument because:
- If you understand the syntax of the language then you will never make that mistake.
- If you don't understand the syntax of the language then making that mistake and learning from it is beneficial

feedmegin
Jul 30, 2008

Optimus Prime Ribs posted:

Everyone has their preferred way to write code.
But why should I be penalised for not conforming to the professor's preference?

In the real world, whether open source or commercial, you'll generally be expected to conform to the existing style of any large body of code to which you contribute. Doing otherwise is aggressively antisocial. I suggest you get used to it.

raminasi
Jan 25, 2005

a last drink with no ice

Dicky B posted:

I've never understood this argument because:
- If you understand the syntax of the language then you will never make that mistake.
- If you don't understand the syntax of the language then making that mistake and learning from it is beneficial

It's about making it more difficult to accidentally gently caress up. And introducing a bug that doesn't get noticed immediately may be eventually "beneficial" from a "learning" perspective, but code is usually supposed to actually do something correctly before it's supposed to be a teaching tool.

Molog
Mar 4, 2004
Title text
Coding standards really help reading other people's code if you are working in a large team. Less time lost figuring out where this guy is putting his members.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
It's way too easy to convert

code:
if (someVariable)
    something = true;
into

code:
if (someVariable)
    something = true;
    somethingElse = true;
and then waste a long time trying to find out why your code doesn't work, or, even worse, you don't notice the bug at all and it will crash and burn weeks from now.

Braces are good, even for single statements.

Adbot
ADBOT LOVES YOU

Optimus Prime Ribs
Jul 25, 2007

feedmegin posted:

In the real world, whether open source or commercial, you'll generally be expected to conform to the existing style of any large body of code to which you contribute. Doing otherwise is aggressively antisocial. I suggest you get used to it.

Admittedly I had not thought of that perspective when I made my post, but I don't think my frustration over the situation is entirely unreasonable.
For what it's worth if I am writing code for a project that is not entirely my own I completely conform to the style of said project.

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