Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 48

Thread: Java HELP :(     submit to reddit submit to twitter

  1. #21
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    I think he was thinking of the function "round to the closest integer". For that, you add one half then round down.

    int RoundToClosestInteger(double d)
    {
    return Math.floor(d + 0.5);
    }


    Anyway, back to the absolute value thing, never forget about absolute value! It can replace a conditional statement for many types of mathematical operations, making for some elegant solutions.

    If anyone knows assembly language (x86), there's actually a way to write the absolute function itself without a conditional statement.



    By the way, it always pissed me off that basically every piece of literature and every teacher in the world tells you to write i++ or j++ in the loop instead of ++i or ++j. Putting the ++ in front of the variable can be more efficient, and since the code doesn't depend on the return value from the expression there's no reason not to do it.

  2. #22
    New Merits
    Join Date
    Oct 2005
    Posts
    204
    BG Level
    4

    Quote Originally Posted by divisortheory
    By the way, it always pissed me off that basically every piece of literature and every teacher in the world tells you to write i++ or j++ in the loop instead of ++i or ++j. Putting the ++ in front of the variable can be more efficient, and since the code doesn't depend on the return value from the expression there's no reason not to do it.
    I didn't even know you could do it either way. I think the reason behind teaching it as x++ is that we usually say variables before actual numbers in equations, like x^2 + 2x + 1. Tough to say which way is more logical I think. It does sort of bother me that I've never even heard of this before now though.

    Quote Originally Posted by divisortheory
    What program are you using to compile and run your java programs? If you get something with a graphical debugger, you can single step over lines of your code, and at each line you can see the value of all kinds of different variables. That's the best way to learn how a program works, by watching it in action.
    I would not recommend NetBeans if you're looking for one. I absolutely hate it, it complicates the entire process of creating a project-type program. It helps with debugging but that's about it from what I saw. The load time is horrendous for some reason, and.. ugh I dunno, I just hate it. I have a much easier time just writing out .bats.

  3. #23
    Relic Weapons
    Join Date
    Apr 2006
    Posts
    357
    BG Level
    4
    FFXI Server
    Lakshmi

    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    AHAHHAHA OMFG I JUST FUCKING PWNED THAT BITCH OF A PROGRAM.
    You get 'em tiger, right after you post on a video game forum for help.
    You're stupid, my fix had nothing to do with what Aurik said, I finished it promptly after posting.
    Be that as it may, owning homework does not consist of asking your gaming buddies for help.

  4. #24
    That SpellCast Guy
    Join Date
    Feb 2006
    Posts
    802
    BG Level
    5

    Quote Originally Posted by divisortheory
    By the way, it always pissed me off that basically every piece of literature and every teacher in the world tells you to write i++ or j++ in the loop instead of ++i or ++j. Putting the ++ in front of the variable can be more efficient, and since the code doesn't depend on the return value from the expression there's no reason not to do it.
    It's true that there's no reason not to do it, but there's also really no reason TO do it. Any decent compiler will compile it down to the same thing when it realizes you're not using the value of the variable anyway. Regardless, even if the compiler doesn't fix it, if you're really trying to optimize your program at that miniscule of a level you probably shouldn't be writing it in a high level language.

  5. #25
    i'm awesome.
    Join Date
    May 2005
    Posts
    9,218
    BG Level
    8

    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    AHAHHAHA OMFG I JUST FUCKING PWNED THAT BITCH OF A PROGRAM.
    You get 'em tiger, right after you post on a video game forum for help.
    You're stupid, my fix had nothing to do with what Aurik said, I finished it promptly after posting.
    Be that as it may, owning homework does not consist of asking your gaming buddies for help.
    Miji why are you such a douchebag, is your life that horrible that you have to negatively comment on everything? I posted here because I know alot of BGs frequent readers are programmers or have some familiarity with programming. Being as java is a common programming language I knew I could get quick help here.

    Didn't your mother ever teach you "If you don't have anything nice to say, don't say anything at all"? Seriously, get a life.

    Btw, thanks for the info on the abs, that table you wrote is what my teacher does he calls it a trace or something. After writing out the code for the abs value approach to the problem I still didn't understand it but I'm going to print it out and ask my Professor about it, and see if he can explain it to me. The way it looks it really simplified the problem to the point where you only needed 4 for-loops. The solution that my professor came up with I think had more, but he assumed we wouldn't use math.abs I guess. But yeh, thanks to everyone for posting in this thread, I learned something new ^.^

  6. #26
    Relic Weapons
    Join Date
    Apr 2006
    Posts
    357
    BG Level
    4
    FFXI Server
    Lakshmi

    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    AHAHHAHA OMFG I JUST FUCKING PWNED THAT BITCH OF A PROGRAM.
    You get 'em tiger, right after you post on a video game forum for help.
    You're stupid, my fix had nothing to do with what Aurik said, I finished it promptly after posting.
    Be that as it may, owning homework does not consist of asking your gaming buddies for help.
    Miji why are you such a douchebag, is your life that horrible that you have to negatively comment on everything? I posted here because I know alot of BGs frequent readers are programmers or have some familiarity with programming. Being as java is a common programming language I knew I could get quick help here.

    Didn't your mother ever teach you "If you don't have anything nice to say, don't say anything at all"? Seriously, get a life.
    After that post, it's obvious yours didn't. I don't mind calling you out after how much time you spend in linkshell trying to belittle everyone and how hard you try to make everyone think you are smart. When the fact of the matter is it's your first programming class, and you needed help on what could only be your first or second assignment this semester. Just take it easy on saying how hard you pwned your first programming assignment in just a few hours and how smart you think you are from now on. You're selling it hard, and nobody is buying it.

  7. #27
    Sea Torques
    Join Date
    Jan 2005
    Posts
    535
    BG Level
    5

    I used NetBeans in school (Swing sucks ass, I wouldn't recommend using it) but now I use Oracle JDeveloper at work. It's free, you just have to register I think.

    It seems weird to learn Java as your first programming language. There's so many high-level concepts which you cannot avoid (Exceptions, Streams) that it must be overly complicated for a beginner to really learn anything.

  8. #28
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by Deimos
    It's true that there's no reason not to do it, but there's also really no reason TO do it. Any decent compiler will compile it down to the same thing when it realizes you're not using the value of the variable anyway. Regardless, even if the compiler doesn't fix it, if you're really trying to optimize your program at that miniscule of a level you probably shouldn't be writing it in a high level language.
    This is not entirely true. It probably is in Java, but in C++ it definitely isn't. In C++ you can overload the ++ operator on an object, and then you can say ++object, or object++. This is extremely common with iterators in the STL, for example. How many times have you seen code like this?

    Code:
    for (Iterator iter = container.begin(); iter != container.end(); iter++)
    {
          T i = *iter;
    }
    This is awful! It is not possible to perform any optimizations on the call to iter++, because the compiler uses a different function to implement iter++ and ++iter. It must call the appropriate function, and in the postvix version, an actual copy of the object is made, because that's what you need to return from the function - the value before "incrementing". Depending on the implementation of your constructor, this copy might perform expensive operations. Even if it doesn't, you're still allocating extra memory which although quite fast is still unnecessary. In the implementation of the prefix operator, you don't need to copy anything. You just increment the stuff and return *this.

    In any case, many people build their applications with all optimizations off, and in that case the prefix version will outperform the postfix version even on basic data types like int. If nothing else though, I prefer the prefix just for consistency since sometimes it's "necessary".

    It seems weird to learn Java as your first programming language. There's so many high-level concepts which you cannot avoid (Exceptions, Streams) that it must be overly complicated for a beginner to really learn anything.
    I tend to agree with this. At the same time, I think an object oriented language MUST be used as the first language. I hate when people learn C as their first language. I think C++ is best, but the book being used to learn from must understand that they need to teach C++, and not C with classes. So far the only book I know that fits the bill is Accelerated C++ by Koenig and Woo.

  9. #29
    i'm awesome.
    Join Date
    May 2005
    Posts
    9,218
    BG Level
    8

    [quote=Miji]
    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by Maguspk
    Quote Originally Posted by Miji
    Quote Originally Posted by "Maguspk":ba137
    AHAHHAHA OMFG I JUST FUCKING PWNED THAT BITCH OF A PROGRAM.
    You get 'em tiger, right after you post on a video game forum for help.
    You're stupid, my fix had nothing to do with what Aurik said, I finished it promptly after posting.
    Be that as it may, owning homework does not consist of asking your gaming buddies for help.
    Miji why are you such a douchebag, is your life that horrible that you have to negatively comment on everything? I posted here because I know alot of BGs frequent readers are programmers or have some familiarity with programming. Being as java is a common programming language I knew I could get quick help here.

    Didn't your mother ever teach you "If you don't have anything nice to say, don't say anything at all"? Seriously, get a life.
    After that post, it's obvious yours didn't. I don't mind calling you out after how much time you spend in linkshell trying to belittle everyone and how hard you try to make everyone think you are smart. When the fact of the matter is it's your first programming class, and you needed help on what could only be your first or second assignment this semester. Just take it easy on saying how hard you pwned your first programming assignment in just a few hours and how smart you think you are from now on. You're selling it hard, and nobody is buying it.[/quote:ba137]

    I seriously think you might be mentally unstable. I never try to belittle anyone, it's quite the opposite actually, e.g. "Emo Magus". Also, I never log onto FFXI anymore except to feed my chocobo then log off; so I don't see where you get any of your argument from. You're simply some 18+ male, actually you're probably older like in your 30's, who thinks he knows everything and has the right to look down on a 17 year old who is excited about college and doing well in his classes. Omg I have joy and am proud of myself, confidence is horrible!

    You need to grow up, you brought on this negative energy in this thread that was totally uncalled for. You had no reason to post your first post which was directed at "belittling" my accomplishment. Hmm, that's ironic isn't it? You go out of your way to read a thread and make a post belittling my accomplishment in finishing what was deemed as "the hardest programming assignment" all year; then a few posts later claim I enjoy belittling people? You need to see a psychiatrist or something, I don't know. Are you jealous of me for god knows why? Did I kill your family? Seriously man, I'm 17 and you're 30+ step back and look at the situation, you're acting like a 5 year old.

    Ok, back to the people with brains who aren't bent on hating me for no apparent reason. Concerning my compiler, I use Win X-32 to log onto some linux terminal thing at my school. I'm not exactly sure what it means but I right click on the desktop of the Redhat Enterprise thing and click "Open Terminal" and it opens a "putty" like window which defaults into my school network folder. Then I cd lab# and then javac ClassName.java, then correct any errors it returns, save the program and recompile. I am interested in looking at the compiler somebody mentioned earlier that tells you what values are assigned to what when it finds errors and stuff. Right now I just have whatever putty uses to compile the program, or whatever the default compiler is, like I said it uses "javac ClassName.java"

    Also, if you couldn't tell java is my first language, and right now it's going ok actually. Took a few labs of struggling before I got into the groove of it but now I'm pretty comfortable with it all. But I'd love to get some recommendations for other things I can use to compile/write for java.

  10. #30
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Well, i'll be honest, I learned Java once like 5 years ago then never touched it again lol. But I think there's something called Eclipse which is supposedly free and might have an integrated debugger. The command line java tools (i.e. the thing you appear to be using now) probably has a debugger also, but naturally it would be a command line debugger, definitely not user friendly even for experienced programmers.

    When you get later on in the semester your programming assignments are going to start getting considerably more complicated, and unless you have a debugger, you're going to have a hell of a time getting things working correctly.

    P.S. I know what it feels like to have that light bulb go off in your head and you figure something out you've been struggling over, so don't worry about the haters

  11. #31
    Sea Torques
    Join Date
    Jan 2005
    Posts
    535
    BG Level
    5

    Eclipse is a great Java IDE also. Open Source with lots of plugins.

    I've actually lost points on Java homework for doing prefix increments in for loops, which is pretty silly. My Data Structures professor emphasised the importance of using ++i, so I just use it all the time.

    Why trust a Compiler to fix your code when you could just write optimized code in the first place?

  12. #32
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by Faranim
    Eclipse is a great Java IDE also. Open Source with lots of plugins.

    I've actually lost points on Java homework for doing prefix increments in for loops, which is pretty silly. My Data Structures professor emphasised the importance of using ++i, so I just use it all the time.

    Why trust a Compiler to fix your code when you could just write optimized code in the first place?
    Was that a typo, or was the data structures professor not the same professor who deducted the points?

  13. #33
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Quote Originally Posted by divisortheory
    Quote Originally Posted by Deimos
    It's true that there's no reason not to do it, but there's also really no reason TO do it. Any decent compiler will compile it down to the same thing when it realizes you're not using the value of the variable anyway. Regardless, even if the compiler doesn't fix it, if you're really trying to optimize your program at that miniscule of a level you probably shouldn't be writing it in a high level language.
    This is not entirely true. It probably is in Java, but in C++ it definitely isn't. In C++ you can overload the ++ operator on an object, and then you can say ++object, or object++. This is extremely common with iterators in the STL, for example. How many times have you seen code like this?

    Code:
    for (Iterator iter = container.begin(); iter != container.end(); iter++)
    {
          T i = *iter;
    }
    This is awful! It is not possible to perform any optimizations on the call to iter++, because the compiler uses a different function to implement iter++ and ++iter. It must call the appropriate function, and in the postvix version, an actual copy of the object is made, because that's what you need to return from the function - the value before "incrementing". Depending on the implementation of your constructor, this copy might perform expensive operations. Even if it doesn't, you're still allocating extra memory which although quite fast is still unnecessary. In the implementation of the prefix operator, you don't need to copy anything. You just increment the stuff and return *this.

    In any case, many people build their applications with all optimizations off, and in that case the prefix version will outperform the postfix version even on basic data types like int. If nothing else though, I prefer the prefix just for consistency since sometimes it's "necessary".
    As long as we're naggling about minor details, for an iterator, shouldn't you be using some sort of .next() anyway? Now I don't write a lot of java, but the whole idea of postfix/prefix addition isn't clear when you're not even using a number. You should just explicitly say that you want the next item in the sequence.

  14. #34
    That SpellCast Guy
    Join Date
    Feb 2006
    Posts
    802
    BG Level
    5

    I think he's saying his Data Structures professor emphasized the importance of it, so he does it out of habit now, but in another one of his courses he was marked down for doing it the "non-conventional way".

    Either way, I know the reasoning for doing it if it's going to have to create a whole new object every time, but it shouldn't be a concern for basic data types. Personally I think if your method of iterating over one of your data structures is so ugly that the situation even comes up, the problem is probably more with the structure or the method, not with the post-increment. There may be cases that it's necessary though, I just can't really come up with any offhand.

    As for learning Java as a first language, yeah, it might be a bit strange. I know at the university I went to, the first course was done in Pascal (which I don't think is a great idea either), but then we went pretty much straight to Java. I can't really speak for how effective that was, because I had already been programming for about 5 years before I was taking my "intro" classes. Let's just say I didn't attend many lectures during my first year.

    The majority of my courses were Java, unless some other language was better for the material (C++ in Graphics, C in Operating Systems, etc.). One of the creators of Java is an alumni or something, so they liked to make us use it a lot. It's a fine language, but definitely not one of my favorites. When I'm just writing a program for myself, I never do it in Java.

  15. #35
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by aurik
    As long as we're naggling about minor details, for an iterator, shouldn't you be using some sort of .next() anyway? Now I don't write a lot of java, but the whole idea of postfix/prefix addition isn't clear when you're not even using a number. You should just explicitly say that you want the next item in the sequence.
    The code sample I used was C++. In C++ (STL) that's just how you do iterators. The reason is that the STL is filled with tons of generic (templatized) functions where you have skeleton code that can work with thousands of different types of collections. One of the original design goals was that it should work with original C++ arrays, which use pointer arithmetic to traverse. e.g.

    Code:
    int* intarray = new int[10];
    
    for (int* current = intarray; current != intarray+10; ++current)
        int current_int = *current;
    (I know you could use array indexing to make things more readable, but you'll see why I didn't in the next code sample. In this case there's no such thing as int.next(). In order to write a generic function that works not only with iterator objects, but also with pointer arithmetic, overloaded operator is a requirement.

    Code:
    template<class T>
    void iterate(T begin, T end)
    {
       for(; begin != end; ++begin)
           DoSomething(*begin);
    }
    
    
    void main()
    {
         int* tenints = new int[10];
         std::vector<int> tenints2(10);
    
         iterate(tenints, tenints+10);
         iterate(tenints2.begin(), tenints2.end());
    }
    Same function, but one is receiving 2 pointers as an argument, the other is receiving 2 objects. Templates can be overly complicated, but the amount of power they offer is fucking ridiculous. Even .NET Generics don't come close to C++ templates.


    Personally I think if your method of iterating over one of your data structures is so ugly that the situation even comes up, the problem is probably more with the structure or the method, not with the post-increment. There may be cases that it's necessary though, I just can't really come up with any offhand.
    I know, I just come from a heavy C++ background where iterators are used heavily, as described above. It's fine to choose not to do it, but only if you understand the alternative and the pros and cons of each. Most people do postfix because they don't even know that prefix can offer a performance advantage. As long as you understand there's a difference, you can choose whichever you want. Yes, it's a micro optimization, and in the grand scheme of things will affect your code almost not at all but after you've been doing this long enough you can glance at someone's code and tell who's been doing this type of thing for tens of years, and who's been doing it for 1 or 2 years. The devil is in the details, they make the difference between good code and great code.

  16. #36
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Quote Originally Posted by divisortheory
    Quote Originally Posted by aurik
    As long as we're naggling about minor details, for an iterator, shouldn't you be using some sort of .next() anyway? Now I don't write a lot of java, but the whole idea of postfix/prefix addition isn't clear when you're not even using a number. You should just explicitly say that you want the next item in the sequence.
    The code sample I used was C++. In C++ (STL) that's just how you do iterators. The reason is that the STL is filled with tons of generic (templatized) functions where you have skeleton code that can work with thousands of different types of collections. One of the original design goals was that it should work with original C++ arrays, which use pointer arithmetic to traverse. e.g.

    Code:
    int* intarray = new int[10];
    
    for (int* current = intarray; current != intarray+10; ++current)
        int current_int = *current;
    (I know you could use array indexing to make things more readable, but you'll see why I didn't in the next code sample. In this case there's no such thing as int.next(). In order to write a generic function that works not only with iterator objects, but also with pointer arithmetic, overloaded operator is a requirement.
    I'd argue that this is a failure with C++. It's nice that "we want it to look like iterating with a numeric index", but that's just making concessions which detract from the overall readability of your code.

    The fact is, "++" doesn't make sense to a non-numeric entity. You aren't adding one to it. You shouldn't use it.

  17. #37
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by aurik
    I'd argue that this is a failure with C++. It's nice that "we want it to look like iterating with a numeric index", but that's just making concessions which detract from the overall readability of your code.

    The fact is, "++" doesn't make sense to a non-numeric entity. You aren't adding one to it. You shouldn't use it.
    You're not alone arguing that, the debate has a long running history, but it really just comes down to the fact that extra flexibility comes with a price. If ++ doesn't make sense for a particular type of object, you shouldn't use it. I think it does make sense for an iterator personally, but very few other types of objects.

    Even if it's wrong from a philisophical point of view though, this "feature" alone makes for some extremely powerful C++ template idioms that can literally knock thousands of lines of code out of programs. So maybe you sacrifice a little readability from seeing ++ on something that isn't a number, but on the other hand perhaps you increase readability (and decrease probability of introducing errors) by decreasing the overall number of lines of code in your program. In addition to readability, you increase program stability by being able to take advantage of hundreds of pre-written functions that come with the C++ Standard Library and are part of the official supported standard. That's much better than having to roll your own function. Finally, reducing multiple similar functions into a single function which operates on multiple types increases maintainability, because code becomes more centralized, and you can make a fix in one place and have it be picked up by lots of different callers rather than having to go change code in multiple different functions, hoping you catch them all. Again, it's just a tradeoff but there are quite a few advantages and the only real disadvantage is one of a philisophical nature.

    The same argument you used to say that that's a failure of the C++ language could be used to argue that assembly language fails as well, but really it's just giving you more power, and assuming you know what you're doing. An example would be that there are different assembly language instructions for treating a piece of memory as an unsigned number or a signed number, and you have to know what a piece of memory is supposed to represent when you decide which instruction to use. Just because you "can" use the signed version everywhere doesn't mean you should.

  18. #38
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Quote Originally Posted by divisortheory
    Quote Originally Posted by aurik
    I'd argue that this is a failure with C++. It's nice that "we want it to look like iterating with a numeric index", but that's just making concessions which detract from the overall readability of your code.

    The fact is, "++" doesn't make sense to a non-numeric entity. You aren't adding one to it. You shouldn't use it.
    You're not alone arguing that, the debate has a long running history, but it really just comes down to the fact that extra flexibility comes with a price. If ++ doesn't make sense for a particular type of object, you shouldn't use it. I think it does make sense for an iterator personally, but very few other types of objects.

    Even if it's wrong from a philisophical point of view though, this "feature" alone makes for some extremely powerful C++ template idioms that can literally knock thousands of lines of code out of programs. So maybe you sacrifice a little readability from seeing ++ on something that isn't a number, but on the other hand perhaps you increase readability (and decrease probability of introducing errors) by decreasing the overall number of lines of code in your program. In addition to readability, you increase program stability by being able to take advantage of hundreds of pre-written functions that come with the C++ Standard Library and are part of the official supported standard. That's much better than having to roll your own function. Finally, reducing multiple similar functions into a single function which operates on multiple types increases maintainability, because code becomes more centralized, and you can make a fix in one place and have it be picked up by lots of different callers rather than having to go change code in multiple different functions, hoping you catch them all. Again, it's just a tradeoff but there are quite a few advantages and the only real disadvantage is one of a philisophical nature.

    The same argument you used to say that that's a failure of the C++ language could be used to argue that assembly language fails as well, but really it's just giving you more power, and assuming you know what you're doing. An example would be that there are different assembly language instructions for treating a piece of memory as an unsigned number or a signed number, and you have to know what a piece of memory is supposed to represent when you decide which instruction to use. Just because you "can" use the signed version everywhere doesn't mean you should.
    The whole idea behind STL is to provide a generalized interface for Doing Useful Things, yet they compromise it because bespectacled beardies want to write ++ in their for loop. The entire reason to use C++ over other OO C-style languages is STL; enforcing an illogical (from a semantic PoV) construct on STL so that it looks like pre-existing C notation is the tail wagging the dog.

    The real answer is to provide classed integers, like Java, and then let people inline i.next() for Integer to be ++i. People bitch about Java being slow, but the reason it is slow has absolutely nothing to do with classed primitive types. Of course there's a lot of retarded shit in Java I don't like either...python ftmfw.

  19. #39
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    I'd argue that Integer.Next() makes even less semantical sense than Iterator++. Iterator++ is just syntactic sugar for a function which, for all intents and purposes you can pretend is called Next(). What if your integer isn't in a collection? What does Integer.Next() do then?

    There's definitely still a valid need for languages which are closer to the level of the machine, and C++ fits that bill. STL isn't the only reason to use C++ over other OO languages, or even the primary reason. The primary reason to use C++ over other OO languages is that it's close to the level of the machine, and gives you the power to do anything you want to the system and achieve higher performance.

    Try using something other than C++ to inject a DLL into a process's address space while that process is running, then redirecting calls from some other DLL in that address space to the new DLL. Good luck if you're using anything other than C++. Even .NET recognizes this, by allowing you to use P/Invoke to call functions written in C++ or other unmanaged languages.

  20. #40
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Quote Originally Posted by divisortheory
    I'd argue that Integer.Next() makes even less semantical sense than Iterator++. Iterator++ is just syntactic sugar for a function which, for all intents and purposes you can pretend is called Next(). What if your integer isn't in a collection? What does Integer.Next() do then?

    There's definitely still a valid need for languages which are closer to the level of the machine, and C++ fits that bill. STL isn't the only reason to use C++ over other OO languages, or even the primary reason. The primary reason to use C++ over other OO languages is that it's close to the level of the machine, and gives you the power to do anything you want to the system and achieve higher performance.

    Try using something other than C++ to inject a DLL into a process's address space while that process is running, then redirecting calls from some other DLL in that address space to the new DLL. Good luck if you're using anything other than C++. Even .NET recognizes this, by allowing you to use P/Invoke to call functions written in C++ or other unmanaged languages.
    "next" totally passes the semantic test. What's the "next" integer after, eg, "4"? I think it's 5. That makes sense to me.

    The only reason you can read ++ as "get the next item in the sequence" is because either you internally have overloaded the meaning of "++", or you internally have overloaded the meaning of "increment" w.r.t. an iterator. Again, the only reason you understand this is because you have been taught to understand it, whereas everyone is taught how to count in ascending order as a baby, and naturally understands that the "next" integer after 4 is 5.

    Furthermore, consider you have an iterator over the fibbonacci numbers: 0,1,1,2,3,5,8... In this case your idea of "++" is totally deceptive, as it is of all iterators over a set of numbers that aren't necessarily in counting order. (0)++ gives you (1), then (1)++ gives you (1), then (1)++ again gives you (2)... later on, (8)++ gives you (13). What the fuck? At least with next() you understand that your iteration operation isn't necessarily "add one to the value".

    Java's complete suckitude when it comes to performance has nothing to do with the use of basic primitives as classes, which is a huge reason for the semantic use of ++ on iterators in loops.

    The reason why C++ is so powerful is because of developer support. There are much much much better OO languages out there (Java is one of them) that beat C++ at it's own game, mostly by virtue of language designers identifying the flaws in the C++ implementation and attempting to fix them. Because of strong developer support, there are awesome debuggers, IDEs, libraries, etc, as people attempt to make their development time more efficient. That in itself doesn't mean C++ doesn't completely suck as a language.

    However, the language should be subservient to the purpose it is being used for, and not the other way around; the strange insistence on STL's conformity with deprecated semantics that don't make sense in modern code, simply for purposes of language, is a failure in this respect.

Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. Need help fixing Java Code
    By Minardi in forum General Discussion
    Replies: 18
    Last Post: 2010-03-15, 23:56
  2. Java Help
    By jinkazama in forum General Discussion
    Replies: 28
    Last Post: 2010-01-30, 23:07
  3. Java Help.
    By Zilla in forum General Discussion
    Replies: 27
    Last Post: 2009-11-16, 19:41
  4. Java Programming Help
    By bori in forum General Discussion
    Replies: 9
    Last Post: 2008-09-19, 09:00
  5. Help with Java Programming Project. Get GF off my back plz
    By Azkarin in forum General Discussion
    Replies: 18
    Last Post: 2007-10-10, 10:59
  6. Need java help...
    By Sekkite in forum General Discussion
    Replies: 15
    Last Post: 2005-10-16, 15:58