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
RankWeis
Jul 10, 2010

ctz posted:

code:
>>> 4 == "4"
False
>>> 4 === "4"
  File "<stdin>", line 1
    4 === "4"
        ^
SyntaxError: invalid syntax
You have some strange beliefs.

Yeah, unfortunately, I was posting from my iPad so google and a terminal were too complicated to actually test anything out. But I recall that languages that do this type of comparison usually have a 'strict' comparison to go along with it, and I thought python was one of them

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

http://search.cpan.org/~dsugal/Taint-0.07/Taint.pm

Perl does it differently, what with it being a dynamic language. Seriously people, this is babbies first programming argument in here.

king_kilr
May 25, 2007
I've never been responsible for employee interviews before, but if I ever am, I'm asking a question about how the candidate feels about type coercions.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

king_kilr posted:

I've never been responsible for employee interviews before, but if I ever am, I'm asking a question about how the candidate feels about type coercions.

are you going to ask that in order to see whether they agree with you, or to see what knowledge they display about the subject and what reasoning they give for their opinion?

king_kilr
May 25, 2007

Hammerite posted:

are you going to ask that in order to see whether they agree with you, or to see what knowledge they display about the subject and what reasoning they give for their opinion?

Both.

Lysandus
Jun 21, 2010
code:
for (int i = 0; i<1; i++ )
{
     /do some stuff, guess how many times.
}

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Lysandus posted:

code:
for (int i = 0; i<1; i++ )
{
     /do some stuff, guess how many times.
}

I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.

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.
Have you heard of the if statement?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Mustach posted:

Have you heard of the if statement?

Yes, I have.

I sense that you think you are making a point in a pithy fashion. Please make your point more explicitly.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Lysandus posted:

code:
for (int i = 0; i<1; i++ )
{
     /do some stuff, guess how many times.
}

This could be pretty powerful if merged with the FOR-CASE idiom.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Hammerite posted:

I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.

It does things exactly once. Unless you are doing i--; in the body, which is just all kinds of hosed up. The for statement might as well not exist.

while(true) is a completely different control structure and actually has a use.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Hammerite posted:

I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.

You might've had a point with do { .. } while(0), but you missed your chance.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Ryouga Inverse posted:

It does things exactly once. Unless you are doing i--; in the body...

Yes, I realise that.

Ryouga Inverse posted:

... which is just all kinds of hosed up.

It wouldn't appear likely to be the best way of achieving whatever is intended, but I don't think it's clear-cut enough to write off as definitely wrong in all situations. Chances are high (given the thread) that in the code it was taken from it was not appropriate, but I cannot conclude that any and every use of it would be indefensible.

Ryouga Inverse posted:

while(true) is a completely different control structure and actually has a use.

Different in effect, certainly. I'm not sure it qualifies as being different in style. Both are ways of using looping structures that aren't on the face of it the "usual" or most straightforward way of using those structures.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

pokeyman posted:

You might've had a point with do { .. } while(0), but you missed your chance.

I don't see what you mean. Yes, do { ... } while (false) is another good example, although as far as I am aware it only provides the same functionality as goto.

Zombywuf
Mar 29, 2008

Right now I am very tempted to send an email around my company:

The email I am not sending posted:

If you have marked your page as being XHTML and you are getting strange errors in Chrome such as "expected ;" the problem is that you haven't escaped one of the following characters &<>'". Chrome actually validates XHTML which means you have to make your XHTML parse as valid XML. This is not rocket science people, the next person I see puzzling over a bug that was caused by <a href="http://somedomain/path?aparam=avalue&anotherparam=anothervalue"> I will loving kill you.
I am not sending this because I have a sword beside my desk and people might take it the wrong way.

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"

Zombywuf posted:

Right now I am very tempted to send an email around my company:

I am not sending this because I have a sword beside my desk and people might take it the wrong way.
I don't have chrome on this system to test, but does it use an XML parser for pages served as "text/html", depending on their doctype? If so, that's the real horror.

e: I just tested it; HTML with the wrong doctype is parsed as HTML, which means your coworkers have roughly the IQ of grass. Send the hell out of that email.

TOO SCSI FOR MY CAT fucked around with this message at 18:58 on Sep 27, 2010

ToxicFrog
Apr 26, 2008


Otto Skorzeny posted:

There's a semantic spat to be had here about whether scalar variables in Perl have types and whether perl's concept of SV's and PV's constitute datatypes, but I'll instead say that you probably also have a bone to pick with ANSI C's handling of equality between ints and floats:

