• Lucid Dreaming - Dream Views




    Page 2 of 3 FirstFirst 1 2 3 LastLast
    Results 26 to 50 of 62
    Like Tree1Likes

    Thread: How Many Programming Langauges Do You Know?

    1. #26
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      You need some studying to do young'un[/b]
      No, nope, I'm pretty sure you're evenly matched in your, uh, contest.

    2. #27
      dsr
      dsr is offline
      我是老外,可是我會說一點中文。
      Join Date
      Nov 2006
      Gender
      Location
      my mind
      Posts
      374
      Likes
      1
      This is a rather pointless, er, "contest." Arby, how does Haskell's performance (when compiled with GHC) compare to native code written in more mainstream languages like C or C++? I never gave Haskell any thought until I read your post, but I just checked out the wiki and it looks pretty interesting.

      Kaniaz, Vim users unite! Bellum gerendum contra Emacs est. Actually, I like GNU Emacs but find it painful on my wrists.

    3. #28
      Eprac Diem arby's Avatar
      Join Date
      May 2006
      LD Count
      i/0
      Gender
      Location
      Canada
      Posts
      1,957
      Likes
      52
      Quote Originally Posted by dsr View Post
      This is a rather pointless, er, "contest." Arby, how does Haskell's performance (when compiled with GHC) compare to native code written in more mainstream languages like C or C++? I never gave Haskell any thought until I read your post, but I just checked out the wiki and it looks pretty interesting.

      [/b]
      Pointless, yes... =P oh well.

      Well, i'm not really sure about the specifics of why haskell is that efficient since i'm not exactly a computer science graduate but I have a general idea. Heres a demo peice of code just for refernce.

      Lets use a factorial function to demonstrate.

      in C:

      int factorial(x){
      y=1
      for(i=1,i<=x,i++){
      y = y*i
      }
      return y
      }

      It takes a few lines, a for loop and some variable calculations. In haskel:

      fac 0 = 1
      fac n | n > 0 = n * fac (n-1)

      A simple recurrsion, no unneeded calculations. Plus, it looks dam sexy fitting all those lines of code into 2 or even 1 line of code:

      fac n = if n > 0 then n * fac (n-1) else 1

      Anyways, its not more efficient in all cases and i&#39;m really not sure what parts of it are that much better but I worked under a university computer science professor using this language and he said it was more efficient in most cases so i&#39;m assuming he knew what he was talking about XD

      Anyways, if you&#39;re interested heres a good link

    4. #29
      dsr
      dsr is offline
      我是老外,可是我會說一點中文。
      Join Date
      Nov 2006
      Gender
      Location
      my mind
      Posts
      374
      Likes
      1
      Actually, the C implementation would most likely be recursive, too:

      Code:
      int factorial&#40;int x&#41; {
      ****if &#40;x == 1 || x == 0&#41;
      ********return 1;
      ****else
      ********return x * factorial&#40;x - 1&#41;;
      }
      If you really want 1 line:

      Code:
      int factorial&#40;int x&#41; {if &#40;x==1||x==0&#41; return 1; else return factorial&#40;x-1&#41;*x;}
      Also, your C example doesn&#39;t use C syntax

      Thanks for the link. I&#39;ll check it out when I have the time. I&#39;m still curious about how Haskell&#39;s performance compares to C/C++, especially for algorithmic code. Maybe Haskell&#39;s wiki answers that somewhere.

    5. #30
      Eprac Diem arby's Avatar
      Join Date
      May 2006
      LD Count
      i/0
      Gender
      Location
      Canada
      Posts
      1,957
      Likes
      52
      Quote Originally Posted by dsr View Post
      Actually, the C implementation would most likely be recursive, too:

      Also, your C example doesn&#39;t use C syntax

      [/b]
      True, it could be recursive, but it wont get the full benifit because C isn&#39;t a lazy language (at least I think)

      And I used pseudo code for the C portion =P I&#39;m more used to languages similar to C.

    6. #31
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      I started learning C++ because of this topic.

      Here&#39;s my first program that checks if a number is prime. I&#39;m really angry because I just found out I could&#39;ve used a modulus operator and made it a lot shorter and faster >



      #include <iostream>

      using namespace std;

      float x;
      float y;
      int z;

      int main ();

      int composite ()
      {
      cout << "&#092;nCOMPOSITE";
      main ();
      }

      int main()
      {
      cout << "&#092;n&#092;n-PRIME-&#092;nEnter a number to determine if it is prime.&#092;n";
      cin >> x;
      if ( x <= 0 && x &#33;= -1 )
      composite ();
      for ( z = 2; z <= ( x / 2 ); ++z )
      {
      for ( y = 2; y <= ( x / 2 ); ++y )
      {
      if ( z == ( x / y ) )
      composite ();
      }

      }
      cout << "&#092;nPRIME";
      main ();
      }


      I am making a text-based rpg right now It&#39;s going to have colored font&#33;

    7. #32
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      Do you actually call main more than once or something there? In a perfect world, there would be indentation.

      Anyway, yeah, first rule of programming. If you find something is beginning to look quite ugly (like your solution and lack of modulus operator above), it&#39;s best to think to yourself, "has any other programmer possibly ever tried this before", and usually, more or less, there&#39;s a better way to do it.

    8. #33
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      C is a low-level language, meaning it works the same however you indent it.

      I also copied and pasted, and tabs for some reason don&#39;t copy and paste into firefox.

      And to answer your original question, it&#39;s because my compiler requires each function to be defined before it encounters it; in composite(), my compiler doesn&#39;t know what main() is yet, so I just have to define it before using it. I wasn&#39;t calling it twice.

      Also, I feel that if I copy a program, I might as well just download it. You misunderstood my intent with this program; it&#39;s to learn, not to create an uber omgI&#39;llfindthelargestprimenumberinzahworld program. Using someone else&#39;s code doesn&#39;t help you learn. I&#39;m not looking for the best way.

      I hope I wasn&#39;t too harsh :/ thanks for trying to help.

    9. #34
      Your cat ate my baby Pyrofan1's Avatar
      Join Date
      Nov 2006
      Gender
      Posts
      720
      Likes
      3
      C is a low-level language, meaning it works the same however you indent it.
      [/b]
      That&#39;s not right
      First of all C is not a low level language it&#39;s a medium level language
      A low level language means its closer to machine language unlike a high level language like BASIC which looks more like english

    10. #35
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      K, well I was going by what a tutorial said, anyway.

      You also completely missed the point of what I was saying :/

      *realizes this is a nerd topic and leaves* haha now you&#39;ll never get my rpg

    11. #36
      Your cat ate my baby Pyrofan1's Avatar
      Join Date
      Nov 2006
      Gender
      Posts
      720
      Likes
      3
      haha now you&#39;ll never get my rpg
      [/b]
      Fine, you&#39;ll never get my graphics based one.

    12. #37
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      The fact it works the same however you indent it doesn&#39;t mean you shouldn&#39;t indent ¬_¬

    13. #38
      Member
      Join Date
      Aug 2006
      Location
      Prague, Czech republic
      Posts
      17
      Likes
      0
      Hey guys,
      seems everyone is an expert here...

      * JAVA (J2EE or rather EE as J2EE is an obsolete term for enterprise java)
      * PHP - i think this can be called prog. lang. but someone could call it just scripting lang.

      * and of course a lot of stuff around the web (html, css, JS etc...)



    14. #39
      Eprac Diem arby's Avatar
      Join Date
      May 2006
      LD Count
      i/0
      Gender
      Location
      Canada
      Posts
      1,957
      Likes
      52
      Quote Originally Posted by lechat View Post
      Hey guys,
      seems everyone is an expert here...
      [/b]
      na, its just that the people who aren&#39;t experts pretend to be =P

    15. #40
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      Quote Originally Posted by arby View Post
      na, its just that the people who aren&#39;t experts pretend to be =P
      [/b]
      Haha like me

    16. #41
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      Uh, no. Let me clear some of this up for you.

      C is a low-level language, meaning it works the same however you indent it.[/b]
      All very true, and the same can be said for C++, but code is always read more times than it is written. The next person to see your code will not be able to see the structure of your program easily with for blocks etc if you do not indent in. The compiler is very loose and ultimately the code loses its indentation when it is compiled, but this does not mean that I can read machine code. Always indent it, it&#39;s much easier to read: it&#39;s easier to get into the habit now. I understand it Firefox did something weird.

      And to answer your original question, it&#39;s because my compiler requires each function to be defined before it encounters it; in composite(), my compiler doesn&#39;t know what main() is yet, so I just have to define it before using it. I wasn&#39;t calling it twice.[/b]
      You were. I don&#39;t believe your program should compile cleanly (or perhaps even at all). Apart from having recursion in your program that would cause a stack overflow if used too much, you have an illegal definition of composite() - you have said it returns an integer value when it does not return anything. If this compiled, it would have surely made a warning.

      Also, I feel that if I copy a program, I might as well just download it. You misunderstood my intent with this program; it&#39;s to learn, not to create an uber omgI&#39;llfindthelargestprimenumberinzahworld program. Using someone else&#39;s code doesn&#39;t help you learn. I&#39;m not looking for the best way.[/b]
      Uh. You can learn a lot from other people&#39;s code - I find learning by example one of the best ways to learn something. It&#39;s entirely possible to go it alone and end up making something that gets a value in 100 lines of code when there is a much more elegant solution available. I understand the point was to learn something by doing, here, and you&#39;ve done so, but your program does not run and would not compile.

      A rundown of the problems:
      Code:
      #include &#60;iostream&#62;
      using namespace std;
      
      float x;
      float y;
      int z;
      
      int main &#40;&#41;;
      
      int composite &#40;&#41;
      {
      ****cout &#60;&#60; &#34;&#092;nCOMPOSITE&#34;;
      ********main &#40;&#41;;
      }
      
      int main&#40;&#41;
      {
      
      ****cout &#60;&#60; &#34;&#092;n&#092;n-PRIME-&#092;nEnter a number to determine if it is prime.&#092;n&#34;;
      ****cin &#62;&#62; x;
      ****
      ****if &#40; x &#60;= 0 && x &#33;= -1 &#41;
      ********composite &#40;&#41;;
      
      ****for &#40; z = 2; z &#60;= &#40; x / 2 &#41;; ++z &#41;
      ****{
      ********for &#40; y = 2; y &#60;= &#40; x / 2 &#41;; ++y &#41;
      ********{
      ************if &#40; z == &#40; x / y &#41; &#41;
      ****************composite &#40;&#41;;
      ********}
      
      ****}
      ****
      ****cout &#60;&#60; &#34;&#092;nPRIME&#34;;
      ****
      ****main &#40;&#41;;
      }
      Code:
      #include &#60;iostream&#62;
      using namespace std;
      This is fine. Great, in fact, that you&#39;re using the STL.

      Code:
      float x;
      float y;
      int z;
      Bad news: you&#39;re defining global variables. Most people would consider this the Antichrist, these should be defined in a more local scope - main() itself would be fine for is. Moving these declarations into main() would do you a better service. Because you declare them here they are not initialised which is another bad point and could cause your program to crash/be more insecure than it needs to be.

      Code:
      int composite &#40;&#41;
      {
      ****cout &#60;&#60; &#34;&#092;nCOMPOSITE&#34;;
      You say this function returns an int. It doesn&#39;t, a simple mistake, just add return 0; if you want to use this function.

      Code:
      main&#40;&#41;;
      }
      Why are you calling main again? This will cause a stack overflow very quickly if your program is used too much, and you should never call main more than once (contrary to your insistence, you are calling it more than once). Your function should return 0; and then main should loop again. Else the call stack will grow and grow.

      Then in main():
      Code:
      ****main &#40;&#41;;
      }
      You call main () again when you should be looping it, causing the same problem and making your code nigh on impossible to follow.

      So your code does not actually compile, although like we&#39;ve just gone over, some problems that don&#39;t cause compiler errors still cause your code to be very hard to follow. Compiling your program in VC gets me this:

      ------ Build started: Project: Prime, Configuration: Debug Win32 ------
      Compiling...
      main.cpp
      c:&#092;users&#092;admin&#092;projects&#092;prime& #092;prime&#092;main.cpp(14) : error C4716: &#39;composite&#39; : must return a value
      c:&#092;users&#092;admin&#092;projects&#092;prime& #092;prime&#092;main.cpp(38) : warning C4717: &#39;main&#39; : recursive on all control paths, function will cause runtime stack overflow
      Build log was saved at "file://c:&#092;Users&#092;Admin&#092;Projects&#092;Prime& #092;Prime&#092;Debug&#092;BuildLog.htm"
      Prime - 1 error(s), 1 warning(s)
      ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
      [/b]
      I think that more or less proves my point.

      A better program using your code would look like this:

      Code:
      #include &#60;iostream&#62;
      using namespace std;
      
      int main&#40;&#41;
      {
      ****float x = 0;
      ****float y = 0;
      ****int z = 0;
      
      ****/* Realise that &#39;done&#39; will never become true and that you will never actually end this program in this state because you
      ****** are using cin as the input instead of any other method. Win32 API would use WM_CLOSE messages for example, to set done
      ****** to true. Therefore the program will loop forever but it since it never calls any other functions it will never crash
      ****** or overflow. */
      ****bool done = false, composite = false;
      ****while &#40; &#33;done &#41;
      ****{
      ********cout &#60;&#60; &#34;&#092;n&#092;n-PRIME-&#092;nEnter a number to determine if it is prime.&#092;n&#34;;
      ********cin &#62;&#62; x;
      
      ********/* We don&#39;t know at the start. So it isn&#39;t. */
      ********composite = false;
      ****
      ********if &#40; x &#60;= 0 && x &#33;= -1 &#41;
      ********{
      ************cout &#60;&#60; &#34;Composite&#33;&#34;;
      ************composite = true;
      
      ************/* It&#39;s easy enough to break here. */
      ************continue;
      ********}
      
      ********for &#40; z = 2; z &#60;= &#40; x / 2 &#41;; ++z &#41;
      ********{
      ************for &#40; y = 2; y &#60;= &#40; x / 2 &#41;; ++y &#41;
      ************{
      ****************if &#40; z == &#40; x / y &#41; &#41;
      ****************{
      ********************cout &#60;&#60; &#34;Composite&#33;&#092;n&#34;;
      ********************composite = true;
      ********************break;
      ****************}
      
      ****************/* Horrible. The way the program is structured requires this. */
      ****************if &#40; composite &#41;
      ********************break;
      ************}
      
      ************/* Also horrific. Don&#39;t do this&#58; it&#39;s the only way to stop the program from spewing &#34;composite&#33;&#34; over and over
      ************** again the amount of times the condition is true. */
      ************if &#40; composite &#41;
      ****************break;
      ********}
      ****
      ********if &#40; &#33;composite &#41;
      ************cout &#60;&#60; &#34;&#092;nPrime&#33;&#34;;
      ****}
      ****
      ****/* &#39;0&#39; is the convention for &#34;success&#34; in C++ style programs. It probably does not matter here, but
      ****** we return it anyway. */
      ****return 0;
      }
      That works. You will notice:

      1. I removed the composite() function. I didn&#39;t see the point on it in this case: it&#39;s called only twice and two cout statements could do just as fine. Encapsulating your code is important, but in this case was moot.
      2. The code does not cause a stack overflow on runtime, which is important else the program would crash.
      3. There is an ugly use of boolean in there to stop the program from spewing out the wrong message. It works, which is great, but the way the program was structured was kind of hard to do any other way (the continue keyword in C++ doesn&#39;t support continue all the way up the loop like PHP does). I didn&#39;t want to rewrite your entire program as you don&#39;t feel you&#39;d learn a lot from that hence the rather nasty looking solution of guard clauses.
      4. It compiles.

      Either way, that should help.

    17. #42
      explore Demerzel's Avatar
      Join Date
      Apr 2004
      Gender
      Location
      Scotland, UK
      Posts
      1,189
      Likes
      6
      Quote Originally Posted by dsr View Post
      If you really want 1 line:

      Code:
      int factorial&#40;int x&#41; {if &#40;x==1||x==0&#41; return 1; else return factorial&#40;x-1&#41;*x;}
      [/b]
      Wouldn&#39;t this work and be a bit less messy?
      Code:
      int factorial&#40;int x&#41; { &#40;x==1||x==0&#41; ? return 1 &#58; return factorial&#40;x-1&#41;*x;}
      [22:59] <Kaniaz> You basically did a massive shit on the rug of this IRC
      [22:59] <Kaniaz> And called it a message

    18. #43
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      I&#39;d like to add that even though you claim taking other people&#39;s code and perhaps editing it "does not teach you anything", but I must ask you to reconsider.

      I&#39;ve learned PHP and C++ mostly through seeing other people&#39;s code and editing it. I&#39;ve learned how to do new stuff; I could always create (web-)applications with current knowledge, but only to some extent - I couldn&#39;t - and still can&#39;t - magically sense what functions are used where on a completely new topic, when creating new applications unrelated to anything I&#39;ve ever done before. Looking at other people&#39;s code is the solution here (either that, or tutorials, but I tend to learn more from looking at how other people do it than simply reading a tutorial).

    19. #44
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      You were. I don&#39;t believe your program should compile cleanly (or perhaps even at all). Apart from having recursion in your program that would cause a stack overflow if used too much, you have an illegal definition of composite() - you have said it returns an integer value when it does not return anything. If this compiled, it would have surely made a warning.[/b]
      Lol how come ive compiled it and it works then?

      Try actually learning C before you criticize people, loser.

    20. #45
      explore Demerzel's Avatar
      Join Date
      Apr 2004
      Gender
      Location
      Scotland, UK
      Posts
      1,189
      Likes
      6
      Quote Originally Posted by M View Post
      Lol how come ive compiled it and it works then?

      Try actually learning C before you criticize people, loser.
      [/b]
      He&#39;s right. You&#39;re wrong. Read what he says and you might be up to a 3% chance of learning C yourself.
      [22:59] <Kaniaz> You basically did a massive shit on the rug of this IRC
      [22:59] <Kaniaz> And called it a message

    21. #46
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      Lol how come ive compiled it and it works then?

      Try actually learning C before you criticize people, loser.[/b]
      Oh grow up. Your code was invalid and would be choked upon by a compiler, but I won&#39;t argue the point (not much debate can come up against those magic compilers). I&#39;m sorry if I spent all that time trying to help you write better code by basically detailing its life story. I won&#39;t expect to see much good coming from you until you change the attitude.

    22. #47
      Banned
      Join Date
      Jun 2006
      Posts
      547
      Likes
      0
      You are in denial. If you actually tried compiling it you would see it works . Apparently you do not wish to do that because you know I am right, you are wrong.

      And what is wrong with using a perfectly respectable compiler? Just because yours might be crap doesn&#39;t mean other people can&#39;t use good ones .

      Owned kthxbai. I don&#39;t feel like coming back to this nerdy topic so I will leave you to wallow in your self-pity I am too cool to be arguing about programming languages lol.

    23. #48
      MSG
      MSG is offline
      Colloquial MSG's Avatar
      Join Date
      Jul 2004
      LD Count
      1
      Posts
      1,363
      Likes
      14
      Okay so I&#39;m going to try and compile this motherfucker
      sleephoax likes this.

    24. #49
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      This is the funniest topic ever. Thanks M-Cat, even though you won&#39;t read this anymore, you&#39;ve made me laugh harder than I have in a long time.

    25. #50
      MSG
      MSG is offline
      Colloquial MSG's Avatar
      Join Date
      Jul 2004
      LD Count
      1
      Posts
      1,363
      Likes
      14
      Okay so it didn&#39;t compile in Visual C++ 2005 Express.

      M-Cat, what compiler are you using? I really want to get your program to work.

    Page 2 of 3 FirstFirst 1 2 3 LastLast

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •