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
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I think that example's funny because I'm sure that even if I had no experience of programming, I'd be able to look at it and think "else balance = balance + 0? What's the point of that?"

Plus withdraweing monety and stuff I guess.

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

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

Sebbe posted:

To be fair, I've seen quite a few people write that sort of code in introductory programming classes; it's more of a sign that they don't really understand what they're writing than a horror, in my opinion.
Yes, I agree; as I said, I can't see how someone would, for example, think it worthwhile to put in those obviously redundant else {} clauses if they really understood properly what they were writing.

This is something I was thinking about only yesterday, as I was doing some teaching for a first-year calculus course (I'm a postgrad and we're asked to give a certain amount of help teaching every semester). It's fairly basic stuff that all of the first-year mathematics students have to do, and so you can understand how some of them will find it boring and switch off. But you do come into contact with students who seem not to readily engage with the idea that they need to think critically about what they're doing. By this I mean that they often seem to be used to the idea that there is some algorithmic, rote method that they will be able to learn and apply dutifully to whatever problem they're presented with. To do mathematics at a higher level they need to try and have a real understanding of the ideas they're working with, but while the introductory courses we give try to instill this in them, I have the uncomfortable impression they often don't succeed.

I'm talking about my discipline which is maths, but I can readily believe it applies to other technical disciplines too. I know you weren't criticising the student who wrote this, just observing that he didn't understand what he was writing. I tend to feel that while there is a value in "learning by doing", you shouldn't present a piece of work, purporting to be a genuine solution to a problem, in which you've written something you don't understand. I'm not sure in what way it is best to get students to understand that they really need to engage with the material they are learning, however.

I'm rambling so I'll shut up now.

Hammerite
Mar 9, 2007

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

Athas posted:

\exists and \forall are an E and an A mirrored across both axes.

He means, if you rotate W in one direction it looks like an E and if you rotate it in the other direction it looks like \exists.

Hammerite
Mar 9, 2007

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

evensevenone posted:

Or his "IT" professor didn't know or give a poo poo about php.
Well, this issue (the discussion is still about the passwords thing right?) isn't actually a PHP issue, it's HTML (and HTTP?)

I think it's clear that even if his professor did outright state what the guy claims he did, it's still something you might think to check somehow, if secure passwords are important in what you're doing.

Hammerite
Mar 9, 2007

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

WildFoxMedia posted:

Deciding to poo poo up another thread with your "OMG PHP SUCKS, EVERYONE WHO DOES PHP SUCKS" bullshit?

Well, at least the first of those statements is correct. I do scripting in PHP and I have a soft spot for it, but I can recognise that it does objectively suck pretty badly.

I don't think there should be an argument about it in this thread though.

Hammerite
Mar 9, 2007

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

Parantumaton posted:

How the gently caress did that guy even managed to get something compiled :psyduck:

He threw things together until it worked, didn't you read the quote? :)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Using an if block, for block, or whatever and omitting the braces is just bad in my opinion. It's like omitting brackets just because you know what the order of operations is; why make things less clear for the reader?

Hammerite
Mar 9, 2007

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

Plorkyeran posted:

Do you write x * y + z as (x * y) + z?

No. Although I would not object to seeing it.

I think BODMAS (or whatever you learnt it as) is sufficiently basic to be assumed. Obviously some base level of knowledge could be assumed in all instances. But I would stop short or writing, I don't know, x and y or a and b when I could write (x and y) or (a and b), because buggered if I can remember whether and or or has higher precedence.

Hammerite
Mar 9, 2007

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

Plorkyeran posted:

So in other words, you support leaving out the parentheses when you know the order of operations but want them there when you don't?

Yep, fairly close to that. But I'd certainly be charitable enough to put them in when I don't feel it's sufficiently "common knowledge" what the order of operations is.

Hammerite
Mar 9, 2007

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

HappyHippo posted:

So what does this have to do with leaving the braces out of an if block?

Nothing instrinsically. They are two separate things that I consider to be bad ideas on the grounds of contributing to poor understandability.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
https://www.youtube.com/watch?v=bOtMizMQ6oM

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:

Programming is math, but that doesn't mean it uses the same weird notation as algebra.
The form of mathematical notation that that code attempts to replicate

(a) is a fairly natural way to express binary relations between mathematical objects,
(b) needn't be seen as having any greater connection to algebra (in either the layman's or the mathematician's use of the word) than it does to any other field in which set theory is used.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
code:
$reverse_string = implode("xxx", $reversed_array);
$reverse_string = str_replace("xxx", "", $reverse_string);
This bit in particular is a bit odd. Why not just use implode('', $reversed_array)?

Hammerite
Mar 9, 2007

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

dark_panda posted:

Further to that, the MySQL Gotchas list.

Granted, some (maybe a lot) of these problems might be fixed in more recent versions of MySQL but it's still horrifying. MySQL is a coding horror in and of itself and actively propagates coding horrors as it is used.

