• (cs) in reply to Bytecodes is not codebytes
    Anonymous:
    Then there must be many dinosaurs developers out there on earth then. But most of them is only dinosaurs to thoose who dont see whole picture. Take me for example. I am now using a 386 computer 32 Mb ram, sitting on a modemdial up line with a 14k4 modem in a country where we read/write from right to left using letters you probably haven't ever seen, perhaps seen but cant fit to what country

    You don't know me.  Don't assume what I know or don't know.

    Anonymous:
    we have not english as second language, I have learned some from movies, but most from porely translated instructionalbooks/tutorials.. translated from other language to english. exactly none of relatives and friends (have alot, really, we will tight together here) knows more than say 20 waords in english. And here I try discussing with you the advantage GOTO's can have in some situations.. all this in a language I hardy know. Refreshing this forum to see if you have replied takes 10 minutes for me, I guess the line to where webb-server is located is quite long.

    I will give you credit for discussing this in a non-native language but the fact is that your English is quite sufficient so I don't see it as a great barrier to discussion.

    Given your situation, perhaps you might want to consider listening to people who are immersed in newer technologies instead of dismissing them.

  • Bytecodes is not codebytes (unregistered) in reply to dubwai
    dubwai:
    Anonymous:

    the application is getting correct locations of data from a database.. it is actually not the original function, only an altered subroutine, the real one contains less constants in comparisons and alot more variables.

    Are you kidding?  What kind of screwed up design requies a method like that to find data in a database?  You do realize that IO to a DB is generally about 1000 times slower than local memory access.  So even if the Java code is 50 times slower, it won't matter.  You should do a wiki search on micro-optimization.  They might even have a page on it in your own language.

    Anonymous:

    to make a comparison, you actually don't think the raw power in googles search engine is written using classes and such do you?

    I think they use C++ but I'm not really sure.  Pretty much everything I've done for the last 7 years in my work has involved databases and I've never seen anything even approaching the ugliness of that for it.  Why do you need so much code to do such a simple task?

     

    database is not like MSSQL or something, it is inside memory, it is not with tables and such. Prehaps naming it database messed up my point in previous post. Also it is only one subroutine, and it is altered to be simplified

  • Z (unregistered) in reply to Bytecodes is not codebytes
    Anonymous:

    the application is getting correct locations of data from a database.. it is actually not the original function, only an altered subroutine, the real one contains less constants in comparisons and alot more variables. to make a comparison, you actually don't think the raw power in googles search engine is written using classes and such do you?



    I have to jump in here in your iscussion. Of course Google uses advanced modern coding techniques, specifically from functional languages. For example, their Mapreduce system automatically paralellizes and distributes computations over clusters of workstations. The implementation (if i remember correctly) is done in C++-

    Read more at http://labs.google.com/papers/mapreduce.html
  • Bytecodes is not codebytes (unregistered) in reply to dubwai
    dubwai:
    Anonymous:
    Then there must be many dinosaurs developers out there on earth then. But most of them is only dinosaurs to thoose who dont see whole picture. Take me for example. I am now using a 386 computer 32 Mb ram, sitting on a modemdial up line with a 14k4 modem in a country where we read/write from right to left using letters you probably haven't ever seen, perhaps seen but cant fit to what country

    You don't know me.  Don't assume what I know or don't know.

    Anonymous:
    we have not english as second language, I have learned some from movies, but most from porely translated instructionalbooks/tutorials.. translated from other language to english. exactly none of relatives and friends (have alot, really, we will tight together here) knows more than say 20 waords in english. And here I try discussing with you the advantage GOTO's can have in some situations.. all this in a language I hardy know. Refreshing this forum to see if you have replied takes 10 minutes for me, I guess the line to where webb-server is located is quite long.

    I will give you credit for discussing this in a non-native language but the fact is that your English is quite sufficient so I don't see it as a great barrier to discussion.

    Given your situation, perhaps you might want to consider listening to people who are immersed in newer technologies instead of dismissing them.

    Well, actually I have listened to you all the way, havn'e had the chance to reply everything,  but you seems to get irritated by such nonsense things as not replying. I carefully choose what to reply to not open up to wide discussing-subject, wheres all this would be pointless to me. Things I purposely dont reply to is most often things I decently grasp and doesn't want spend time on discussing. Things I actually reply to is things I feel just a bit uncertain about. Things where you have convinced me different is pointless discussing any more, waste of time. You seems to reply only to things you know best, and let the questionable things, for you, fluid out in the sea.

  • (cs) in reply to Bytecodes is not codebytes

    Anonymous:
    Well, actually I have listened to you all the way, havn'e had the chance to reply everything,  but you seems to get irritated by such nonsense things as not replying. I carefully choose what to reply to not open up to wide discussing-subject, wheres all this would be pointless to me. Things I purposely dont reply to is most often things I decently grasp and doesn't want spend time on discussing. Things I actually reply to is things I feel just a bit uncertain about. Things where you have convinced me different is pointless discussing any more, waste of time. You seems to reply only to things you know best, and let the questionable things, for you, fluid out in the sea.

    You seem to be describing our responses similarly.  As suggested before, the discussion can quickly branch of into to many side discussions.  I don't reply to items that I feel are off-subject or that I have no real comment on i.e. I agree or don't have an opinion.  If you feel that I should address something, please feel free ask me to address is explicitly.

  • (cs) in reply to Bytecodes is not codebytes
    Anonymous:

    database is not like MSSQL or something, it is inside memory, it is not with tables and such. Prehaps naming it database messed up my point in previous post. Also it is only one subroutine, and it is altered to be simplified

    If that is the case, then I will suggest that focusing on optimizing a method like this is not the correct approach.  The design needs to be addressed, specifically your data structure.  Such complications should not necessary for a trivial task such as finding a record.  This is the exact problem with micro-optimization.  You are focusing on whether this method executes very fast while ignoring that you shouldn't need such complications.

    If you describe what your data-structure is or the requirements, perhaps someone can suggest a more efficient approach.

  • but it blows the stack faster than the un-optimized version (unregistered) in reply to dubwai
    dubwai:
    Anonymous:

    database is not like MSSQL or something, it is inside memory, it is not with tables and such. Prehaps naming it database messed up my point in previous post. Also it is only one subroutine, and it is altered to be simplified

    If that is the case, then I will suggest that focusing on optimizing a method like this is not the correct approach.  The design needs to be addressed, specifically your data structure.  Such complications should not necessary for a trivial task such as finding a record.  This is the exact problem with micro-optimization.  You are focusing on whether this method executes very fast while ignoring that you shouldn't need such complications.

    If you describe what your data-structure is or the requirements, perhaps someone can suggest a more efficient approach.

    I hate to get into this obviously overly touchy thread... but given the fact that it requires branching between nested loops to determine the position of something I'm guessing that they have mangaged to build their own version of a hierarchical database system.  If they are having to debug each others code for logic errors simply retrieving data more than once a month... year... decade... then obviously they have not implemented it correctly either.  (I wonder what a CODASYL DB goes for these days) In any case they could probably buy a boxed RDMS which will do the whole sheebang much more obviously and safer.  I can't make a claim about execution time but in my world "right" beats "fast" everytime.

  • (cs) in reply to but it blows the stack faster than the un-optimized version
    Anonymous:

    I hate to get into this obviously overly touchy thread...

    Hey, join the party.

    Anonymous:

    but given the fact that it requires branching between nested loops to determine the position of something I'm guessing that they have mangaged to build their own version of a hierarchical database system.  If they are having to debug each others code for logic errors simply retrieving data more than once a month... year... decade... then obviously they have not implemented it correctly either.  (I wonder what a CODASYL DB goes for these days) In any case they could probably buy a boxed RDMS which will do the whole sheebang much more obviously and safer.  I can't make a claim about execution time but in my world "right" beats "fast" everytime.

    Heirarchical as opposed to relational, right?  Isn't that kind of abnormal?

    In any event, wouldn't that generally involve tree structures?  Here I see lot's of magic numbers and arithmetic that would suggest going directly at the location in memory.  A sketchy approach, at best.

  • but it blows the stack faster than the un-optimized version (unregistered) in reply to dubwai
    dubwai:
    Anonymous:

    I hate to get into this obviously overly touchy thread...

    Hey, join the party.

    Anonymous:

    but given the fact that it requires branching between nested loops to determine the position of something I'm guessing that they have mangaged to build their own version of a hierarchical database system.  If they are having to debug each others code for logic errors simply retrieving data more than once a month... year... decade... then obviously they have not implemented it correctly either.  (I wonder what a CODASYL DB goes for these days) In any case they could probably buy a boxed RDMS which will do the whole sheebang much more obviously and safer.  I can't make a claim about execution time but in my world "right" beats "fast" everytime.

    Heirarchical as opposed to relational, right?  Isn't that kind of abnormal?

    In any event, wouldn't that generally involve tree structures?  Here I see lot's of magic numbers and arithmetic that would suggest going directly at the location in memory.  A sketchy approach, at best.

    Yes its abnormal and heirarchical databases were full of optimizations to try and squeeze the last bit of performance out... that and being written in COBOL or FORTRAN or C or Assembler to remove any temptation to use useful labels or structure made them such a joy to maintain </SARCASM>

    Heck simply moving to C++ and encapsulating stuff in objects would probably reduce debug time no end... sizeoff could really help eliminate some of the magic numbers.  That is assuming thats whats going on in the magic mobius spaghetti code we are seeing here.

  • Suomynona (unregistered)

    Let's face it - the real WTF here is that so many people say that "he shoulda used continue", but don't know how continue works themselves.

    And, by the way, there are legit reasons for using goto, though the original example does not show us one of them. I wrote (among other things) a couple of state machines in the last months, and gotos are almost a must there if you care about elegance and performance. Microsoft actually agrees, that's why there's not only a goto statement in C#, but actually you do not have to add additional labels in many cases because the C# goto allows you to jump to specific case labels in the innermost switch-block of your state machine. In C++, I had to do this:


    case state_foo:
    state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto state_foo;


    In C#, you can save one redundant label and write


    case state_foo:
        // handle state foo

        break;

    case state_bar:

        // ...

        goto case state_foo;



    In both cases, it's so much easier to model an "epsilon transition" from state_bar to state_foo than in "clean", puritarian languages that ban the use of goto for the sole reason that it can be abused.

  • Bytecodes is not codebytes (unregistered) in reply to Suomynona

    Anonymous:
    Let's face it - the real WTF here is that so many people say that "he shoulda used continue", but don't know how continue works themselves.

    And, by the way, there are legit reasons for using goto, though the original example does not show us one of them. I wrote (among other things) a couple of state machines in the last months, and gotos are almost a must there if you care about elegance and performance. Microsoft actually agrees, that's why there's not only a goto statement in C#, but actually you do not have to add additional labels in many cases because the C# goto allows you to jump to specific case labels in the innermost switch-block of your state machine. In C++, I had to do this:


    case state_foo:
    state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto state_foo;


    In C#, you can save one redundant label and write


    case state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto case state_foo;


    In both cases, it's so much easier to model an "epsilon transition" from state_bar to state_foo than in "clean", puritarian languages that ban the use of goto for the sole reason that it can be abused.

     

    I use this all the time. Discussion here differenties because there are people coding "math, optimizations and so one" and there are people coding "interactive userfriendly applications". I agree with you, and will say goto should not be banned for the sole reason that it CAN be abused. There is usefulness for the function. Reason because discussing got so awkward is I believe because the goto example I posted was considered bad way of typing code, but all I wanted to demonstrate was the goto label inside nested loops fenomen, and how difficult that logic is to implement in Java-language because of lack of goto command.

  • poon (unregistered) in reply to Bytecodes is not codebytes

    <!--StartFragment --><FONT color=#000000>Bytecodes is not codebytes - would you be able to give us a higher-level description of the what the application your code snippet comes from actually does?</FONT>

    I'm interested to see what sort of problem requires a solution of that form.

     

  • poon (unregistered) in reply to poon

    WTF? First the forum eats my post when I type it in Firefox, then when I submit it from IE it does weird things to the font. It really /is/ that bad, isn't it.

  • (cs) in reply to Bytecodes is not codebytes

    Discussion here differenties because there are people coding "math, optimizations and so one" and there are people coding "interactive userfriendly applications". I agree with you, and will say goto should not be banned for the sole reason that it CAN be abused

    No, goto should be banned because it completely fucks up code readability, and thus maintainability. By the time you've learned enough programming to be able to use goto in a relatively sane way, you should also know a shitload of other ways to solve the same problem in a readable manner. And hopefully, you will use one of them.

    If you're writing math, optimisations and so on, you're not going to be using goto either. Because you're going to be unrolling loops. And when you're really optimising, conditionals and branches fuck things up. In a major way.

    There are cases where goto is useful, but they are very few and far between, and generally involve code that's being written at an extremely low level that needs to spin in cache on older processors. The LKML thread linked earlier in the discussion covers this - in this context, compiled code size is absolutely premium. For 99% of programmers, this is most certainly not the case. Even then, one has to be very careful, as all compilers are not equal, and neither are the platforms they target : something that is hyper-efficient on one platform may well run like an absolute dog on another.

    I've probably used goto about twice a year (average, I don't think I've actually shipped goto-using-code for over 5 years, but that is possibly an indicator of how my coding emphasis has changed recently) in the last 20 years of doing commercial development (not counting the assembler stuff). In all cases it was caused either by the language in question not providing the necessary constructs to get around it, or an absolute need as discussed above.

    I believe because the goto example I posted was considered bad way of typing code,

    Yeah, I'd consider it an acceptable reason for contract termination :)

    but all I wanted to demonstrate was the goto label inside nested loops fenomen, and how difficult that logic is to implement in Java-language because of lack of goto command.

    What you've actually demonstrated, in fact, is that it's a problem that is inherently hard to solve elegantly when your chosen language doesn't provide the tools you need.

    Your C version was concise and completely obfuscated. A relatively clever piece of code, but far from readable.

    The Java version posted later was fairly average Java (I'm not knocking the coder here, but the language) - neither (particularly) elegant nor concise, but at least readable.

    Both of them require source code changes should the state machine change.

    I'd give you a ruby, lisp, or smalltalk version (and I'm fairly sure that I could do it elegantly in perl too, despite the fact 'elegantly' and 'perl' are often orthogonal to one another) that could handle changing requirements without source code changes; all of these languages provide the tools to do the job at hand in an elegant and readable manner - but this forum software continually fucks up my posts to the point where I'm afraid to post anything other than plain text.

    This is not to say that 'X is better than Y' - such arguments are pointless and childish, but instead that certain languages are better than others for solving particular problems.

    Simon

  • Z (unregistered) in reply to dubwai
    dubwai:

    Apparently 'fact' is another word you are not really understanding.  Why can't a JVM be optimally coded?  Why can't something writen in C be as fast as something written in C?



    I stumbled upon an interesting study on the performance of bytecode versus C-code that you may be interested in. The context was a compiler for Scheme, and the study measures the difference between C-code they generate, and bytecode they generate. You may find it at http://www-sop.inria.fr/oasis/Bernard.Serpette/bib/icfp02.ps

    (Maybe not the best quote, but it was a long thread. )
  • LordOfThePigs (unregistered) in reply to Suomynona
    Anonymous:

     In C++, I had to do this:

    case state_foo:
    state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto state_foo;


    In C#, you can save one redundant label and write


    case state_foo:
        // handle state foo

        break;

    case state_bar:

        // ...

        goto case state_foo;



    That would be a bad example since a simple fall-through would work just as well. Consider:

    case state_bar:
        //...
    case state_foo:
        // handle state foo
        break;

  • Bytecodes is not codebytes (unregistered) in reply to LordOfThePigs

    Anonymous:
    Anonymous:

     In C++, I had to do this:

    case state_foo:
    state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto state_foo;


    In C#, you can save one redundant label and write


    case state_foo:
        // handle state foo
        break;
    case state_bar:
        // ...
        goto case state_foo;



    That would be a bad example since a simple fall-through would work just as well. Consider:

    case state_bar:
        //...
    case state_foo:
        // handle state foo
        break;

    That would be a bad example since you don't have a single clue what code is above this code. A simple fall-through to state_foo would now be a fall-through to state_bar.

  • (cs) in reply to Z

    Z:

    I stumbled upon an interesting study on the performance of bytecode versus C-code that you may be interested in. The context was a compiler for Scheme, and the study measures the difference between C-code they generate, and bytecode they generate. You may find it at http://www-sop.inria.fr/oasis/Bernard.Serpette/bib/icfp02.ps

    (Maybe not the best quote, but it was a long thread. )

    Interesting.  But it's about a scheme-to-JVM bytecode compiler.  Not being a bytecode expert, it's hard for me to determine whether their compiler is good or not.  They admit in the beginning that bytecodes have to be specially crafted to avoid defeating the JIT compiler.

  • (cs) in reply to tufty

    tufty:
    The Java version posted later was fairly average Java (I'm not knocking the coder here, but the language) - neither (particularly) elegant nor concise, but at least readable. Both of them require source code changes should the state machine change.

    The Java version I posted was not what I would call "good code."  It was basically a mechanical conversion of the C code to Java.  Without understanding exactly what the point of the code was, it was difficult to do anything more.  Besides, the only intent was to give the bare-minimum proof of the existance of a conversion.  I wager that given the requirements, my 'optimal' solution would look very different (better.)

  • Z (unregistered) in reply to dubwai
    dubwai:

    Z:

    I stumbled upon an interesting study on the performance of bytecode versus C-code that you may be interested in. The context was a compiler for Scheme, and the study measures the difference between C-code they generate, and bytecode they generate. You may find it at http://www-sop.inria.fr/oasis/Bernard.Serpette/bib/icfp02.ps

    (Maybe not the best quote, but it was a long thread. )

    Interesting.  But it's about a scheme-to-JVM bytecode compiler.  Not being a bytecode expert, it's hard for me to determine whether their compiler is good or not.  They admit in the beginning that bytecodes have to be specially crafted to avoid defeating the JIT compiler.



    I thought it interesting mostly because it is an example of a team that has been working hard to generate the exact same program in both bytecode and C. My impression is that the Bigloo compilers are good soplid compilers that generate fast code.

    The fact that they must take the current JITs into account to generate fast code is symptomatic of the Java platform. There are numerous bugs in most JVM-implementations (especially Sun's) that anly arise when another language than Java is compiled to bytecode.

    But I concede, it may not be wholly relevant for Java-performance :)
  • (cs) in reply to Z
    Anonymous:
    dubwai:

    Z:

    I stumbled upon an interesting study on the performance of bytecode versus C-code that you may be interested in. The context was a compiler for Scheme, and the study measures the difference between C-code they generate, and bytecode they generate. You may find it at http://www-sop.inria.fr/oasis/Bernard.Serpette/bib/icfp02.ps

    (Maybe not the best quote, but it was a long thread. )

    Interesting.  But it's about a scheme-to-JVM bytecode compiler.  Not being a bytecode expert, it's hard for me to determine whether their compiler is good or not.  They admit in the beginning that bytecodes have to be specially crafted to avoid defeating the JIT compiler.



    I thought it interesting mostly because it is an example of a team that has been working hard to generate the exact same program in both bytecode and C. My impression is that the Bigloo compilers are good soplid compilers that generate fast code.

    The fact that they must take the current JITs into account to generate fast code is symptomatic of the Java platform. There are numerous bugs in most JVM-implementations (especially Sun's) that anly arise when another language than Java is compiled to bytecode.

    But I concede, it may not be wholly relevant for Java-performance :)

    Another thing about this is that it appears to be from 2002 or 2003.  The 1.5 compiler and JVM are reportedly significantly faster than the previous version which was is in turn supposedly faster than 1.3.  According to this document they use 1.3 in 'client' mode.  I'm not sure why they used 'client' mode as server mode is much faster.

    So I'd be interested to see how the use of the newest JVM in 'server' mode fares.  I'm really confused about why they used 'client' mode.  It's like putting weights on a runner's legs in a race.

  • Z (unregistered) in reply to dubwai
    dubwai:

    Z:

    I stumbled upon an interesting study on the performance of bytecode versus C-code that you may be interested in. The context was a compiler for Scheme, and the study measures the difference between C-code they generate, and bytecode they generate. You may find it at http://www-sop.inria.fr/oasis/Bernard.Serpette/bib/icfp02.ps

    (Maybe not the best quote, but it was a long thread. )

    [snip]

    Another thing about this is that it appears to be from 2002 or 2003.  The 1.5 compiler and JVM are reportedly significantly faster than the previous version which was is in turn supposedly faster than 1.3.  According to this document they use 1.3 in 'client' mode.  I'm not sure why they used 'client' mode as server mode is much faster.

    So I'd be interested to see how the use of the newest JVM in 'server' mode fares.  I'm really confused about why they used 'client' mode.  It's like putting weights on a runner's legs in a race.



    I'm sorry to say that I don't have any good answers to your questions. My general impression from this kind of papers (aka scientific papers), is that when something is slightly odd, like only using clinet-mode, then there is usually some explanation for it, although the strict page limits for the papers prohobits any lenghtier explanation about it.

    One guess could be that server-mode does something which is appropriate for a compiled Java-program, but not for a general bytecode-program.
  • (cs) in reply to Z

    Z:

    I'm sorry to say that I don't have any good answers to your questions. My general impression from this kind of papers (aka scientific papers), is that when something is slightly odd, like only using clinet-mode, then there is usually some explanation for it, although the strict page limits for the papers prohobits any lenghtier explanation about it.

    One guess could be that server-mode does something which is appropriate for a compiled Java-program, but not for a general bytecode-program.

    Well, it doesn't really matter I guess.  The paper's conclusion is tha the JVM performance is 'acceptable' which kind of backs up my point.  I had a thought about this today: the BigLoo compiler has been around for a while, right?  It's probably gone through several or more developement iterations.  One would hope that most of these iterations improved the performance.  This paper kind of sounds like the bytecode version is brand new.  It may be htat there are improvements to be had in this compiler on top of the improvements to the JVM.

  • Bill Kerney (unregistered) in reply to dubwai

    Ok, a bunch of semi-related points:

    1. A lot of people have made statements like, "Most of the time programmer time is more valuable than CPU time." This is my most common mindset. I live by it most of the time, and use PHP, Java, etc. -- all the "slow" languages, because not having to rewrite a data structure in C saves the project more time than the millisecond I might shave off my execution time.

    That said -- SOMETIMES SPEED DOES MATTER. Just as hard as it is to believe to people to recite the above line as dogma, sometimes speed does matter. I have a Master's in High Performance Computing. Why don't we use java to do HPC? There was actually a conference on this. Lot of great ideas, but the upshot is that when you're in a field where a 20% improvement in speed is worth a paper, accepting a 2x slowdown just to be able to use java isn't worth it. Turing equivalence works both ways -- and this is a field where people care very highly how long a code takes to run. Some applications are real-time, some are time-critical, and some are long running. When you have a code that takes a year to run, let's say, you sorta care if you retool into java and suddenly have to wait two years to get your results. Or if you are writing code that spots terrorists in an airport queue before they make it through security, you only have a fixed amount of time to do it in, and wishful thinking won't make it any better.

    Oddly enough, we found C isn't the fastest language. For a math kernel that gets executed billions of times in the course of a computation we actually use fortran. Switching from a C kernel to a fortran kernel (less than a page of fortran code in its entirety) resulted in a noticeable speedup. And before you bust out the pitchforks and torches, you should realize that a function call to a kernel in a different language (with a makefile handling the compiling and linking) is appallingly easy and clean to do.

    2) Sometimes gotos are necessary. Again, people will want to bust out the pitchforks. Try writing a thread manager without using setjmp and longjmp. Sure, you can argue that setjmp and longjmp are C Functions, and thus "totally okay" to use, vs gotos and labels, but a rose by any other name is still the same. Hell, the manpage for setjmp: "save stack context for non-local goto".

    Turing equivalence: can Java even do this? I've used Java a lot, but have never had cause to investigate the more arcane areas of coding in Java, using it more for nice friendly stuff. You could probably cheat and use java threads to implement a thread manager, but then the professor would probably give you an F, just as if you tried using the STL when writing your first red-black tree in C++.

    The point is, the world isn't always a perfect place, and someone, somewhere needs to write thread managers, device drivers, and kernels, no matter how it seems implausable to some of you.

    I use what exists if it exists, and never invent the wheel. But if it the wheel doesn't exist, like I'm back in the stone age on some sort of embedded processor, I better damn well know how to write it myself.

    3) Java. Can't tell you how many java standard objects/funtions I've had to rewrite because the platform's implementation I was using was hideous. Java is supposedly write once run anywhere. But their head-in-the-sand attitude ignores the fact that intra-version differences in java are one of the most frustrating experiences you'll ever have to deal with, especially since they went and dogmatically removed the preprocessor. Try running on a platform whose developers are lazy and a version or two out of date, and watch your code start crying when java standard functions go missing. Watch as your code is depricated in one place and nonexistant in another.

    Using Java on uncommon platforms (like IRIX) is painful -- which is ironic since the entire point of the language is to be code portable. Yet when I wrote a C-server with a Java client, the C was way more portable. Took it from IRIX to Solaris, fixed a couple cross-platform function incompatibilities, boom done. Fixing the java code to work on both platforms was like kicking myself in the teeth. Rewriting standard functions is something I want to do in a basic CS class, not something in a production environment.

    Scroll down and look at the wonderful medley of java offerings from SGI, sorted conveniently by what is available by what version of IRIX:
    http://www.sgi.com/products/evaluation/#jdk

    What's worse is when there's actual bugs in the platform's java implementation... never thought there could be a memory leak in java? Watch what happens when the garbage collector decides it doesn't want to run. Ever. :/

    4) Cache is a bigger deal than people think. A classic problem with parallelizing code is that there are two main sections of parallel code, the computation phase, and the communication phase (as each processor syncs with each other). A classic operation (to simplify things) is to start with a large array, NxN, and iterate across it, setting each array element equal to the average of its neighbors. The array is iterated across many many times, until the global delta drops below a certain point, meaning the array is "done". When you parallelize this, you split the array across all the processors. They iterate across their chunk, then transmit the new values to their neighbors on each side. The problem becomes, that as you add more and more processors, your computation time shrinks and shrinks (since you're throwing more cycles at it), but your communication time grows and grows, because you're increasing the surface area of the problem.

    Students beginning studies of parallel processing plot graphs of the performance as you add processors. Typically, it will start by increasing linearly, then taper off, then level off flat, then start falling. This is the classic graph.

    Now, to come to my point, the weird part is that sometimes as you add processors, you will get superlinear speedup. In other words, you multiply the number of processors by 2, but the process runs 3 times as fast. WTF? According to the textbooks, this is impossible!

    What has happened is that the chunk of the array suddenly fit into one of the caches, and so the execution speed shot through the roof, since it doesn't need to hit the next slowest level of memory whatever that is: L2 cache, L2.5 cache, L3 cache, main memory, local NUMA memory, paged memory, whatever.

    A lot of work on compilers is how to reorder loops to maximize cache performance. It's a Really Big Thing.

    So to come to my point, the Linux kernel folks are absolutely right to use goto statements, when they reduce code size. A kernel is a place where you really, really, want your code to run fast. When gotos can be eliminate instructions (and we've moved beyond turing equivalence now... we're in the real world), and indeed, there are a number of cases where gotos will give a significant savings, it should be done as long as:

    1) Speed actually matters (instead of pretending that speed actually matterss, a trap most CS people fall into).

    2) The code will still be readible. The linux kernel code is quite readible, even though it uses gotos.

    3) The code will still be maintainable (i.e. you can play with the code around the goto statements without suddenly breaking everything all to hell).

    or

    1) There's no other way to do it. I'm curious if you can write a thread manager without using setjmp & longjmp or "rose by any other name" equivalents while not completely b0rking their code into unreadability.

    Hell, I never use gotos in anything I write. I don't even consider it in cases where they might help. But there are uses for it, and since this WTF appears to be something involving something low-level, it might not be a WTF at all, at least for this matter.

    As for the guy who posted the weird recursive code problem, you could probably solve it with that other guy's solution, but just simulating a stack to keep track of where you were. I dunno if you count that as a tremedous speed hit or not. Hell, if it works for you, leave it as it is. My philosophy is to leave most code well enough alone, but in those cases where speed does matter, PROFILE, and see if this function really matters. Then test a couple different algorithm designs -- compilers have a funny way of not always doing what you think. If your version with gotos is indeed the fastest, after trying 2 or 3 different version of it, then hell, use it if the performance matters that much.

    Turning equivalence means you can always rewrite code to get rid of gotos (except maybe in the case of the thread manager), but it says nothing about performance.

    -Bill Kerney
  • Z (unregistered) in reply to dubwai
    dubwai:

    Well, it doesn't really matter I guess.  The paper's conclusion is tha the JVM performance is 'acceptable' which kind of backs up my point.  I had a thought about this today: the BigLoo compiler has been around for a while, right?  It's probably gone through several or more developement iterations.  One would hope that most of these iterations improved the performance.  This paper kind of sounds like the bytecode version is brand new.  It may be htat there are improvements to be had in this compiler on top of the improvements to the JVM.



    I realised that I hadn't posted the obvious link yet, http://shootout.alioth.debian.org/, The Great Programming Language Shootout. A page for, you guessed it, comparing the performance of different languages under different compilers on the same set of problems. Always a fun place to look at.
  • (cs) in reply to Zahlman
    Anonymous:

    Bah.

    int foo() {
    void *res1 = *res2 = *res3 = *res4 = *res5 = NULL;
    int result = -1;

    /* Conditionally allocate stuff on previous allocation.
    As soon as anything fails, the rest will fail */
    res1 = alloc_res1();
    res2 = res1 && alloc_res2( res1 );
    res3 = res2 && alloc_res2( res2 );
    res4 = res3 && alloc_res2( res3 );
    res5 = res4 && alloc_res2( res4 );

    if (res5) {
    do_something( res5 );
    result = 0;
    dealloc_res( res5 );
    }

    /* Deallocate everything which actually got allocated. */
    if (res4) dealloc_res( res4 );
    if (res3) dealloc_res( res3 );
    if (res2) dealloc_res( res2 );
    if (res1) dealloc_res( res1 );
    return result;
    }

    Although in C++ you would probably solve the problem with RAII. And personally, I’ve never run into a need for anything like this (which is always the common example) “in all my years”.

    • That is only conceivable because of the simplistic structure of the example I posted. If each step, particularly their interdependencies, were realistically complex, it wouldn’t be this easy to unwind.
    • It doesn’t work, since 10 && 20 is 1, not 20. This is C, not Perl or whatever other language…
    emurphy:
    (I’m guessing that Aristotle intended to use those functions, but copy+pasted and missed making the appropriate changes.)

    Yeah, sorry, I slipped. I spent way too long writing that bit of example code as is…

    dubwai:

    I’ll just point out that I am not sayng that Java is for everything.  I just get tired of the ‘Java is slow’ comments.  It’s just not true.  All the ‘real programmers’ (as in Mel) can waste their licves doing what compilers can do better for all I care.

    See, I don’t understand this. If I want to get high programmer throughput, I’ll pick Perl. Or maybe I’d pick Python or Ruby if I were so inclined – I don’t really care. (I have personal preferences, but I’m not religious about what others want to use.) If I want high performance, I’ll probably pick C. Y’see, I do know that Java has gotten fast enough after a decade of twiddling the underlying technology – but my experience with GUIs written in Java has been craptacular and small utilities take ages to load. JVMs are still memory hungry as ever and have a really noticable startup overhead. So it seems to be useful only for long-running, multithreaded stuff in the first place; but I can’t quite figure out what Java would be best for that wouldn’t be better served another way.

    tufty:
    Generally speaking, if OO has been done in a given piece of C code, the chances are it’s been done by someone who knows what they are doing, and it won’t be as WTF-loaded as the average bit of VB.

    gtk+ [:)]

    dubwai:
    yawn… Without explaining the state pattern I’ll just give the naive implementation.

    Do you seriously want me to believe that you find your translation more readable than the originally posted code? go_to = OP3; break; is better than goto OP3;, how, exactly?

    I agree that the second example he posted looked like… something unprintable, but the first example was a clearly more readable with the gotos rather than as a looped-wrapped switch (a WTF in and of itself, if you ask me…). The code you posted for the second example looks too wordy to be right, but then I didn’t bother reading the original pile of dung hard enough to understand it, so hat off that you even tried.

    In other news, I think Bill Kerney just made all the points to conclude this discussion.

  • (cs) in reply to Aristotle Pagaltzis
    Aristotle Pagaltzis:
    dubwai:

    I’ll just point out that I am not sayng that Java is for everything.  I just get tired of the ‘Java is slow’ comments.  It’s just not true.  All the ‘real programmers’ (as in Mel) can waste their licves doing what compilers can do better for all I care.

    See, I don’t understand this. If I want to get high programmer throughput, I’ll pick Perl. Or maybe I’d pick Python or Ruby if I were so inclined – I don’t really care. (I have personal preferences, but I’m not religious about what others want to use.) If I want high performance, I’ll probably pick C. Y’see, I do know that Java has gotten fast enough after a decade of twiddling the underlying technology – but my experience with GUIs written in Java has been craptacular and small utilities take ages to load. JVMs are still memory hungry as ever and have a really noticable startup overhead. So it seems to be useful only for long-running, multithreaded stuff in the first place; but I can’t quite figure out what Java would be best for that wouldn’t be better served another way.

    Perl might speed-up programming throughput but is absolutely a disaster in terms of maintainablity.  It's too unstructured.  I would never use it for something that is to be enhanced and maintained by a team of dozens.  Java has this over C and C++ too.  The syntax of Java is much more limited than that of C or C++.  When you are working with a lot of developers and a lot of turn-over (contractors) it's a huge bonus to be able to look at the code and know most if not all the syntax rules that are possible.  No operator overloading, no defines.  I can look at a Java snippet of any size and know what it does without question.  It's a spartan language.  I would rather spend my time contemplating and analyzing design than learning a lot of silly tricks.

    People often point out Java GUIs but this is a red-herring.  Java has no native support for GUIs so this really has nothing to do with the Java language.  It's a complaint about a set of classes written in Java.  I can almost guarantee that you are referring to GUIs built with Swing which is one of three commonly used GUI frameworks.  The problem with Swing isn't that it's written in Java, it's that the approach is wrong.  The idea was to make a single framework for all platforms.  To do this, all the widgets are created in Java from very basic OS components.  This is slow approach, regardless of the language.  IBM has a framework SWT which leverages the OS as much as possible and only draws components not available on the platform on it's own.  SWT GUIs are generally indistiguishable from non-Java applications.

    What's memory hungry?  The JVM has a little overhead but nothing that should tax any reasonably modern computer.  As far as startup times go, I have a command-line regex utility that I wrote in a day or so that runs instantaneously as far as I can tell; at least once my virus scan has looked it over.  If you want fast, why not use Fortran?  It's faster than C.

    Aristotle Pagaltzis:
    dubwai:
    yawn… Without explaining the state pattern I’ll just give the naive implementation.

    Do you seriously want me to believe that you find your translation more readable than the originally posted code? go_to = OP3; break; is better than goto OP3;, how, exactly?

    I don't understand why people on forums will attack examples meant to show one thing as not showing something completely different.  The challenge was to create equivalent logic in Java.  I don't have time to rewrite unknown code with zero comments into a clean form for this forum.  I executed a specific task which had nothing to do with making the code 'better'.

    Aristotle Pagaltzis:

    I agree that the second example he posted looked like… something unprintable, but the first example was a clearly more readable with the gotos rather than as a looped-wrapped switch (a WTF in and of itself, if you ask me…). The code you posted for the second example looks too wordy to be right, but then I didn’t bother reading the original pile of dung hard enough to understand it, so hat off that you even tried.

    Like I point out above, the version I gave was a mechanical translation of the code.  I didn't think about it, I just 'cut-paste and edit'ed to get the equivalent code in Java.  If I had the requirements, chances are I would rewrite it entirely differently.

  • (cs) in reply to dubwai

    dubwai:

    Aristotle Pagaltzis:
    dubwai:
    yawn… Without explaining the state pattern I’ll just give the naive implementation.

    Do you seriously want me to believe that you find your translation more readable than the originally posted code? go_to = OP3; break; is better than goto OP3;, how, exactly?

    I don't understand why people on forums will attack examples meant to show one thing as not showing something completely different.  The challenge was to create equivalent logic in Java.  I don't have time to rewrite unknown code with zero comments into a clean form for this forum.  I executed a specific task which had nothing to do with making the code 'better'.

    Aristotle Pagaltzis:

    I agree that the second example he posted looked like… something unprintable, but the first example was a clearly more readable with the gotos rather than as a looped-wrapped switch (a WTF in and of itself, if you ask me…). The code you posted for the second example looks too wordy to be right, but then I didn’t bother reading the original pile of dung hard enough to understand it, so hat off that you even tried.

    Like I point out above, the version I gave was a mechanical translation of the code.  I didn't think about it, I just 'cut-paste and edit'ed to get the equivalent code in Java.  If I had the requirements, chances are I would rewrite it entirely differently.

    Okay, now let us recall:

    Anonymous:

    I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near. If you do that I will will present a more complex function for you. When you have replied with equivalent code in Java then I will transform into a Java-developer and will never touch any other language again.

    Okay, here is your tasks, the simple one:    (I present the complex one for you if you are interested enough, first off you have to translate this one)

    Suggested Tasklist:

    Task #:   Task (difficulty level)

    1:   Try see the logic so you can translate it to Java. (Quite cumbersome)

    2:   Write same code in Java (Very difficult)

    3:   Have it execute faster than my C code (Impossible)

    I think the task is quite specific "I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near.".. The suggested tasklist was just what it reads, a suggested tasklist, nothing more ;)

    Congrats for finnish suggested tasklist number 1 and 2, sorry to say but anyone could have done that. But of course, by looking at words inside the paranthesis, it is clearly task #3 that is the true point in my post. Also, that is just the suggested tasklist, not the specific task at all.

    dubwai:

    I don't understand why people on forums will attack examples meant to show one thing as not showing something completely different.

    Yeah I really wonder why... why do you do such things?

  • (cs) in reply to Bill Kerney

    Bill Kerney:

    That said -- SOMETIMES SPEED DOES MATTER. Just as hard as it is to believe to people to recite the above line as dogma, sometimes speed does matter. I have a Master's in High Performance Computing. Why don't we use java to do HPC? There was actually a conference on this. Lot of great ideas, but the upshot is that when you're in a field where a 20% improvement in speed is worth a paper, accepting a 2x slowdown just to be able to use java isn't worth it. Turing equivalence works both ways -- and this is a field where people care very highly how long a code takes to run. Some applications are real-time, some are time-critical, and some are long running. When you have a code that takes a year to run, let's say, you sorta care if you retool into java and suddenly have to wait two years to get your results. Or if you are writing code that spots terrorists in an airport queue before they make it through security, you only have a fixed amount of time to do it in, and wishful thinking won't make it any better.

    I have not argument with this.  I don't know why people interpret 'Java isn't slow' to mean 'Java is as fast an anything else'.  Is a Testarossa, slow?  If you answer no, I'll point out that it's not as fast as a SR-71 Blackbird, so you are clearly wrong.

    In the real world that you mentioned, the vast majority of applications are not high-performance computing applications.  Especially not in IT which is where Java is mostly used.  The average developer that thinks that Java is too slow for his app is just having delusions of grandeur.  My experience is that a lot of people who think that Java is too slow have written or seen apps that were poorly written.  Writing an app well in Java can be suprisingly difficult.  There is also a lot of wrong-headed adivce out on the internet about how to develop Java applications.  Most of it is old but people still follow it.

    The other points you made about how Java didn't work in certain less used environments doesn't make much sense.  The problem is that the JRE for that platform doesn't exist or is poorly implemented.  I fail to see how that is a problem with Java.  If the C or C++ compiler for that environment were similarly dsyfunctional, would you blame C?

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    dubwai:

    Aristotle Pagaltzis:
    dubwai:
    yawn… Without explaining the state pattern I’ll just give the naive implementation.

    Do you seriously want me to believe that you find your translation more readable than the originally posted code? go_to = OP3; break; is better than goto OP3;, how, exactly?

    I don't understand why people on forums will attack examples meant to show one thing as not showing something completely different.  The challenge was to create equivalent logic in Java.  I don't have time to rewrite unknown code with zero comments into a clean form for this forum.  I executed a specific task which had nothing to do with making the code 'better'.

    Okay, now let us recall:

    Anonymous:

    I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near. If you do that I will will present a more complex function for you. When you have replied with equivalent code in Java then I will transform into a Java-developer and will never touch any other language again.

    Okay, here is your tasks, the simple one:    (I present the complex one for you if you are interested enough, first off you have to translate this one)

    Suggested Tasklist:

    Task #:   Task (difficulty level)

    1:   Try see the logic so you can translate it to Java. (Quite cumbersome)

    2:   Write same code in Java (Very difficult)

    3:   Have it execute faster than my C code (Impossible)

    I think the task is quite specific "I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near.".. The suggested tasklist was just what it reads, a suggested tasklist, nothing more ;)

    Where does that task list specify that the code must be better (more readable) than the original?  The code I posted was equivalently readable to yours as it was basically the same code.

    I think you should take a class in logic.

  • (cs) in reply to dubwai
    dubwai:
    Bytecodes is not codebytes:

    dubwai:

    Aristotle Pagaltzis:
    dubwai:
    yawn… Without explaining the state pattern I’ll just give the naive implementation.

    Do you seriously want me to believe that you find your translation more readable than the originally posted code? go_to = OP3; break; is better than goto OP3;, how, exactly?

    I don't understand why people on forums will attack examples meant to show one thing as not showing something completely different.  The challenge was to create equivalent logic in Java.  I don't have time to rewrite unknown code with zero comments into a clean form for this forum.  I executed a specific task which had nothing to do with making the code 'better'.

    Okay, now let us recall:

    Anonymous:

    I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near. If you do that I will will present a more complex function for you. When you have replied with equivalent code in Java then I will transform into a Java-developer and will never touch any other language again.

    Okay, here is your tasks, the simple one:    (I present the complex one for you if you are interested enough, first off you have to translate this one)

    Suggested Tasklist:

    Task #:   Task (difficulty level)

    1:   Try see the logic so you can translate it to Java. (Quite cumbersome)

    2:   Write same code in Java (Very difficult)

    3:   Have it execute faster than my C code (Impossible)

    I think the task is quite specific "I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near.".. The suggested tasklist was just what it reads, a suggested tasklist, nothing more ;)

    Where does that task list specify that the code must be better (more readable) than the original?  The code I posted was equivalently readable to yours as it was basically the same code.

    I think you should take a class in logic.

     

    I think you should take a class in quoting right, to not let out important relevant information.
    I think you should take a class in reading between the lines, try see the points in sentences without taking exactly everything literally.

  • (cs) in reply to Bytecodes is not codebytes

    I think you should take a class in quoting right, to not let out important relevant information.

    He said, quoting exactly what dubwai posted / quoted, and presumably leaving out exactly the same "important relevant information"...

    I think you should take a class in reading between the lines, try see the points in sentences without taking exactly everything literally.

    Where's the fun in that?

    Holy flying spaghetti monster, when did this become alt.im.a.fucking.pedant?

    Oh. Yes. Bugger.

    Simon

  • (cs) in reply to tufty

    tufty:
    > I think you should take a class in quoting right, to not let > out important relevant information. He said, quoting exactly what dubwai posted / quoted, and presumably leaving out exactly the same "important relevant information"... >I think you should take a class in reading between the > lines, try see the points in sentences without taking > exactly everything literally. Where's the fun in that? Holy flying spaghetti monster, when did this become alt.im.a.fucking.pedant? Oh. Yes. Bugger. Simon

     

    I wrote he needs a class in quoting, and included a post from him where he clear and obvious  leaved out "important relevant information". How is this quote not relevant to what I wrote about quoting? is this logic hard for you?...do you actually mean I should quote a post WITHOUT missing  "important relevant information" and then comment that with "you need a class in quoting". How wierd wouldn't that be/look?

     



     

  • (cs) in reply to dubwai

    After reading this whole thread for the last four hours, I feel the urge to say something.

    @dubwai: hats off for your engagement in this thread. Your Java code was (given the minimalistic specs off the problem at hand) the strike of a genius. I would never have thought off this kind of solution and I would call myself an experienced Java programmer.

    @dubwai and Bill Kerney: I actually find the arguments of both of you very strong and sound.

    To use goto's or not  is not a dogma, it is a decision. And as with all decisions, they can be well- or ill-founded. Java (the language) has no goto, and with respect to my experience it does not need one. Java is aimed for what I call "the application domain", that is business logic, frontends, high-level-of-abstraction-servers, and so on. It never was and never will be aiming for tasks like writing next Linux Kernel, the "Next Generation <place vendor name here> Database Kernel", or the emulation of how fusions bombs explode, the weather will be in the future or how the universe came to existence. This whole discussion between the three of you is actually not about "To Goto Or Not To Goto", it is about choosing the right tool for the task at hand. Yes, you might be able to drive a nail into the wall using a screwdriver, but a hammer would be more appropriate. Equivalently one has to choose between the numerous programming languages (and runtime environments), and it is nothing wrong with the languages you choose NOT to use. Hence all this "Java is (not) slow", "C is better than Java", discussions are moot, it is like mothers discussing who has the best child. It's an emotional discussion, that will more often show the dishonoring human sides of the participants, than it will produce any real arguments. (Thow especially Bill made some very good points there.)

    @bytecodes is not code-bites: I would actually like to see the real code you claim the reduced function you posted here comes from. I would recommend,  you send it to Alex as a proposal for a major WTF. And honestly, it is a WTF, not because of the goto's, but because of what you call "readability" and of course because of it's total lack maintainability. Actually until you present me your original code, I will assume you made this whole thing up and, yes, this means I call you a liar straight in your face. However, if it is real code, then I take it back and will live happily until the day I die, because of the thought that I am certainly not the guy who will have to maintain your code, because where I live, we write from left to right.

    cu

    p.s.: I think I made enough spelling and grammar mistakes to illustrate, that I am also not a native English speaker (and writer for that matter).

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    I think you should take a class in quoting right, to not let out important relevant information.
    I think you should take a class in reading between the lines, try see the points in sentences without taking exactly everything literally.

    So I was suppose to show what you were thinking about asking, not what you actually asked.  Again, take a class in logic.  It's clearly not coming naturally to you.

    Here's what you have done:  You asked me to deomonstrate something that you though couldn't be done.  Then when I did it, you claim I didn't do it well enough or meet your unspecified requirements.  Stop wasting your limited bandwidth with this stupidity.  You aren't king of the fourms, I don't owe you anything.  You ask me to do work and answer your questions but refuse to return the favor.

    Stop acting like an insolent child and I'll stop treating you like one.

  • (cs) in reply to eagle

    eagle:
    After reading this whole thread for the last four hours, I feel the urge to say something.

    @dubwai: hats off for your engagement in this thread. Your Java code was (given the minimalistic specs off the problem at hand) the strike of a genius. I would never have thought off this kind of solution and I would call myself an experienced Java programmer.

    @dubwai and Bill Kerney: I actually find the arguments of both of you very strong and sound.

    To use goto's or not  is not a dogma, it is a decision. And as with all decisions, they can be well- or ill-founded. Java (the language) has no goto, and with respect to my experience it does not need one. Java is aimed for what I call "the application domain", that is business logic, frontends, high-level-of-abstraction-servers, and so on. It never was and never will be aiming for tasks like writing next Linux Kernel, the "Next Generation <PLACE here name vendor>Database Kernel", or the emulation of how fusions bombs explode, the weather will be in the future or how the universe came to existence. This whole discussion between the three of you is actually not about "To Goto Or Not To Goto", it is about choosing the right tool for the task at hand. Yes, you might be able to drive a nail into the wall using a screwdriver, but a hammer would be more appropriate. Equivalently one has to choose between the numerous programming languages (and runtime environments), and it is nothing wrong with the languages you choose NOT to use. Hence all this "Java is (not) slow", "C is better than Java", discussions are moot, it is like mothers discussing who has the best child. It's an emotional discussion, that will more often show the dishonoring human sides of the participants, than it will produce any real arguments. (Thow especially Bill made some very good points there.)

    Thanks, your summation states my view pretty well.  I have nothing else to add.

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    tufty:
    > I think you should take a class in quoting right, to not let > out important relevant information. He said, quoting exactly what dubwai posted / quoted, and presumably leaving out exactly the same "important relevant information"... >I think you should take a class in reading between the > lines, try see the points in sentences without taking > exactly everything literally. Where's the fun in that? Holy flying spaghetti monster, when did this become alt.im.a.fucking.pedant? Oh. Yes. Bugger. Simon

     

    I wrote he needs a class in quoting, and included a post from him where he clear and obvious  leaved out "important relevant information". How is this quote not relevant to what I wrote about quoting? is this logic hard for you?...do you actually mean I should quote a post WITHOUT missing  "important relevant information" and then comment that with "you need a class in quoting". How wierd wouldn't that be/look?

    You could point out what the important relavant information was.  Otherwise it just seems like you are making up more excuses for being wrong.

  • (cs) in reply to eagle

    eagle:

    @bytecodes is not code-bites: I would actually like to see the real code you claim the reduced function you posted here comes from. I would recommend,  you send it to Alex as a proposal for a major WTF. And honestly, it is a WTF, not because of the goto's, but because of what you call "readability" and of course because of it's total lack maintainability. Actually until you present me your original code, I will assume you made this whole thing up and, yes, this means I call you a liar straight in your face. However, if it is real code, then I take it back and will live happily until the day I die, because of the thought that I am certainly not the guy who will have to maintain your code, because where I live, we write from left to right.

     

    I have said in previous posts that the code I posted was just part of a bigger function, and also that it was edited. I will not post the real code for the simpliest reason that I will not reveal code that I make a living on and certainly not in a forum like this. And also where my point in commenting here is only to show that there is code out there with goto's that can't be recreacted with nearly equal fast execution, and without a seriously amount of overhead extra code in languages lacking the command, like java.

     

    I could post him made up code for useful stuff  with code like this, but I doubt that will serve the purpose of this site. The one big thing about this site is that code-snippets posted here is done for real world use, not created and made up for the sole reason to fit into here.

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    I have said in previous posts that the code I posted was just part of a bigger function, and also that it was edited.


    Yes, you said it was edited. Yes, you said it comes from a bigger function. Yes, you said it is from real code.

    And yes, I still think you made it up.

    Bytecodes is not codebytes:

    And also where my point in commenting here is only to show that there is code out there with goto's that can't be recreacted with nearly equal fast execution, and without a seriously amount of overhead extra code in languages lacking the command, like java.


    No doubt about this. But it is like pointing out, that you can travel from Berlin to Paris via Tokio. Sure you can, but you would have to present me a real person that does do it this way. And that's is the problem with your example. I just don't believe you that it comes from real existing production code. And as long as this is the case, there is no point to show such code can be written. No one doubts that. What you would have to prove to me is, that there exists a real world problem, that when it comes to coding requires such language constructs as you used, to be implemented effectively. And you have yet to prove this.Whenever it comes close to the point you become utterly vague.

    What's wrong in telling us your country? Why just "we write from right to left"? Is your country so small that you could be identified by naming it?

    Why not explain in what domain of expertise you work? Why only tell that it is "from some in-memory-database"? Do you fear we could come up with better code than you, if you would explain us specs your coding task?

    Sorry, to say, that all of this is not in favor to your credibility.And so, I have to repeat: ... until you present me your original code, I will assume you made this whole thing up and, ...

    cu

    BTW: I am from Germany, currently unemployed, and in my over 20 years experience in programming I started from many different assemblers (and actually on one system its machine code), over K&R C, UCSD Pascal, Prolog, and many other up to C++ and Java (which I currently use most of the time). I've written interpreters, compilers and even a database engine, though not lately. And it's this experience, that tells me, that your code is just a piece of junk, created with no other purpose, than to produce a case where goto cannot be easily eliminated. And that's why I would like to see the real code, as that's the only way you could prove, that such code is really necessary in the real world.
  • (cs) in reply to eagle

    eagle:

    And that's why I would like to see the real code, as that's the only way you could prove, that such code is really necessary in the real world.

    I would be satisified with a detailed explanation of what each part of the posted code does in the original function.

  • (cs) in reply to loneprogrammer
    loneprogrammer:
    Aristotle Pagaltzis:
    Well, for one thing, your code is illegal in C… in languages without exceptions, GOTO can be the only maintainable and readable way of cleaning up allocated resources.

    I think the best illustration of this point was made by Robert Love (kerneltrap)


    From: Robert Love
    Subject: Re: any chance of 2.6.0-test*?
    Date: 12 Jan 2003 17:58:06 -0500

    On Sun, 2003-01-12 at 17:22, Rob Wilkens wrote:

    > I say "please don't use goto" and instead have a "cleanup_lock" function
    > and add that before all the return statements.. It should not be a
    > burden. Yes, it's asking the developer to work a little harder, but the
    > end result is better code.

    No, it is gross and it bloats the kernel. It inlines a bunch of junk
    for N error paths, as opposed to having the exit code once at the end.
    Cache footprint is key and you just killed it.

    Nor is it easier to read.

    As a final argument, it does not let us cleanly do the usual stack-esque
    wind and unwind, i.e.

        do A
        if (error)
            goto out_a;
        do B
        if (error)
            goto out_b;
        do C
        if (error)
            goto out_c;
        goto out;
        out_c:
        undo C
        out_b:
        undo B:
        out_a:
        undo A
        out:
        return ret;

    Now stop this.

        Robert Love



    In case it was not clear, say you have three tasks to do, and if you fail any of them, you want to roll your changes back.  The above code is a simple way to do this without a lot of indentation, and it's efficient from a CPU point of view.

    Excuse me if I am missing something, but isn't this the same, without indentation:

    do A
    if (!error){
    do B
    if (!error){
    do C
    if (!error) {
    return ret;
    }
    undo C
    }
    undo B
    }
    undo A

    and I don't find this to be a lot of indentation:

    do A
    if (!error){
      do B
      if (!error){
        do C
        if (!error) {
          return ret;
        }
        undo C
      }
      undo B
    }
    undo A

  • (cs) in reply to dubwai
    dubwai:
    Bytecodes is not codebytes:

    I think you should take a class in quoting right, to not let out important relevant information.
    I think you should take a class in reading between the lines, try see the points in sentences without taking exactly everything literally.

    So I was suppose to show what you were thinking about asking, not what you actually asked.  Again, take a class in logic.  It's clearly not coming naturally to you.

    Here's what you have done:  You asked me to deomonstrate something that you though couldn't be done.  Then when I did it, you claim I didn't do it well enough or meet your unspecified requirements.  Stop wasting your limited bandwidth with this stupidity.  You aren't king of the fourms, I don't owe you anything.  You ask me to do work and answer your questions but refuse to return the favor.

    Stop acting like an insolent child and I'll stop treating you like one.



    I've avoided getting in on this one, but I think the final line you're looking for is 'GTFO troll.' 

    As you and eagle have said, thus far he's done nothing but post shitty obfuscated code, bitch about how much Java sucks, and sing the praises of his shitty, obfuscated, unmaintainable, unreadable code.
  • (cs) in reply to dubwai
    Bytecodes is not codebytes:

    I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near.



    Thanks to dubwai for making a start in translating to Java. Now look at this, some refactoring, and it becomes just as (un)readable as the original code. As it is also equivalent and performs somewhere near the original code, maybe, just maybe, BINC is now very happy. However, BINC, please don't become a Java programmer.


    cu



    package com.thedailywtf;

    public class StupidGotoEliminationDemo {

        public int function1(int param1) {
            this.arg1 = param1;
            i = new FL(null, j, m) { @Override boolean test() { return (lv-- > 600 * c + randomfunction(c, 1) + c++); }};
            j = new FL(i   , k, l) { @Override boolean test() { return ((lv += 6) < _rotl(arg1, 1) - c++); }};
            k = new FL(j   , l, n) { @Override boolean test() { return ((lv += _rotr(lv, arg1) / 1.5 / 4) > arg1); }};
            l = new FL(k   , m, q) { @Override boolean test() { return (c > 10 * arg1 + c++); }};
            m = new FL(l   , n, o) { @Override boolean test() { return (lv > arg1 - c--); }};
            n = new FL(m   , o, i) { @Override boolean test() { return (arg1 < lv + c++); }};
            o = new FL(n   , p, r) { @Override boolean test() { return ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv, 2)); }};
            p = new FL(o   , q, k) { @Override boolean test() { return (lv < 500 * arg1 - c--); }};
            q = new FL(p   , r, l) { @Override boolean test() { return (lv > 50 * arg1 + randomfunction(c, 3)); }};
            r = new FL(q   , s, k) { @Override boolean test() { return ((c += c++ + arg1 * 10) == 42); }};
            s = new IFL(r  ,    i) { @Override boolean test() { return ((c += (arg1 += lv / 2) + (lv += arg1 * 4)) != 42); }};

            current = i;
            lv = _rotl(arg1, 4);

            while ((current = current.next()) != null) {
                // everything happens in next()
            }

            return arg1;
        }
       
        int lv, arg1, c;

        FL current, i, j, k, l, m, n, o, p, q, r, s;

        abstract class FL {

            FL outer, inner, conditional;

            int counter;

            public FL(FL outer, FL inner, FL conditional) {
                this.outer = outer;
                this.inner = inner;
                this.conditional = conditional;
            }

            public FL reset() {
                counter = 0;
                return this;
            }

            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return inner.reset();
                }

                return outer;
            }

            abstract boolean test();

        }

        abstract class IFL extends FL {

            public IFL(FL outer, FL conditional) {
                super(outer, null, conditional);
            }

            @Override
            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return this;
                }

                return outer;
            }
        }

        static int randomfunction(int c, int d) {
            return 0;
        }

        static int _rotl(int a, int b) {
            return 0;
        }

        static int _rotr(int a, int b) {
            return 0;
        }

    }

  • (cs) in reply to eagle

    Damn, I hate this forum SW. I hope I get it right this time.


    Bytecodes is not codebytes:


    I would be VERY happy if you replied this post with equivalent code in Java, have it readable, and have it execute faster than my C code, or anyway near.



    Thanks to dubwai for making a start in translating to Java. Now look at this, some refactoring, and it becomes just as (un)readable as the original code. As it is also equivalent and performs somewhere near the original code, maybe, just maybe, BINC is now very happy. However, BINC, please don't become a Java programmer.


    cu

    <font size="1">
    package com.thedailywtf;

    public class StupidGotoEliminationDemo {

        public int function1(int param1) {
            this.arg1 = param1;
            i = new FL(null, j, m) { @Override boolean test() { return (lv-- > 600 * c + randomfunction(c, 1) + c++); }};
            j = new FL(i   , k, l) { @Override boolean test() { return ((lv += 6) < _rotl(arg1,

      • c++); }};
            k = new FL(j   , l, n) { @Override boolean test() { return ((lv += _rotr(lv, arg1) / 1.5 / 4) > arg1); }};
            l = new FL(k   , m, q) { @Override boolean test() { return (c > 10 * arg1 + c++); }};
            m = new FL(l   , n, o) { @Override boolean test() { return (lv > arg1 - c--); }};
            n = new FL(m   , o, i) { @Override boolean test() { return (arg1 < lv + c++); }};
            o = new FL(n   , p, r) { @Override boolean test() { return ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv, 2)); }};
            p = new FL(o   , q, k) { @Override boolean test() { return (lv < 500 * arg1 - c--); }};
            q = new FL(p   , r, l) { @Override boolean test() { return (lv > 50 * arg1 + randomfunction(c, 3)); }};
            r = new FL(q   , s, k) { @Override boolean test() { return ((c += c++ + arg1 * 10) == 42); }};
            s = new IFL(r  ,    i) { @Override boolean test() { return ((c += (arg1 += lv / 2) + (lv += arg1 * 4)) != 42); }};

            current = i;
            lv = _rotl(arg1, 4);

            while ((current = current.next()) != null) {
                // everything happens in next()
            }

            return arg1;
        }
       
        int lv, arg1, c;

        FL current, i, j, k, l, m, n, o, p, q, r, s;

        abstract class FL {

            FL outer, inner, conditional;

            int counter;

            public FL(FL outer, FL inner, FL conditional) {
                this.outer = outer;
                this.inner = inner;
                this.conditional = conditional;
            }

            public FL reset() {
                counter = 0;
                return this;
            }

            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return inner.reset();
                }

                return outer;
            }

            abstract boolean test();

        }

        abstract class IFL extends FL {

            public IFL(FL outer, FL conditional) {
                super(outer, null, conditional);
            }

            @Override
            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return this;
                }

                return outer;
            }
        }

        static int randomfunction(int c, int d) {
            return 0;
        }

        static int _rotl(int a, int b) {
            return 0;
        }

        static int _rotr(int a, int b) {
            return 0;
        }

    }
    </font>
  • (cs) in reply to eagle

    Exactly how is this:

    eagle:
    <FONT size=1>

    public class StupidGotoEliminationDemo {

        public int function1(int param1) {
            this.arg1 = param1;
            i = new FL(null, j, m) { @Override boolean test() { return (lv-- > 600 * c + randomfunction(c, 1) + c++); }};
            j = new FL(i   , k, l) { @Override boolean test() { return ((lv += 6) < _rotl(arg1, 1) - c++); }};
            k = new FL(j   , l, n) { @Override boolean test() { return ((lv += _rotr(lv, arg1) / 1.5 / 4) > arg1); }};
            l = new FL(k   , m, q) { @Override boolean test() { return (c > 10 * arg1 + c++); }};
            m = new FL(l   , n, o) { @Override boolean test() { return (lv > arg1 - c--); }};
            n = new FL(m   , o, i) { @Override boolean test() { return (arg1 < lv + c++); }};
            o = new FL(n   , p, r) { @Override boolean test() { return ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv, 2)); }};
            p = new FL(o   , q, k) { @Override boolean test() { return (lv < 500 * arg1 - c--); }};
            q = new FL(p   , r, l) { @Override boolean test() { return (lv > 50 * arg1 + randomfunction(c, 3)); }};
            r = new FL(q   , s, k) { @Override boolean test() { return ((c += c++ + arg1 * 10) == 42); }};
            s = new IFL(r  ,    i) { @Override boolean test() { return ((c += (arg1 += lv / 2) + (lv += arg1 * 4)) != 42); }};

            current = i;
            lv = _rotl(arg1, 4);

            while ((current = current.next()) != null) {
                // everything happens in next()
            }

            return arg1;
        }
       
        int lv, arg1, c;

        FL current, i, j, k, l, m, n, o, p, q, r, s;

        abstract class FL {

            FL outer, inner, conditional;

            int counter;

            public FL(FL outer, FL inner, FL conditional) {
                this.outer = outer;
                this.inner = inner;
                this.conditional = conditional;
            }

            public FL reset() {
                counter = 0;
                return this;
            }

            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return inner.reset();
                }

                return outer;
            }

            abstract boolean test();

        }

        abstract class IFL extends FL {

            public IFL(FL outer, FL conditional) {
                super(outer, null, conditional);
            }

            @Override
            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return this;
                }

                return outer;
            }
        }</FONT>

    <FONT size=1>         <FONT face="Courier New">static int randomfunction(int c, int d) {
            return 0;</FONT>
        }

    }
    </FONT>

     

    Equal (un)readable as this:

    Anonymous:

    int randomfunction(int v)
    {
     
     //  .. superior secret function with superior code, but not relevant 
     
     return v;
    };


    #define FL(v)  for( (v) = 0; (v) < arg1; (v) += lv)

    int function1(int arg1)
    {
     int c,i,j,k,l,m,n,o,p,q,r,s;
     c=i=j=k=l=m=n=o=p=q=r=s=0;
     int lv = _rotl(arg1, 4);
     
     START: FL(i) if (lv-- > 600*c+randomfunction(c)+c++)     goto OP4; else
     OP1: FL(j) if (lv+=6 < _rotl(arg1,1)-c++)      goto OP3; else
     OP2: FL(k) if ( (lv += _rotr(lv, arg1) / 1.5 /4) > arg1)    goto OP5; else
     OP3: FL(l) if (c>10*arg1+c++)      goto OP8; else
     OP4: FL(m) if (lv > arg1-c--)      goto OP6; else
     OP5: FL(n) if (arg1 < lv+c++)                                         goto START; else
     OP6: FL(o) if ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv)) goto OP9; else
     OP7: FL(p) if (lv<500*arg1-c--)      goto OP2; else
     OP8: FL(q) if (lv>50*arg1+randomfunction(c))     goto OP3; else
     OP9: FL(r) if (c += c++ + arg1*10 == 42)      goto START; else
     OP10: FL(s) if (c+(arg1+=lv/2)+(lv+=arg1*4)!=42)     goto START;
     
     return arg1;
    };

     

     

    I believe my conception of code being unreadable and readable differs alot from your conception about the same thing.

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    I believe my conception of code being unreadable and readable differs alot from your conception about the same thing.



    Yes, my point exactly. ;-)
  • (cs) in reply to Bytecodes is not codebytes

    ooooops, sorry for the bad quote of your code, it wasn't my intension at all to make your code look that bad in terms of fontsize and lineclippings, it didn't look like that in the preview.

  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:

    Exactly how is this:

    eagle:
    <font size="1">

    public class StupidGotoEliminationDemo {

        public int function1(int param1) {
            this.arg1 = param1;
            i = new FL(null, j, m) { @Override boolean test() { return (lv-- > 600 * c + randomfunction(c, 1) + c++); }};
            j = new FL(i   , k, l) { @Override boolean test() { return ((lv += 6) < _rotl(arg1, 1) - c++); }};
            k = new FL(j   , l, n) { @Override boolean test() { return ((lv += _rotr(lv, arg1) / 1.5 / 4) > arg1); }};
            l = new FL(k   , m, q) { @Override boolean test() { return (c > 10 * arg1 + c++); }};
            m = new FL(l   , n, o) { @Override boolean test() { return (lv > arg1 - c--); }};
            n = new FL(m   , o, i) { @Override boolean test() { return (arg1 < lv + c++); }};
            o = new FL(n   , p, r) { @Override boolean test() { return ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv, 2)); }};
            p = new FL(o   , q, k) { @Override boolean test() { return (lv < 500 * arg1 - c--); }};
            q = new FL(p   , r, l) { @Override boolean test() { return (lv > 50 * arg1 + randomfunction(c, 3)); }};
            r = new FL(q   , s, k) { @Override boolean test() { return ((c += c++ + arg1 * 10) == 42); }};
            s = new IFL(r  ,    i) { @Override boolean test() { return ((c += (arg1 += lv / 2) + (lv += arg1 * 4)) != 42); }};

            current = i;
            lv = _rotl(arg1, 4);

            while ((current = current.next()) != null) {
                // everything happens in next()
            }

            return arg1;
        }
       
        int lv, arg1, c;

        FL current, i, j, k, l, m, n, o, p, q, r, s;

        abstract class FL {

            FL outer, inner, conditional;

            int counter;

            public FL(FL outer, FL inner, FL conditional) {
                this.outer = outer;
                this.inner = inner;
                this.conditional = conditional;
            }

            public FL reset() {
                counter = 0;
                return this;
            }

            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return inner.reset();
                }

                return outer;
            }

            abstract boolean test();

        }

        abstract class IFL extends FL {

            public IFL(FL outer, FL conditional) {
                super(outer, null, conditional);
            }

            @Override
            public FL next() {
                if (counter < arg1) {
                    counter += lv;

                    if (test())
                        return conditional.reset();
                    else
                        return this;
                }

                return outer;
            }
        }</font>

    <font size="1">         <font face="Courier New">static int randomfunction(int c, int d) {
            return 0;</font>
        }

    }
    </font>

     

    Equal (un)readable as this:

    Anonymous:

    int randomfunction(int v)
    {
     
     //  .. superior secret function with superior code, but not relevant 
     
     return v;
    };


    #define FL(v)  for( (v) = 0; (v) < arg1; (v) += lv)

    int function1(int arg1)
    {
     int c,i,j,k,l,m,n,o,p,q,r,s;
     c=i=j=k=l=m=n=o=p=q=r=s=0;
     int lv = _rotl(arg1, 4);
     
     START: FL(i) if (lv-- > 600*c+randomfunction(c)+c++)     goto OP4; else
     OP1: FL(j) if (lv+=6 < _rotl(arg1,1)-c++)      goto OP3; else
     OP2: FL(k) if ( (lv += _rotr(lv, arg1) / 1.5 /4) > arg1)    goto OP5; else
     OP3: FL(l) if (c>10*arg1+c++)      goto OP8; else
     OP4: FL(m) if (lv > arg1-c--)      goto OP6; else
     OP5: FL(n) if (arg1 < lv+c++)                                         goto START; else
     OP6: FL(o) if ((lv += _rotr(lv, arg1)) / 1.5 > randomfunction(lv)) goto OP9; else
     OP7: FL(p) if (lv<500*arg1-c--)      goto OP2; else
     OP8: FL(q) if (lv>50*arg1+randomfunction(c))     goto OP3; else
     OP9: FL(r) if (c += c++ + arg1*10 == 42)      goto START; else
     OP10: FL(s) if (c+(arg1+=lv/2)+(lv+=arg1*4)!=42)     goto START;
     
     return arg1;
    };

     

     

    I believe my conception of code being unreadable and readable differs alot from your conception about the same thing.



    It's quite simple, really.  What you posted is a GOTO jumble of unreadable spahgetti bullshit, and what eagle wrote is good, clear, structured code.  Now, if you'll excuse me, your commentary in this thread is about to result in my breakfast leaving my stomach in reverse.  [+o(]
  • (cs) in reply to Bytecodes is not codebytes
    Bytecodes is not codebytes:
    ooooops, sorry for the bad quote of your code, it wasn't my intension at all to make your code look that bad in terms of fontsize and lineclippings, it didn't look like that in the preview.


    Earlier you said, a refresh of this forum takes you 10 minutes. So, how is it, that it took you only three minutes to answer on your on post, AFTER viewing posted (i.e. not in preview) ?

    As I said, you're a liar.

    And as JThelen said: GTFO troll.

    cu

    BTW: Sad enough you did not point out the coding errors I made. Now it's too late, I discovered the bugs myself. Do you see them?
  • (cs) in reply to eagle

    eagle:
    Bytecodes is not codebytes:
    ooooops, sorry for the bad quote of your code, it wasn't my intension at all to make your code look that bad in terms of fontsize and lineclippings, it didn't look like that in the preview.


    Earlier you said, a refresh of this forum takes you 10 minutes. So, how is it, that it took you only three minutes to answer on your on post, AFTER viewing posted (i.e. not in preview) ?

    As I said, you're a liar.

    And as JThelen said: GTFO troll.

    cu

    BTW: Sad enough you did not point out the coding errors I made. Now it's too late, I discovered the bugs myself. Do you see them?

    It sometimes takes more than 10 minutes. Sometimes I cannot reach this server at all. And interesting enough, it sometimes works quite fast! This thing about technology working over huge distances differs so much in performance is very wierd right? the logic in such things is really obfuscating for you too? There is nothing sane about it, is it? well, I don't get it, how can that be?

Leave a comment on “When It's OK To GOTO”

Log In or post as a guest

Replying to comment #:

« Return to Article