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
Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Jabor posted:

code:
var downType=$('#rdoPercentage').val() == "pct" ? "pct": "fixed";
Wouldn't this always be "pct", or am I just not getting jquery?

Oh duh; this is why I prefer to use the DOM:

code:
> f = document.forms['track']
// => <form name="track" id="track" action="/live/form.rvt">…</form>
> f['ident']
// => <input name="ident" id="ident" type="text" value="DAL64" title="e.g. N123AB">
> f['ident'].value
// => "DAL64"

Cocoa Crispies fucked around with this message at 05:40 on Sep 3, 2011

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

BonzoESC posted:

Oh duh; this is why I prefer to use the DOM:

code:
> f = document.forms['track']
// => <form name="track" id="track" action="/live/form.rvt">…</form>
> f['ident']
// => <input name="ident" id="ident" type="text" value="DAL64" title="e.g. N123AB">
> f['ident'].value
// => "DAL64"

Except your way doesn't work either. You are just getting the value of a single radio input by ID just like the other example:

http://jsfiddle.net/WxThT/

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe
Was supposed to do 10-12 hours of work on it today. Woke up at 2.30pm, its now 5pm, and i really can't be arsed.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
var hasChanged = false;

hasChanged |= module1.hasChanged() |
module2.hasChanged() |
module3.hasChanged() |
module4.hasChanged();

if(hasChanged){
module1.reload();
module2.reload();
module3.reload();
module4.reload();
}



Spoilers: Bitwise vs logical OR.

Not a great horror, but if you are going to reload every module anyway, you might as well make use of short circuiting.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Except knowing this code, at least one of those hasChanged() methods has some side effects that short circuiting would break.

qntm
Jun 17, 2009
That or it's to defeat timing attacks of some kind. But realistically, no, the other thing.

TasteMyHouse
Dec 21, 2006
thanks, whoever worked on this project before me:

code:
    if (input == 0)
return;
this is immediately followed by a chain of "else if(input == 1)" statements going all the way up to 16. Never heard of a switch statement?

There's also gotos.

corgski
Feb 6, 2007

Silly goose, you're here forever.

gotos aren't evil and gently caress the guy who said they were. The only problem with them is when inexperienced programmers shovel them in every possible fragment of code, making reading that code look like you're watching a vertical tennis match.

if...then...else combined with gotos were your first exception handlers. :colbert:

TasteMyHouse
Dec 21, 2006

thelightguy posted:

gotos aren't evil and gently caress the guy who said they were. The only problem with them is when inexperienced programmers shovel them in every possible fragment of code, making reading that code look like you're watching a vertical tennis match.

if...then...else combined with gotos were your first exception handlers. :colbert:

gently caress Dijkstra? Okay...

No Safe Word
Feb 26, 2005

Dijkstra never explicitly said Gotos were "evil" and in fact, the letter that was published as an article wasn't even originally titled "Go To Statement Considered Harmful" it was just "A Case against the GO TO Statement." (which was later retitled upon article submission) And people who slavishly hold everything in that letter/article to be gospel are silly anyway. Dijkstra was right about a lot of things but the statement

EWD posted:

the go to statement should be abolished from all "higher level" programming languages (i.e. everything except -— perhaps -- plain machine code)
is a teensy bit fanatical

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Additionally if you actually read the paper quite a few of his arguments are specifically against FORTRAN-style line numbered GOTOs and not the textual labels found in modern languages and halfway decent assemblers.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
and really the paper is just an argument in favor of structured programming

TasteMyHouse
Dec 21, 2006
these are kind of dumb gotos, but really my primary horror was the reverse indentation.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

TasteMyHouse posted:

these are kind of dumb gotos, but really my primary horror was the reverse indentation.

Speaking of, and here's an opportunity to ask, I've seen code that aligns all preprocessor directives to the left no matter what. So you get stuff like

code:
            hurtyFlurtySchnipp();
#if DEBUG
            log("sup");
#endif
            etCetera();
I've always assumed it's just lovely style, but it occurs to me that maybe there's some technical reason for it, like gcc's old preprocessor used to ignore any hashes not in column 1 or something. Am I just excusing lovely style?

tractor fanatic
Sep 9, 2005

Pillbug
I thought preprocessor tokens couldn't be indented, but apparently that hasn't been true since before I was born.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

pokeyman posted:

Speaking of, and here's an opportunity to ask, I've seen code that aligns all preprocessor directives to the left no matter what. So you get stuff like

code:
            hurtyFlurtySchnipp();
#if DEBUG
            log("sup");
#endif
            etCetera();
I've always assumed it's just lovely style, but it occurs to me that maybe there's some technical reason for it, like gcc's old preprocessor used to ignore any hashes not in column 1 or something. Am I just excusing lovely style?

It's probably because preprocessor tokens are "special," since they're more about the implementation of the software than the design of it.

Hughlander
May 11, 2005

pokeyman posted:

Speaking of, and here's an opportunity to ask, I've seen code that aligns all preprocessor directives to the left no matter what. So you get stuff like