I looked through that list and I would say the things on it fall into three categories.

  • Things that are fixed in the current version of MySQL. Example: "1.4. Case sensitivity in CHAR / VARCHAR fields". The guy makes no mention of character sets and collations here - I'll be charitable and assume he must be talking about a version of MySQL that had no character set/collation support, or poor support.
  • Things which are admittedly bad, but which are fixed by making sure MySQL is running in traditional mode. (You should always make sure it is running in traditional mode.) Example: truncation of overlong strings.
  • Things that apparently work contrary to how the author hoped they would, but which I don't see any problem with. Examples: all the waffling about inserting integers into ENUM columns (to me being able to use integers to specify an ENUM element by its index is handy), or the thing about division by zero resulting in NULL. N.B. this last is also different if MySQL is in traditional mode.

dark_panda posted:

schizophrenic features that sometimes work on certain table engines but not on others...

While I can see how that might be frustrating, I don't see how they could have implemented a flexible system for allowing swappable storage engines without having features that work on some engines but not others; and the swappable storage engines are nice to have. At any rate, most applications are fine sticking with InnoDB for just about anything, maybe MyISAM for text searching.

Can't comment on spatial data types, never used them. I have no reason to doubt what you say about them.

Hammerite
Mar 9, 2007

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

dark_panda posted:

As for some problems that can be solved by traditional mode, well, even those cases seem flat out weird. For instance, even with traditional mode enabled, "SELECT 1 / 0;" still returns NULL, 'cause apparently the ERROR_FOR_DIVISION_BY_ZERO option only errors out on INSERTs and UPDATEs; meanwhile, for SELECTs, a warning is silently produced.

I didn't know about that. That is not very well implemented.

quote:

Further to that, why do they handle division by zero but not the square root of negative numbers or any other situation where the result of an expression is mathematically undefined? This works fine:

code:
mysql> insert into testing values (sqrt(-1));
Query OK, 1 row affected (0.04 sec)
Even with traditional mode enabled and all that. I'd expect that INSERT to error out as well, there doesn't seem to be an equivalent for ERROR_FOR_DIVISION_BY_ZERO for such undefined operations. MySQL's stance seems to be "when something is wrong, NULL is the answer." NULL isn't supposed to be some catch-all hand waving solution that solves all of life's problems in database management, it's supposed to represent that there is an absence of a value. In situations like this, we don't have an absence of a value but rather we know that the result of the expression is undefined mathematically, which is different than being absent.

Yeah, I would agree that throwing an error would be appropriate here. Although as a mathematician I feel the need to be picky and say that the result isn't "undefined mathematically", it just isn't a value that MySQL is designed to be able to manipulate. But it is a definite value and NULL isn't appropriate.

quote:

Speaking of collation support, I find it bizarre that the default encoding and collation settings are latin1 and latin1_swedish_ci respectively. Collation is a bit harder to default, I guess, and I know MySQL AB is based in Sweden, but I would at least think that these days UTF-8 would be the more popular choice for the encoding.

Arguably, but you have to bear in mind that MySQL will reserve 3 bytes per character if you make a CHAR column UTF-8, so it is not without side-effects.

quote:

The swappable storage engines can be alluring, but in the end it seems to cause so many headaches that you start to wonder if it's worth it.

You could take either of two positions on the subject. On the one hand you could say that it's good to have swappable storage engines in principle, because it means that developers have the freedom to create engines optimised for all sorts of different tasks. This is largely a theoretical advantage, although you can see it to a certain extent in the existence of the ARCHIVE and MEMORY engines. On the other hand you could argue that it leads to huge duplication of effort and results in none of the engines being as polished as a single engine could be if it was focused on by the design team.

Hammerite
Mar 9, 2007

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

dancavallaro posted:

At first I thought that was way too spot-on to be real, but I'm honestly not so sure anymore. In his post about "landing a high-paying new job", he mentions and links to a post he made on Reddit (http://www.reddit.com/r/programming/comments/c2lcy/ask_proggit_any_excellent_beginner_books_on_crypto), where he asks about books that will help him learn crypto without delving into "overly complex" topics like rainbow tables and ciphers (what the christ?). And the post on Reddit seems pretty real, it's a pretty typical "asking for help" post with a healthy dose of stupid on top. If this guy is faking it, he's doing a really loving good job.

That doesn't demonstrate that he's for real. He could equally be trolling or trying to drum up more visitors for his blog while remaining in character.

Hammerite
Mar 9, 2007

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

tef posted:

they're called race conditons because they make the code go faster :eng99:

what you need here is a big red stripe!! and maybe a chevron

Hammerite
Mar 9, 2007

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

FinkieMcGee posted:

Just found out in one of our applications database credentials are being passed via a querystring through an iframe.

You mean the user enters credentials and they're submitted this way, or...?

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?

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.

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.

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.

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.

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

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.