I'm not as mussed about it in statically typed languages, because then the type checker can ensure that (a) the coercion will never fail at runtime and (b) no information is lost - in the case of C, for example, short int == long int will upcast the lhs to a long int, int == float will upcast it to a float, and int == char * is an error (or at least a warning). In a dynamically typed language no such guarantees can be made, so the possibility exists for something that works most of the time, but fails on certain input as the coercion fails at runtime - or something that works all of the time even when it should fail and report invalid input.

RankWeis posted:

Yeah, unfortunately, I was posting from my iPad so google and a terminal were too complicated to actually test anything out. But I recall that languages that do this type of comparison usually have a 'strict' comparison to go along with it, and I thought python was one of them

Most dynamically typed languages are nonetheless strongly typed and, consequently, tend not to pull this. It mostly seems to be a feature of weakly typed languages like Perl or TCL.

It may come as no surprise that my preference is for strongly+statically typed languages. :)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Here's some type-related fun I came across in some vendor code today:

code:
SetLineVol(String(Number(nLineNo)), String(Number(nVolume)));

ToxicFrog
Apr 26, 2008


So wait, is it calling Number() on something that's already numeric? Or are they not only using systems hungarian, but lying about the type?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

ToxicFrog posted:

So wait, is it calling Number() on something that's already numeric? Or are they not only using systems hungarian, but lying about the type?

The inputs to this method come from SELECT elements, so technically that is a String always. There's a lot of weird stuff like this, which I gather comes form said vendor being a .NET developer who had to do a little bit of javascript.

mjau
Aug 8, 2008

ToxicFrog posted:

int == float will upcast it to a float,

Bit of a nitpick, but this is not true. A 32-bit int can hold more distinct integer values than a 32-bit float can, so just casting the int to float wouldn't work.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Hammerite posted:

I don't see what you mean. Yes, do { ... } while (false) is another good example, although as far as I am aware it only provides the same functionality as goto.

Sorry, I thought we were playing "seemingly odd but legitimate uses of loops", not "heh everything is a goto".

PS How is what you quoted a goto?

Lysandus
Jun 21, 2010

Hammerite posted:

I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.

I challenge thee to provide an example.

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.

Hammerite posted:

Yes, I have.

I sense that you think you are making a point in a pithy fashion. Please make your point more explicitly.
The point is that they implemented the if statement with a for.

There is no hypothetical "maybe this construct could sometime, someday be useful — I'm going to put this feather in my cap!" situation. Not only did the snippit say that the loop goes through just one iteration, if i were modified in the body, in any fashion, it would be a classifiable mess. I guarantee you that I can come up with a clearer version of any possible replacement for "//do some stuff, guess how many times" that involves modifying i.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

pokeyman posted:

Sorry, I thought we were playing "seemingly odd but legitimate uses of loops", not "heh everything is a goto".

PS How is what you quoted a goto?

Well, it could be that there is a use for do { ... } while (false) that has not occurred to me, but my own use of it has been limited to error checking; as in

code:
$error_type = false;
$error_message = '';

