How not to use a switch statement
-
@PJH, can you change edit time limits per category? Having a super long time limit on the CodeSOD category would be awesome, so that I could update the original code if I decide that it needs clarification (in this instance, showing what "do stuff" is).
Nope. There's only a global time limit. The only alternative is to make a post a wiki, but then everyone can edit it.
-
Too bad.
-
Im even a mu-user!
("mu" as the next letter in the Greek alphabet after lamda, and as in "micro" user [of lambda] as well – we're seeing a bit too much of this lately ...)
-
-
Yes, I am a user of a secret stash of ammo and health.
Thanks, I decided that this weekend will be dedicated purely to procrastination, so you just gave me the idea for a "weekend project".
Have to get that damned achievement for all caches already.
-
If
argv[1] == 5
is true, I'd be worried.That might, maybe valid on an architecture that doesn't put interrupt vectors or something like that down in low memory, but otherwise, yeah.
-
The lowest however many virtual addresses aren't used because dereferencing a NULL pointer to a struct shouldn't yield different results than dereferencing a NULL pointer to one of its fields.
-
The lowest however many virtual addresses aren't used
How many 8-bit embedded micros have virtual addressing?
-
How many 8-bit embedded micros have a command line?
I seriously know nothing about 8-bit embedded micros other than the fact that they have no filesystem.
-
Most, if not all, may not have real command lines, but at least some have C libraries that can call
main()
withargc
andargv
set, possibly to hard values in ROM.
-
A NULL pointer doesn't need to have 0 as internal representation, though:
So I think that means that it may be true that ((char*)5) - ((char*)0) != 5.
-
Straw man. That's not functional in any way.
-
Actually, I'm pretty sure ((char*)5) is undefined, at least in most contexts. And I certainly don't see any sane reason why you'd write that.
-
argv[1] == 5
Agreed, I was merely referring to the proposed scenario that argv[1] == 5, which I presume was intended to mean argv[1] == (char*)5, arguing (though I'm not completely certain) how ben_lubar's comment could be incorrect.
Oh, and I'm currently coding an operating system, and ((char*)5) isn't literally in there, but it wouldn't be completely out of place there (ie. "(Character*) 0xB8000" is literally in there). Of course, it's not intended to be portable to different architectures.
-
Actually, I'm pretty sure ((char*)5) is undefined, at least in most contexts.
But generally should be minor undefined. Making a demon fly out of your nose for just that would be considered to be a severe implementation flaw.
-
I'd assume whoever wrote this has been a VB6 programmer before.
At least there, this idiom is quite often used:
Select Case True Case x Is Nothing, x.Foo < 0 doSomething Case x.Foo > 100 doSomethingElse End Select
instead of
If x Is Nothing || x.Foo < 0 Then doSomething ElseIf x.Foo > 100 Then doSomethingElse EndIf
just that the shortcut
||
operator (OrElse
in VB.NET) did not yet exist in VB6, and you sometimes need shortcut evalution (likex.Foo
will raise an error ifx Is Nothing
).If you need a cascade of
&&
(AndAlso
) expressions, you can also findSelect Case False
.Not that I think this code is nice, it is a kludge for a specific problem, which was known in the respective coder community. In JavaScript (where there are shortcutting operators) I don't think this is needed ...
-
On reflection not nearly enough.
But then again I'm a PHP programmer and I wouldn't make that mistake. Mind you, I'd like to believe I'm in the very small group of 'capable PHP programmers' if such a thing exists, and if not then maybe I really am TRWTF.
-
-
Where do I apply? Is the test hard?
Is it hard to cheat?
-
@PJH, @Arantor and I would like a Capable PHP Programmer badge each please.
That's nice. Would another Snowflake badge suffice?
-
Actually, the Zend certification test isn't especially difficult. I don't mean the one for Zend Fuckwork, but the language itself.
-
Where do I apply? Is the test hard?
Not really. You just have to be competent relative to the average PHP programmer. You can probably get away with leaving a few XSS and SQL injection exploits in your code.
-
Would another Snowflake badge suffice?
Only if you can make it so I can wear more than one at a time.
-
It helps your cred somewhat if you can spot XSS flaws in other peoples' apps because if you can spot other peoples' XSS from the code, you're usually competent enough to avoid them yourself.
That is assuming you don't just blindly mash anything in there and wait to see what sticks.
-
It helps your cred somewhat if you can spot XSS flaws in other peoples' apps because if you can spot other peoples' XSS from the code, you're usually competent enough to avoid them yourself.
Well, we've found an aspect in which Discourse has excelled for the community.
-
How many of us have found patches in the code for XSS though?
-
I remember encountering file uploads on mine; something I really don't do very often but it just so happened that in the weeks just prior to taking it, I'd done an extension reworking of something that just happened to revolve around file uploading.
-
Not really. You just have to be competent relative to the average PHP programmer. You can probably get away with leaving a few XSS and SQL injection exploits in your code.
Can I just fall asleep on my keyboard?
-
That would probaly qualify you.
-
Capable PHP Programmer
@thegoryone said:
I rarely hear the words "competent" and "PHP" included in the same sentence.
Mostly because the ones that would identify as competent would not then also identify themselves as PHP programmers first as their main language.
-
Primary language: PHP, doing it for 11 years now. I can't think of any other language I have used for so long. But I wouldn't say I have 11 years of experience, because I know I repeated the first couple of years over at least once. Too insular, too afraid to learn bad habits from other people - until I began to realise that if I spotted bad patterns, I didn't have to learn from them.
Then again I also self-describe as TRWTF so that may not help my case much.
-
PHP, doing it for 11 years now
Which means you've done 3 different PHPs really... it's almost like C -> C++ -> C# at that point isn't it?
Unless you've just kept plugging along in PHP3 mode for 11 years now.
-
it's almost like C -> C++ -> C# at that point isn't it?
Wait, did you just imply that Source Engine games are built on the C equivalent of PHP4?
-
Wait, did you just imply that Source Engine games are built on the C equivalent of PHP4?
Not really. But, if you were going to take that route, it would be PHP3 that lines up with C, PHP4 with C++, and PHP5 with C#.
For an actual parallel, Java would be more apt.... Java 1.3 = PHP3, Java 1.4 = PHP4, Java 1.5 and up = PHP5?
-
Yeah, there are still legitimate reasons to use C or C++, whereas PHP3 or Java 1.3... not so much.
-
The real point I was trying to make is that PHP3 is barely even the same language as PHP5. PHP3 was a purely imperative function/linear language vs PHP5 which supports object oriented development.
-
Err, when was PHP ever functional? I'm not just being snarky.
I guess PHP 5.4 or something has closures. And it has first class functions, apparently. What about purity? Referential transparency?
-
Err, when was PHP ever functional
Sorry mr pedant ;)
Imperative with functions, not functional.
edited to make clear that I wasn't referring to the actual term "functional language", rather, a language with functions.
-
Procedural isn't the same as functional.
Here's something functional (and useless): http://play.golang.org/p/rXGrAZ6aia
-
Procedural isn't the same as functional.
Already ninjad that.
And yes, I am well aware. Just terminology overlap.
-
a language with functions
Isn't that all languages (except the really esoteric ones)?
-
Isn't that all languages (except the really esoteric ones)?
Depends on whether you count Assembly language constructs as "functions"
-
No. Most languages have "procedures". Not many have a separate type for functions, let alone first class functions. Think command/query separation. Pure computations are queries. Procedures/commands are drivers.
-
Pretty much the second things got pedantic when I used the word functional, this conversation was going to go to hell.
Filed Under: I have only myself to blame.
-
It's getting to be usable these days. But the legacy shit is holding any potential down. And, as discussed in another thread, that probably means it's boned because removing backwards compatibility would probably just kill it dead anyway.
-
Which means you've done 3 different PHPs really... it's almost like C -> C++ -> C# at that point isn't it?
Unless you've just kept plugging along in PHP3 mode for 11 years now.
Nope, I started with PHP 4.0.6 if I remember rightly. But even that is a massively different proposition to how things are now. I mean, I was doing PHP before $_GET and $_POST were really a thing.
-
The real point I was trying to make is that PHP3 is barely even the same language as PHP5. PHP3 was a purely imperative function/linear language vs PHP5 which supports object oriented development.
Technically PHP 4 does OOP too but it's a pretend version of OOP which assumes the only visibility is public. 5 introduced goodies like interfaces and 5.3 introduces things like namespaces. It is getting better, and it is not quite the toxic hellstew of old.
-
Now if we only could proper method overloading instead of futzing around with
__call
...
-
Steady on. It's taken long enough to get viable OOP.
-