|
EpicCodeMonkey posted:I never understood why the language (or other C-derived languages, for that matter) don't make fall-through legal in switch statements, but require that the last statement in each case be "break", "return", or "continue" - the latter specifying a fallthrough. If anything else is encountered it would be a syntax error. The only downside would be that... I don't understand why you have a problem with the way it works now. It's more powerful than your idea, because the two case statements subject to the fallthrough don't have to be contiguous, and use of the goto keyword is more consistent and appropriate than continue in this case, anyway (continue being used to skip the remaining statements in a loop). Look at the first example on this page and tell me it's not more logical and flexible than what you just proposed.
|
# ? Oct 23, 2011 09:26 |
|
|
# ? May 21, 2024 02:11 |
|
EpicCodeMonkey posted:I never understood why the language (or other C-derived languages, for that matter) don't make fall-through legal in switch statements, but require that the last statement in each case be "break", "return", or "continue" - the latter specifying a fallthrough. If anything else is encountered it would be a syntax error. The only downside would be that: Expression switches In an expression switch, the switch expression is evaluated and the case expressions, which need not be constants, are evaluated left-to-right and top-to-bottom; the first one that equals the switch expression triggers execution of the statements of the associated case; the other cases are skipped. If no case matches and there is a "default" case, its statements are executed. There can be at most one default case and it may appear anywhere in the "switch" statement. A missing switch expression is equivalent to the expression true. In a case or default clause, the last statement only may be a "fallthrough" statement (§Fallthrough statement) to indicate that control should flow from the end of this clause to the first statement of the next clause. Otherwise control flows to the end of the "switch" statement. The expression may be preceded by a simple statement, which executes before the expression is evaluated. code:
|
# ? Oct 23, 2011 20:27 |
|
Don't know if this is really a horror but I laughed at itcode:
|
# ? Oct 24, 2011 16:30 |
|
Jesus Christ. Where did you find that?
|
# ? Oct 24, 2011 16:50 |
|
It's in JodaTime, https://github.com/JodaOrg/joda-time/blob/master/src/main/java/org/joda/time/chrono/BasicGJChronology.java
|
# ? Oct 24, 2011 16:51 |
|
Hahaha I love the bit shift, it's a little microcosm of everything that is wrong with that function.
|
# ? Oct 24, 2011 17:16 |
|
Aleksei Vasiliev posted:It's in JodaTime, https://github.com/JodaOrg/joda-time/blob/master/src/main/java/org/joda/time/chrono/BasicGJChronology.java Well, beats Calendar I guess
|
# ? Oct 24, 2011 17:17 |
|
Aleksei Vasiliev posted:Don't know if this is really a horror but I laughed at it I have no notion that my code gets compiled and optimized, so here is an obtuse series of nested ternary-notation comparing magic numbers.
|
# ? Oct 24, 2011 18:02 |
|
quote:If the shell is written in C++, why not just export its base classes?
|
# ? Oct 24, 2011 18:13 |
|
Aleksei Vasiliev posted:Don't know if this is really a horror but I laughed at it For the record: while this code should certainly be using named constants, and I personally would write it with if instead of nested conditionals, the three explicit optimizations here are worthwhile, and a date library is a good candidate for this degree of tuning. First, the compiler is very unlikely to be able to do the range analysis necessary to figure out that it can use 32-bit arithmetic here, but doing so is a substantial speedup on a 32-bit architecture. Second, if the code were written to divide by 86400000 instead of 1024, a good compiler would do that division with multiplies, but it would probably be blocked (again, by inadequate knowledge of the range constraints) from factoring out 84375 and getting all the way to this code. Third, while some compilers might convert a sequence of conditions into a binary search, many wouldn't, and that's not necessarily just a missing optimization: there's a lot of code that's structured so that the more likely cases are checked first. So yeah, the style could be a lot better, but the ideas are good.
|
# ? Oct 24, 2011 18:53 |
|
How often do you need to go from millis to months in a tight loop?
|
# ? Oct 24, 2011 19:50 |
|
yaoi prophet posted:How often do you need to go from millis to months in a tight loop? Even if you somehow did end up in a situation like this, you'd probably be better off optimizing the loop itself. If you really and truly need to do some millions of month look-ups, you'd probably still be better off just caching them.
|
# ? Oct 24, 2011 20:13 |
|
Standish posted:Raymond Chen's blog Where's the horror? I write OO in C all the time and while I often wish I were doing it in a language that made it easier, it remains a great way to organize and think about your code. Anyone who has read or written code that does COM in C has seen stuff that looks practically identical to this. It may seem silly to you but Chen's justifications are valid ones, especially when you consider the constraints of the early 90s.
|
# ? Oct 24, 2011 20:14 |
|
SlightlyMadman posted:Even if you somehow did end up in a situation like this, you'd probably be better off optimizing the loop itself. If you really and truly need to do some millions of month look-ups, you'd probably still be better off just caching them. This criticism is misplaced. If you were rolling your own milli-to-month converter as a tiny part of a larger project, I agree that your time would probably be better spent optimizing something else. It is not at all obvious that this is equally true of the maintainer of a date/time library. Analogously, an application programmer should not start optimizing their code by rewriting malloc, but criticizing the libc maintainers for doing so is asinine. And yes, I can imagine someone wanting to decompose timestamps into dates in a fairly tight loop.
|
# ? Oct 24, 2011 21:37 |
|
This is all theoretically true, but libc maintainers are hopefully smart enough to make their own decisions rather than be swayed by the opinions of a guy on the internet. Everyone else happens to fall into the "not a libc maintainer" category, and probably has no business writing code like that.
|
# ? Oct 24, 2011 21:52 |
|
If they need performance, why are they writing in Java in the first place? :smugC++:
|
# ? Oct 24, 2011 21:59 |
|
This is the result of the #cobol irc channel being asked to collaboratively write fizzbuzz:code:
|
# ? Oct 24, 2011 22:00 |
|
Whole lotta pent up homosexuality in that code. Just sayin'.
|
# ? Oct 24, 2011 22:05 |
|
epswing posted:
PEP3101 represent.
|
# ? Oct 24, 2011 22:10 |
|
SlightlyMadman posted:This is all theoretically true, but libc maintainers are hopefully smart enough to make their own decisions rather than be swayed by the opinions of a guy on the internet. Everyone else happens to fall into the "not a libc maintainer" category, and probably has no business writing code like that. So, to paraphrase, your opinions are above reproach because anyone smart enough to not need them is smart enough to ignore you.
|
# ? Oct 24, 2011 22:13 |
|
Everyone here realizes that Java's date/time implementation is terrible, and JodaTime is an extremely popular and widely-used date/time library, right?
|
# ? Oct 24, 2011 22:46 |
|
rjmccall posted:So, to paraphrase, your opinions are above reproach because anyone smart enough to not need them is smart enough to ignore you. Something like that. At least I'm not a dick, though.
|
# ? Oct 24, 2011 22:53 |
|
dancavallaro posted:Everyone here realizes that Java's date/time implementation is terrible, and JodaTime is an extremely popular and widely-used date/time library, right? I'm sure it performs great but god drat is that ugly.
|
# ? Oct 24, 2011 22:56 |
|
SlightlyMadman posted:Something like that. At least I'm not a dick, though. No, you're a moron
|
# ? Oct 25, 2011 01:06 |
|
Internet Janitor posted:Do they specify a level of granularity? Public methods (easy and a good idea), Lines (arbitrary), Code paths (gently caress)? Code paths. On the plus side I learned an interesting little bit about java byte code construction code:
Anybody looking for someone in the DC area to not do government work?
|
# ? Oct 25, 2011 02:31 |
|
Sign posted:Code paths. On the plus side I learned an interesting little bit about java byte code construction
|
# ? Oct 25, 2011 04:27 |
|
Sign posted:Code paths. On the plus side I learned an interesting little bit about java byte code construction And what do you think happens with: code:
|
# ? Oct 25, 2011 05:01 |
|
HORATIO HORNBLOWER posted:Where's the horror? I write OO in C all the time and while I often wish I were doing it in a language that made it easier, it remains a great way to organize and think about your code. Anyone who has read or written code that does COM in C has seen stuff that looks practically identical to this. It may seem silly to you but Chen's justifications are valid ones, especially when you consider the constraints of the early 90s. Yeah but we're in 2011 and you still need to deal with all this COM bullshit to write a shell extension. It hasn't gotten any better since the late 90's.
|
# ? Oct 25, 2011 05:25 |
|
What would you replace it with?
|
# ? Oct 25, 2011 05:31 |
|
pseudorandom name posted:What would you replace it with? Bash scripts.
|
# ? Oct 25, 2011 12:18 |
|
tef posted:No, you're a moron I'd rather work with a mediocre programmer who knows his limits, than a genius who doesn't.
|
# ? Oct 25, 2011 15:07 |
|
I suggest learning java and developing middleware. Apart from the limits bit.
|
# ? Oct 25, 2011 18:18 |
|
aleph1 posted:And what do you think happens with: Cross-thread Thread.Abort() will do the trick as well in .NET 1.0 and 1.1. It's been fixed since .NET 2.0, but TerminateThread can still abort in the middle of a finally block. e: There's a couple of .NET library calls which can call Thread.Abort if you try to access COM objects in a funny way, which is a bit of a coding horror / annoying as hell.
|
# ? Oct 25, 2011 20:07 |
|
MEAT TREAT posted:What did you think the finally clause did? I thought it did that but that it was one block of code from the perspective of coverage. As in it didn't become more than one copy of the same stuff in byte code.
|
# ? Oct 25, 2011 21:26 |
|
Sign posted:I thought it did that but that it was one block of code from the perspective of coverage. As in it didn't become more than one copy of the same stuff in byte code. It is, in fact, one block of code. The finally block itself is implemented as a subroutine (using jsr/ret), and anywhere control leaves the corresponding try block, that subroutine gets called first. But if you're going for full test coverage, you need to test every way you can get into that subroutine, rather than just testing one case and assuming that it works correctly for the others.
|
# ? Oct 25, 2011 21:53 |
|
code:
|
# ? Oct 25, 2011 23:16 |
|
So the horror is that you're confused by inheritance and virtual methods?
|
# ? Oct 25, 2011 23:23 |
|
Plorkyeran posted:So the horror is that you're confused by inheritance and virtual methods? The horror is that the base has all of it's member functions implemented as no-ops, while the derived classes copy/paste the same implementation for 90% of the code, with no indication that you're even dealing with a polymorphic class. I guess the example I posted really didn't give a sense of the scope to which everything was copied.
|
# ? Oct 25, 2011 23:28 |
|
w00tz0r posted:The horror is that the base has all of it's member functions implemented as no-ops
|
# ? Oct 26, 2011 00:50 |
|
|
# ? May 21, 2024 02:11 |
|
PrBacterio posted:That's what we in the industry like to call an "interface," and it's what the derived classes are "copying" (actually *implementing*, since, as the empty methods from the base class don't actually *do* anything there isn't any code being duplicated from there). The horror here being that all of these empty virtual methods from the base class should have been declared as abstract virtual methods (ie. virtual foo() = 0;) instead. Not according to what he said -- they're duplicating functionality. The common functionality needs to be implemented in the base class in a non-virtual method, which possibly calls some virtual/abstract methods that contain differing, implementation-specific code. Of course, I'm not sure what you're calling an "interface" there, since there are no interfaces anywhere in the example, and an interface isn't appropriate for what he was talking about anyway.
|
# ? Oct 26, 2011 01:10 |