do {

    if ( /* Error condition 1 /* ) {
        $error_type = 1;
        $error_message = 'Type 1 error';
        break;
    }

    if ( /* Error condition 2 /* ) {
        $error_type = 2;
        $error_message = 'Type 2 error';
        break;
    }

    ...

    if ( /* Error condition n /* ) {
        $error_type = n;
        $error_message = 'Type n error';
        break;
    }

} while (false);

if ( $error_type !== false ) {
    // Report error to user as appropriate
} else {
    // Go ahead and do something; no error conditions satisfied
}
And of course this can be replaced by a label at the location of the while (false), and each "break" replaced by a goto pointing at that label. It's straightforwardly identical in operation. Forgive me if I haven't spotted something else you can do with do { ... } while (false), but the loop can only ever run once and all you can do is break out of it, AFAIK.

I don't know what you mean by "heh everything is a goto". I don't think I've said anything to that effect.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Mustach posted:

The point is that they implemented the if statement with a for.

I'm sorry, but I don't understand your reasoning. How is that in any way an implementation of the if control structure?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Lysandus posted:

I challenge thee to provide an example.

I cannot.

Plorkyeran
Mar 22, 2007

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

Lysandus posted:

I challenge thee to provide an example.
It's useful in C preprocessor macros but I guess one could argue it's not being used as a control structure there.

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"
while(true) is great when you need to do something like "read n bytes from this socket"; sure, it's possible to encode this loop with for, but an infinite loop combined with break or return is much clearer.

do { } while(0) is really only useful for preprocessor macros. That use of it for error handling is obscene, just use goto, gently caress, it doesn't bite.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Janin posted:

do { } while(0) is really only useful for preprocessor macros. That use of it for error handling is obscene, just use goto, gently caress, it doesn't bite.

I would use goto, but it isn't available in PHP until version 5.3, and I want my scripts to be portable to hosts running versions 5.0 and above.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Quote is not edit

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"

Hammerite posted:

I would use goto, but it isn't available in PHP until version 5.3, and I want my scripts to be portable to hosts running versions 5.0 and above.
Oh, sorry, didn't read it close enough to notice it's not C. Yeah, if your language is crippled, ya gotta do what ya gotta do.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Hammerite posted:

php

I had no idea we were talking about PHP. My apologies.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

pokeyman posted:

I had no idea we were talking about PHP. My apologies.

For myself, I didn't think what we were talking about was specific to PHP - what's different in other languages? Tell me more.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
The skeleton code for my current programming assignment is certainly horrific. Among the things about it I hate, there are such wonderful things as:

1) Being forced into using java.nio when multithreading would be so very much easier (and there wouldn't even be data shared between threads at any time, so I can't see a disadvantage to using it)!

2) A parsing method, to retrieve the hostname from an HTTP header, which returns 'void'. Since we are explicitly not allowed to change the provided interface, I've made this method set a member variable which is then read by the method that calls it, which is a coding horror in and of itself. Of course, it could just return String, in which case everything would be simple.

3) To make the marking easier, they've split the code into three different methods which (theoretically) can be tested on their own if the entire thing doesn't work as intended. Of course, this means that various data must be stored in member variables since the interfaces are fixed and they don't provide all the necessary parameters. Besides, if not all methods work as intended, the entire thing will be completely hosed anyway.

I have a suspicion that this code may have been written by the TA who couldn't figure out why an extra curly brace was causing an error, nor why variable.socket is different from variable.socket().

Vino
Aug 11, 2010

quote:

do { } while(0)

I use this on occasion to create a scope from which my objects will be destructed automatically after completion. For example:


do {
CRenderingContext c(Game()->GetRenderer());
c.SetBlend(BLEND_ALPHA);
CRootPanel::PaintTexture(m_iGraphic, 10, 20, 30, 40);
} while (false);

// Since CRenderingContext pops the blend state in its destructor, any painting here won't have alpha blending.


In my experience a simple { } didn't do this, the do while false bit was needed. Perhaps there is a better way?

schnarf
Jun 1, 2002
I WIN.

Vino posted:

I use this on occasion to create a scope from which my objects will be destructed automatically after completion. For example:


do {
CRenderingContext c(Game()->GetRenderer());
c.SetBlend(BLEND_ALPHA);
CRootPanel::PaintTexture(m_iGraphic, 10, 20, 30, 40);
} while (false);

// Since CRenderingContext pops the blend state in its destructor, any painting here won't have alpha blending.


In my experience a simple { } didn't do this, the do while false bit was needed. Perhaps there is a better way?
Just doing {} should do that.

Vino
Aug 11, 2010

schnarf posted:

Just doing {} should do that.

Odd. In my limited tests it did not. Perhaps more investigation is needed.

Bozart
Oct 28, 2006

Give me the finger.

Hammerite posted:

For myself, I didn't think what we were talking about was specific to PHP - what's different in other languages? Tell me more.

I am totally unfamiliar with PHP, but why wouldn't you just use an else if? That break in each of the if blocks makes me want to check that it exists in all of them or if there is some kind of bizzaro override.

Adbot
ADBOT LOVES YOU

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

PT6A posted:

2) A parsing method, to retrieve the hostname from an HTTP header, which returns 'void'. Since we are explicitly not allowed to change the provided interface, I've made this method set a member variable which is then read by the method that calls it, which is a coding horror in and of itself. Of course, it could just return String, in which case everything would be simple.

I have to deal with a 3rd party API which does something similar. There's a function to get certain information from devices, which is void, so how do you actually get the info? Why it's simple:

1. You give the instance that represents the device a GetInfoCallback.
2. You call RequestInfo, which returns immediately.
3. The callback is called on a separate thread.
4. In the callback you call GetInfo, which gives you the last requested info.

If you have two simultaneous info requests, you'll get both results, but there's no way to tell which is which.

Oh, and if an error occurs, then the callback is never called, but you're also never notified that something went wrong.

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