|
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:
|
# ? Sep 28, 2010 09:18 |
|
|
# ? Apr 27, 2024 08:44 |
|
Hammerite posted:I would use goto, but it isn't available in PHP until version 5.3.
|
# ? Sep 28, 2010 09:38 |
|
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.
|
# ? Sep 28, 2010 09:43 |
|
Hammerite posted:
Ever considered using Exceptions? code:
|
# ? Sep 28, 2010 09:58 |
|
PHP has lots of crap in it (see the nth debate about it in here), but the loose typing system is hardly an horror in itself compared to a weird design decision. Most people would never even complain about it had the operators '==' and '===' or '!=' and '!==' been reversed on which is loose and which is strict. You could use PHP in an entirely strict manner (note: strict, not statically typed) by using the right operators and annotating function arguments with types: http://ideone.com/ulkD2 So this is php:<?php function untyped_plus($x, $y, $z) { return $x + $y + $z; } function typed_plus(double $x, int $y, string $z) { return $x + $y + $z; } function partially_typed_plus(double $x, int $y, $z) { return $x + $y + $z; } // main yes $x = 4.0; $y = 6; $z = "2"; echo untyped_plus($x, $y, $z)."\n"; // should be 12 echo partially_typed_plus($x, $y, $z)."\n"; // works. 12 echo typed_plus($x, $y, $z); // crashes ?> quote:12
|
# ? Sep 28, 2010 10:21 |
|
Hammerite posted: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. code:
|
# ? Sep 28, 2010 11:10 |
|
Hammerite posted:I'm sorry, but I don't understand your reasoning. How is that in any way an implementation of the if control structure?
|
# ? Sep 28, 2010 12:01 |
|
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.
|
# ? Sep 28, 2010 12:45 |
|
Exceptions are great until they are thrown 14 calls back with no indications of which method threw it.
|
# ? Sep 28, 2010 13:46 |
|
What crazytown language doesn't vomit a stack dump when you get an uncaught exception?
|
# ? Sep 28, 2010 14:00 |
|
NotShadowStar posted:What crazytown language doesn't vomit a stack dump when you get an uncaught exception? RIMs bastard java they put on Blackberrys.
|
# ? Sep 28, 2010 14:04 |
|
Lysandus posted:RIMs bastard java they put on Blackberrys. Sounds like OCAP. If you are doing C, you should be able to write a macro that embeds line numbers and more into the exceptions message.
|
# ? Sep 28, 2010 15:43 |
|
I thought I'd share this little gem by a programmer we recently sacked because he told my boss in all seriousness that he deserved a 100% pay raise. The gist is that it loops through an array of member objects which may have duplicates in it and produces an array with no duplicates.code:
|
# ? Sep 28, 2010 17:24 |
|
NotShadowStar posted:What crazytown language doesn't vomit a stack dump when you get an uncaught exception?
|
# ? Sep 28, 2010 18:48 |
|
Hammerite posted: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. loving Exceptions, how do they work? http://us.php.net/manual/en/language.exceptions.php
|
# ? Sep 28, 2010 21:29 |
|
zootm posted:Interestingly if you're using java.util.concurrent you do not get a stack trace if your task dies, you have to check the return value of your Future instance when it completes. This catches people out when they're using them as "a nicer way to spawn threads". You can get them if you register a default uncaught exception handler (http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#getDefaultUncaughtExceptionHandler%28%29) but the type of people you describe in your last sentence probably wouldn't have figured this out either.
|
# ? Sep 28, 2010 21:34 |
|
Hammerite posted: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: else ifs + exceptions removes the need for those nested structures, doesn't take up as much room, and is easier to read. (pseudo-) code:
NeedCondition1(StateData1,StateData2) NeedCondition2(DEFCON1,DEFCON0) Do stuff.. NeedCondition1(DifferentStateData1,DifferentStateData2) etc. Then again maybe I'm an oddball. Sorry for the long post.
|
# ? Sep 29, 2010 03:32 |
|
I've mentioned before that I work in a C++ dev shop. We have a ton of objects being dumped in a hash map that my coworker wants to iterate over efficiently. Rather than writing or finding an implementation of a LinkedHashMap or similar, he has rolled his own memory pool and overloaded operator new() to ensure that they're all next to each other in memory, so that he can use pointer arithmetic or something.
|
# ? Sep 29, 2010 04:36 |
|
Lysandus posted:RIMs bastard java they put on Blackberrys. That whole thing is a coding horror. My favorite part was probably finding out that in a multithreaded app, blocking the UI thread would block the entire application, including the background thread that pings the robot every 50ms to keep it from going into full reverse and destroying something. Although, to be fair, the robot was around 4-5 horrors on its own. That entire project was a clusterfuck.
|
# ? Sep 29, 2010 06:19 |
|
w00tz0r posted:I've mentioned before that I work in a C++ dev shop. A linked list is not a particularly efficient way to iterate.
|
# ? Sep 29, 2010 09:55 |
|
Zombywuf posted:A linked list is not a particularly efficient way to iterate. Please describe how to iterate over an entire list in less than O(1)... If you're referring to a specific implementation of linked lists, don't do that.
|
# ? Sep 29, 2010 09:59 |
|
baquerd posted:Please describe how to iterate over an entire list in less than O(1)... If you're referring to a specific implementation of linked lists, don't do that. Yes, obviously I am talking about asymptotic complexity. Go away and learn about caching.
|
# ? Sep 29, 2010 10:25 |
|
Zombywuf posted:Yes, obviously I am talking about asymptotic complexity. Go away and learn about caching. Please, just because you implement linked lists in a naive fashion does not mean that you can't arrange them in a memory efficient manner.
|
# ? Sep 29, 2010 10:30 |
|
baquerd posted:Please, just because you implement linked lists in a naive fashion does not mean that you can't arrange them in a memory efficient manner. You mean write a custom allocator that places them in a contiguous memory block so they can be traversed by simple pointer arithmetic. Hey, if you were to do that you could eliminate the need for the next pointer and just treat it as an array. What an awesome idea!
|
# ? Sep 29, 2010 11:00 |
|
Zombywuf posted:You mean write a custom allocator that places them in a contiguous memory block so they can be traversed by simple pointer arithmetic. Hey, if you were to do that you could eliminate the need for the next pointer and just treat it as an array. What an awesome idea! This is true for smaller objects where your pro-caching technique works well. For large objects that may not even fit in the cache in the first place, the original LinkedHashMap is in fact a great choice, and there are many further optimizations depending on how pedantic you want to be and how far you want to mess up your data structure.
|
# ? Sep 29, 2010 11:09 |
|
baquerd posted:This is true for smaller objects where your pro-caching technique works well. For large objects that may not even fit in the cache in the first place, the original LinkedHashMap is in fact a great choice, and there are many further optimizations depending on how pedantic you want to be and how far you want to mess up your data structure. If your objects are too large to even fit in your level 2 cache then you need to start worrying about separating the key part of your data from the value, otherwise a hash table is probably the wrong structure. Judging by his description of the problem I'm going to stick with assuming w00tz0r is just wrong. Even if he's not the C++ way to do it would not be copying parts of the Java standard library, also linked lists are still the death of efficiency in all but a very few cases.
|
# ? Sep 29, 2010 13:36 |
|
I can't post the code, because it's no individual line that makes it a crime against humaity. It's 8912 line Perl module that implements some bastard homegrown version of OO that I have to rewrite at work.Larry Wall posted:Perl is cute, funny, fun, smart, and trendy. Other languages are stodgy, boring, depressing, and have no sense of humor. gently caress you Larry.
|
# ? Sep 29, 2010 14:24 |
|
ToxicFrog posted:
Fun fact: in "RIM Java", static initialization on final variables can be fired every time the classloader of a subclass is executed. Oh, and "Error 523", the magical "gently caress you" error message that tells you nothing other than that RIM wrote a Java implementation that can produce kernel panics for ill-defined reasons.
|
# ? Sep 29, 2010 14:47 |
|
A very bad man posted:I can't post the code, because it's no individual line that makes it a crime against humaity. It's 8912 line Perl module that implements some bastard homegrown version of OO that I have to rewrite at work. That has nothing to do with Perl, I used to have to maintain a 60,000 line XSLT file.
|
# ? Sep 29, 2010 14:56 |
|
Luxury!
|
# ? Sep 29, 2010 15:06 |
|
Internet Janitor posted:Fun fact: in "RIM Java", static initialization on final variables can be fired every time the classloader of a subclass is executed. Try this with strings and watch your memory footprint EXPLODE INTO WONDERLAND!
|
# ? Sep 29, 2010 19:37 |
|
Man just when I thought I heard everything about Java being terrible. I wonder how RIM isn't sued to hell from Oracle like they're doing with Google. On one had I wish Oracle would self destruct Java so as a whole we could move on to something interesting, on the other that would be bad as legions of absolutely awful Indians and eastern Europeans working for $10/hr are unleashed unsuspecting on the rest of everything, Enterprising everything they touch. It happened with C#!
|
# ? Sep 29, 2010 20:52 |
|
Yeah I hate when the browns mess up my code.
|
# ? Sep 29, 2010 21:03 |
|
code:
|
# ? Sep 29, 2010 21:47 |
|
I deal with PHP daily. I get a new bit of death inside every day. Someone doesn't know how to do events, so here's how they did them: code:
code:
code:
code:
|
# ? Sep 29, 2010 22:21 |
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.
|
|
# ? Sep 30, 2010 00:39 |
|
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?
|
# ? Sep 30, 2010 00:45 |
Hammerite posted:What kind of online quiz? One of those "WHICH FAMILY GUY CHARACTER ARE U???" type ones, or something important? Slightly more important than that type of quiz, but not terribly important. It was a quiz that the company gives its employees to see if they are knowledgeable enough to sell a certain product. I notified them about the stupidity anyways.
|
|
# ? Sep 30, 2010 01:21 |
|
Zombywuf posted:If your objects are too large to even fit in your level 2 cache then you need to start worrying about separating the key part of your data from the value, otherwise a hash table is probably the wrong structure. Judging by his description of the problem I'm going to stick with assuming w00tz0r is just wrong. You're right, I'm totally off the mark with this one. My original plan was to use a vector, since it has contiguous memory allocation, rather than a linked list; LinkedHashMap was a terrible example, I was thinking of complexity, not efficiency. I forgot we were storing pointers to the objects, not the object themselves; so even if we used a contiguous block of memory to store them, we'd still get cache misses when we went to dereference the pointers.
|
# ? Sep 30, 2010 02:13 |
|
|
# ? Apr 27, 2024 08:44 |
|
Bozart posted:else ifs + exceptions removes the need for those nested structures, doesn't take up as much room, and is easier to read. You don't need to bother with else clauses if you throw an exception. It breaks the normal program flow. That becomes less annoying if implemented as exception throwing functions though. On the other hand, you've already got the else blocks to avoid the non-linear exception handling altogether. code:
code:
|
# ? Sep 30, 2010 02:50 |