code:
            hurtyFlurtySchnipp();
#if DEBUG
            log("sup");
#endif
            etCetera();
I've always assumed it's just lovely style, but it occurs to me that maybe there's some technical reason for it, like gcc's old preprocessor used to ignore any hashes not in column 1 or something. Am I just excusing lovely style?

I know our latest coding standard at work calls for that block to be either:
code:
            hurtyFlurtySchnipp();
#           if defined(DEBUG)
            {
                  log("sup");
            }
#           endif
            etCetera();
or

code:
            hurtyFlurtySchnipp();
            #if defined(DEBUG)
            {
                  log("sup");
            }
            #endif
            etCetera();
depending on preference of the coder.

Impotence
Nov 8, 2010
Lipstick Apathy

Wheany posted:

var hasChanged = false;

hasChanged |= module1.hasChanged() |
module2.hasChanged() |
module3.hasChanged() |
module4.hasChanged();

if(hasChanged){
module1.reload();
module2.reload();
module3.reload();
module4.reload();
}



Spoilers: Bitwise vs logical OR.

Not a great horror, but if you are going to reload every module anyway, you might as well make use of short circuiting.

Why not just use hasChanged && (module1.reload(), module2.reload(), module3.reload(), module4.reload());

(assuming this is js)

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Biowarfare posted:

Why not just use hasChanged && (module1.reload(), module2.reload(), module3.reload(), module4.reload());

(assuming this is js)

Because being cute with short-circuiting is way worse than using an if statement.

tef
May 30, 2004

-> some l-system crap ->

thelightguy posted:

gotos aren't evil and gently caress the guy who said they were. The only problem with them is when inexperienced programmers shovel them in every possible fragment of code, making reading that code look like you're watching a vertical tennis match.

if...then...else combined with gotos were your first exception handlers. :colbert:

the guy who wrote about the use of gotos has contributed more to programming than you ever will in your lifetime. :3:

corgski
Feb 6, 2007

Silly goose, you're here forever.

tef posted:

the guy who wrote about the use of gotos has contributed more to programming than you ever will in your lifetime. :3:

I know, but that doesn't mean he wasn't wrong about gotos.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I don't think he was wrong, I just think that people are stupid and sensationalized his statements to the extreme.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

eh. I think it's people taking it to extremes on either side. I haven't really, legitimately, needed to use a GOTO since my Atari BASIC days. Does that mean they are verboten and should never be used? Does that mean they are awesome and should always be used? Or does it mean that a guy wrote an article, which at the time, a lot of people were abusing GOTO and it pissed him off.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Everything I've ever read by Dijkstra is hyperbolic, and it's probably because he just wants people to think critically about the issues he brings up. Some people take him at face value without noticing this and either leap to agreeing with him because he's Dijkstra or just as rashly conclude he's an rear end in a top hat who doesn't know what he's talking about. It's food for thought, not proclamations from on high.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

thelightguy posted:

I know, but that doesn't mean he wasn't wrong about gotos.
He wasn't wrong, you're just reading it from the wrong context.

At the time, GOTO was used for *everything*. Every single branch was a GOTO, and most languages did not have the concept of a loop or conditional.

He advocated that the constructs of IF, WHILE, etc, should be used in preference to GOTO. He didn't claim that all GOTOs were bad, just that languages of the time should be given features that relieved the programmer from having to think about manual branch management.

He was so thoroughly correct that today, computer science undergrads claim he was wrong about GOTO because they can't even contemplate a world without structured programming.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I just wrote a Fortran compiler for 'fun'. Here is a nontrivial program written in a language where the only meaningful flow control mechanism is a numbered goto. A language in which variable names cannot exceed two characters long and integral types must start with i, j, k, l, m or n. A language without facilities for named constants or procedure definitions.

Read this horrible thing and ponder the fact that I'm not intentionally obfuscating my source- this is what programming used to look like.

OddObserver
Apr 3, 2009

Internet Janitor posted:

I just wrote a Fortran compiler for 'fun'. Here is a nontrivial program written in a language where the only meaningful flow control mechanism is a numbered goto. A language in which variable names cannot exceed two characters long and integral types must start with i, j, k, l, m or n. A language without facilities for named constants or procedure definitions.

Read this horrible thing and ponder the fact that I'm not intentionally obfuscating my source- this is what programming used to look like.

Why are you using > and not .gt., etc.? Softy.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Biowarfare posted:

Why not just use hasChanged && (module1.reload(), module2.reload(), module3.reload(), module4.reload());

(assuming this is js)

Why not use hasChanged ? (module1.reload(), module2.reload(), module3.reload(), module4.reload()):0;

Hey, it works, so why not!

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

OddObserver posted:

Why are you using > and not .gt., etc.? Softy.

I based my implementation on this document, which does not indicate the use of stropped keywords or symbols. I thought that was mainly an ALGOL thing, anyway.

OddObserver
Apr 3, 2009

Internet Janitor posted:

I based my implementation on this document, which does not indicate the use of stropped keywords or symbols. I thought that was mainly an ALGOL thing, anyway.