Hammerite
Mar 9, 2007

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

Bozart posted:

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.

I tried using if... else if... else if... else but didn't like the way it turned out, chiefly because it's too easy to end up with something like this:

code:
if ( /* Error condition 1 */ ) {
    // handle error
} else if ( /* Error condition 2 */ ) {
    // handle error
} else {
    // do something
    if ( /* Error condition 3 */ ) {
        // handle error
    } else if ( /* Absence of error condition 4 */ ) {
        if ( /* Error condition 5 */ ) {
            // handle error
        } else if ( /* Error condition 6 */ ) {
            // handle error
        } else {
            // do something else
            if ( /* Absence of error condition 7 */ ) {
                // Do what I wanted to do
                // (see how much of a chore this is to find)
            } else {
                // handle error
            }
        }
    } else {
        // handle error
    }
}
Using do... while false allows all of the error conditions to be separated, and I can do work between the if blocks if I want to. The if blocks all have the same form (set a certain number of variables, follow last of all with break) and it's quite easy to check over.

Hammerite
Mar 9, 2007

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

Sagacity posted:

This is actually quite amazing. For all the weird quirks and invitations to abuse the language PHP has, it only recently acquired the goto statement?

Yup, I was surprised when I realised this as well.

Hammerite
Mar 9, 2007

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

WildFoxMedia posted:

Ever considered using Exceptions?

I've heard of them but I haven't made the effort to learn about them yet. I'm a little suspicious of them because I don't understand where the flow of control goes when one happens, but this is entirely down to me not knowing anything about how they work.

Fehler posted:

I always do something like this: (code)

Yes, in places where I want to list all the errors (rather than stop after the first one) I do something similar.

Hammerite
Mar 9, 2007

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

fletcher posted:

My friend was taking an online quiz and I noticed how lovely the website looked, so I did a View->Source to have a laugh. All of the answers to the questions were in there as <input type="hidden"/>. Not only that, but the last 10 questions had incorrect answers marked in the key. After you finish the quiz it doesn't tell you your score or which ones you got wrong, it's just a pass/fail, so who knows how long this has gone by without notice.

What kind of online quiz? One of those "WHICH FAMILY GUY CHARACTER ARE U???" type ones, or something important?

Hammerite
Mar 9, 2007

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

Argue posted:

Okay, here comes another wonderful piece of architecture from our client, incidentally a very large company that's well-known in my country.

There's an HTTP server running, and it listens for requests such as "reset PIN#". When the server receives such a request, it dumps the connection into a pool, and queues up the request for processing by another thread, the service thread.

Now, the service thread does its processing (which is partly what my previous posts were about), and generates a response. How do you suppose this response gets sent back to the original requester?

That's right! It doesn't! Instead, it just plucks any connection out of the pool, and returns the response there. The results are exactly as you might expect. One guy might receive a "successful" confirmation message when his transaction failed, and vice versa. :toot:

Hahaha

"Your PIN has been reset. Have a nice day!"

"What nooooo"

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:

So two of them should bring your hard drive right back.

Good point! Better stick another couple in just to be safe.

Hammerite
Mar 9, 2007

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

GrumpyDoctor posted:

Maybe I'm the real horror here, but I think I agree with the lead dev on this one.

Agree that it's more concise, or that it's better? (It is one of those things, but not the other.)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
The argument in defense of Microsoft isn't that they're competent, merely that they're not necessarily being dishonest. Also, the whole thing is still in beta isn't it?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
The whole "omg PHP type-juggling" thing is a bit of a dead horse isn't it? Yeah it's not always terribly consistent, it's meant to allow you to Get poo poo Done quickly. It's not necessarily optimised for that, but it doesn't do too badly. It does give you ways to compare things carefully when you need to do so.

The main comparison-operator complaint I have about PHP is that if you want to check whether a variable exists and is null, you have to use array_key_exists($var, $GLOBALS). You can't use isset() (because it returns false if the variable is set but is null) and you can't use is_null() (because it returns true if the variable doesn't exist) (you still shouldn't use is_null even if it didn't do this, mind, because it will cause unset variable notices).

Hammerite
Mar 9, 2007

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

tef posted:

You are claiming to be a painter but all you do is cover walls in your own faeces because you can't get the paint cans open.

If you want to slate PHP, I can think of at least 10 things that are more worthy of criticism than type-juggling.

Adbot
ADBOT LOVES YOU

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:

Yeah, I forgot "gently caress my life" == 0 really helps make websites faster :?:

I interpreted this as: "Your post is wrong, because type-juggling does not cause websites to run more quickly". This is a misunderstanding of my post - my implication is that it makes some general-purpose scripts easier to program (where strict attention to the types of data is not required). That is, writing code can be faster.

There are many situations in which type-safety is required, in which case it is available.

Hammerite fucked around with this message at 16:40 on Dec 11, 2010

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