That thing is pretty awesome, thanks for the link (it's always fun to read those early document). As for .gt., etc.... well, I am pretty sure at least Fortran 77 required those:
http://www.fortran.com/F77_std/rjcnf0001-sh-6.html#sh-6.3.1
.. and looking at WP articles on early Fortran dialects, seem likes they pretty much dropped the conditional feature in favor of a simpler version...

Edit: or see Fortran 66: ftp://ftp.nag.co.uk/sc22wg5/ARCHIVE/Fortran66.pdf

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

pokeyman posted:

Speaking of, and here's an opportunity to ask, I've seen code that aligns all preprocessor directives to the left no matter what. So you get stuff like

code:
            hurtyFlurtySchnipp();
#if DEBUG
            log("sup");
#endif
            etCetera();
I've always assumed it's just lovely style, but it occurs to me that maybe there's some technical reason for it, like gcc's old preprocessor used to ignore any hashes not in column 1 or something. Am I just excusing lovely style?

I used to do it because macros don't obey scoping rules and standard code formatting has indentation giving hints to the different scopes.
As of now though I do it like that out of habit.

Zombywuf
Mar 29, 2008

Edison was a dick posted:

I used to do it because macros don't obey scoping rules and standard code formatting has indentation giving hints to the different scopes.
As of now though I do it like that out of habit.

Preprocessor stuff should look ugly because it is ugly. If you want it to look not ugly make it less so, i.e.:
code:
#ifndef NDEBUG
#define log(s) fputs((s), stderr)
#else
#define log(s) do {} while (0)
#endif
That way you can safely pretend you're using a function instead of littering compilation instructions all over your code.

tef
May 30, 2004

-> some l-system crap ->

thelightguy posted:

I know, but that doesn't mean he wasn't wrong about gotos.

He was pretty right about gotos. You use If and while and for, right? You wouldn't be using gotos for them? Dijkstras point was that goto is a form of unstructured programming and we should be using structured programming constructs.

This was around the time where getting programmers to use subroutines was considered a challenge.

Janin posted:

He was so thoroughly correct that today, computer science undergrads claim he was wrong about GOTO because they can't even contemplate a world without structured programming.

Agreeing with Janin here. People take if, while, and for for granted that the context of the argument is lost.

A similar thing happens with BASIC. At the time, basic had 26 variables (A-Z), no structured programming and a lot of goto. The only way to write code was spaghetti. Basic at the time was closer to an assembly language (in terms of managing registers and control flow) than more high level language people know today as BASIC. But lo and behold 'basic cripples the mind' is read as if he was complaining about a modern variant.


Internet Janitor posted:

Everything I've ever read by Dijkstra is hyperbolic

this means you've probably read two of this things - 'how do we tell truths that might hurt' and 'gotos considered harmful', and of those you haven't read the first closely. ewd wrote a *lot* of things, and you're judging them by a subset.


I don't think anyone on something awful can call out dijkstra for being a little hyperbolic :3:



DIJKSTRA WAS RIGHT.

tef
May 30, 2004

-> some l-system crap ->

Janin posted:

He was so thoroughly correct that today, computer science undergrads claim he was wrong about GOTO because they can't even contemplate a world without structured programming.

undergrads seem to be full of opinons without context :(

TasteMyHouse
Dec 21, 2006
I sighed aloud

code:
lval = RegisterRead(hDevice->hRegister, someOffset);
handle->someBool = (lval & SOME_MASK) ? true : false;
some names were obfuscated -- but "lval" is original.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

tef posted:

DIJKSTRA WAS RIGHT.

Was

(ha ha, only serious)

e: He probably forgot more about programming than I will ever learn, but I don't dare to use gotos even when they make sense because I'm afraid of my coworkers preaching the holy gospel of Dijkstra during code inspection.

Wheany fucked around with this message at 20:06 on Sep 7, 2011

BigRedDot
Mar 6, 2008

Amusing anecdote: I took class taught by Dijkstra when I was an undergrad. He didn't actually have a computer in his office, and all of his notes were handwritten (impeccably).

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

TasteMyHouse posted:

I sighed aloud
some names were obfuscated -- but "lval" is original.
Haha, it's the mutant cousin of retval.

NotShadowStar
Sep 20, 2000
I use retval a lot. I am a bad programmer.
Actually I generally do that in terribad languages that have immutable strings and such, having to do dumb poo poo like

code:
StringBuilder retval = new StringBuilder();
retval.append(HorribleEnterprise.putAPipeCleanerInMyDick("with a spoon");
retval.append("\n");
retval.append(new MoarEnterprise("dickbutt"));
return retval.ToString();

NotShadowStar fucked around with this message at 00:06 on Sep 8, 2011

Adbot
ADBOT LOVES YOU

Volte
Oct 4, 2004

woosh woosh
If you ever come to a point where you think "A goto would be really easy here, otherwise I'll have to add in a bunch of boolean flags and conditionals to code my way around it" and then add in the boolean flags and conditionals, you're doing it wrong

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