SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 43
  1. #1
    SitePoint Zealot
    Join Date
    May 2013
    Posts
    193
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Does python have more power than php?

    I know(skills) as of server scripting: php and java,...
    Well many web server environments (like 4GH Godaddy) not support java but python... You find it good learn a third additional language like python...?

    Does python have more power than php?
    Last edited by HAWK; Oct 14, 2013 at 15:32.

  2. #2
    Community Advisor ULTiMATE's Avatar
    Join Date
    Aug 2003
    Location
    Bristol, United Kingdom
    Posts
    2,160
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    I'll answer this one, but in the future you may want to make your posts clearer. Aside from the gist of your post I doubt anyone can understand your post.

    Python has been around for years, a fair bit longer than Java. It is primarily a scripting language, in many ways like PHP once was, which is why so many libraries exist for Python, and why there is still such a great divide between Python 2 and Python 3.

    For the record, Python isn't as powerful as PHP. Python can be used everywhere, but so can PHP with the correct libraries. As someone who has casually worked with both languages I will say that Python is much, much nicer to work with. I'm a huge fan of Django, and it's my framework of choice when working on stuff at home. PHP can be nice to work with, but I argue that most PHP projects are legacy projects, and most Python work is newer and as such is nicer code to work with.

    You can be a lot more expressive with PHP, so in that way it could be considered stronger, but given the sheer amount of crappy code out there I would probably call that a weakness.

    If you are a beginner and you want to start out in Web Development I would recommend picking either Ruby, Python, or ASP.NET. All three have/are strong frameworks, and by their nature will allow you to generate much nicer code. However, at the end of the day, these are tools to get the job done. Evaluate the job, and the tool will almost pick itself.

  3. #3
    SitePoint Zealot
    Join Date
    May 2013
    Posts
    193
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you were like me to have knowledge of PHP/MySQL & Java/JSP/MySQL & Java/Android, would you save time to learn Python 3 or latest???? would it make the life even a little easier?

  4. #4
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    One man's trash is another man's treasure, all those programming languages are still around not just for nothing, there aint a remedy that satisfies every programmer's need. I personally prefer PHP over Python due to my fondness of C++/Java/C# style syntax, but Python has its place in elsewhere and for those people, Python may as well be more powerful than PHP indeed. The word 'powerful' itself is a bit confusing anyway.

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    64 Post(s)
    Tagged
    2 Thread(s)
    The "which is more powerful" qestion as well as "which language to pick up next" really cannot be answered without knowing what types of things you are and want to work on. PHP destroys any other language when it comes to the most common tasks in web development, including speed of development (for those who know what they are doing) because of the tools available (aside from django in python, there isn't much else. This is a completely different story if you want to DEPLOY your own web app that has built in server. Python can handle this much better (but again like @ULTiMATE said, there's a huge divide between 2 and 3 which will cause you headache if you need to read some documentation.

    If you want to get in to game development, it depends on what kind, before you make your decision.
    If you want to get in to some highly computational apps, it depends on what kind, again...

    One language that hasn't been brough up yet is Go, and depending on what your doing this might be your best third language.

    So before this conversation goes any further with pointless suggestions being thrown at you, what are your interests / goals for this new language?

  6. #6
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unlike PHP, which has web development features built directly into the core language, Python's web development capabilites are provided by add-on modules. Basic CGI capabilities are provided by the 'cgi' module which comes in Python's standard library. There's also a wide range of third-party modules available for Python; some are complementary, others compete. As a result, Python provides a more flexible base for web development.

    There are some adverse side effects, Unless you are working experienced Python web developers, PHP is easier to get started with. Second, support for PHP is more common with shared-hosting companies than support for the various Python options.

    -iGyan
    Last edited by Force Flow; Oct 9, 2013 at 15:11. Reason: Removed link. Please wait 90 days before adding a signature

  7. #7
    SitePoint Zealot
    Join Date
    May 2013
    Posts
    193
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    python except for web what other uses has? is it like java, for web apps, for desktop apps, ... for mobile apps... i do not think the latter...well?

  8. #8
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Recent events at PHP internal has made me believe that PHP's declining and may not last another decade. If this happens, Python has a good chance to take the throne, its objected oriented but actually quite easy to learn. Node.js is also a strong candidate, but the language has yet to mature and there is a good deal of uncertainty involved with node.js. Java and C# suffer from the problem of being statically typed, which is an advantage for desktop apps but a hindrance for web development(C# does not run very well on linux hosts, thats another problem for C#.net and ASP.net). Ruby has a steep learning curve, its difficult if not impossible for complete newbies to start with, the fact that you need at least some programming background to understand/write ruby code is probably why it never reached the popularity as many people had hoped.

  9. #9
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Off Topic:


    Quote Originally Posted by Hall of Famer View Post
    Ruby has a steep learning curve, its difficult if not impossible for complete newbies to start with, the fact that you need at least some programming background to understand/write ruby code is probably why it never reached the popularity as many people had hoped.
    I'm not sure I'd agree with you there. I've just started looking into Ruby myself (albeit as someone who already knows several languages) and I don't see why it would be any harder for a complete beginner to pick up than PHP. In fact, there are some aspects of the language that I think make it slightly better than PHP as a first language (no need for semi-colons and less use of curly braces and parentheses, to give an example).

    What parts of the language do you think would be more difficult to get to grips with for a new programmer?


  10. #10
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    64 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by lse123 View Post
    python except for web what other uses has? is it like java, for web apps, for desktop apps, ... for mobile apps... i do not think the latter...well?
    Python is very widely used for mobile, desktop apps, server scripting, mathematics, etc. In a lot of ways its easier to pick up on than PHP. It is a good tool to have under your belt.

    Quote Originally Posted by Hall of Famer View Post
    Recent events at PHP internal has made me believe that PHP's declining and may not last another decade. If this happens, Python has a good chance to take the throne, its objected oriented but actually quite easy to learn. Node.js is also a strong candidate, but the language has yet to mature and there is a good deal of uncertainty involved with node.js. Java and C# suffer from the problem of being statically typed, which is an advantage for desktop apps but a hindrance for web development(C# does not run very well on linux hosts, thats another problem for C#.net and ASP.net). Ruby has a steep learning curve, its difficult if not impossible for complete newbies to start with, the fact that you need at least some programming background to understand/write ruby code is probably why it never reached the popularity as many people had hoped.
    I agree with the PHPs decline and possiblly not lasting, but Python is in too much of an unstable point right now and is hindered by a lot of performance issues even compared to PHP. Now something like .NET or GoLang replacing it in 10-15 years when highly concurrent apps are more mainstream, that I can see.

  11. #11
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by fretburner View Post
    Off Topic:




    I'm not sure I'd agree with you there. I've just started looking into Ruby myself (albeit as someone who already knows several languages) and I don't see why it would be any harder for a complete beginner to pick up than PHP. In fact, there are some aspects of the language that I think make it slightly better than PHP as a first language (no need for semi-colons and less use of curly braces and parentheses, to give an example).

    What parts of the language do you think would be more difficult to get to grips with for a new programmer?

    Well its a completely different story once you already know a lot about programming, no matter whether you know just one or multiple languages. For computer genius who grasped the basics of programming easily, they may not understand how an average beginner coder perceive and learn these programming concepts. Some programming languages are more suited for newbies to start with as they provide easier ways for newbies to learn such concepts from scratch. There is a reason why certain languages are more newbie-friendly than others, take a look at this link if you are interested. Its generally believed that Python > PHP > Ruby in terms of 'ease of learning'(although PHP can be easier if you come from a C/Java background), assuming you are a complete newbie with no idea of how to write even the simplest hello world code:
    https://www.udemy.com/blog/modern-language-wars/

    To tell the truth, I actually did attempt to start with Ruby a few years ago before I became a PHP programmer, as I was trying to play with a game dev engine called RPG Maker which uses ruby code. I had absolutely no luck, ruby was beyond my understanding however hard I tried. A few months ago, however, I accidentally picked up the old Ruby book I used before and browsed through it again. Everything was making perfect sense and I could write ruby code easily. It will take me shorter time to learn Ruby than the time I spent on PHP years ago, but its by no means an implication that Ruby is easier to learn than PHP. It simply proves that taking on another language is much easier once you already learn the basic concepts/terminologies with one language, nothing more nothing less.

  12. #12
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Yeah I've come across that infographic before, but I was hoping you might have some specific examples of what you think makes Ruby harder to learn?

    As a beginner, the first things you come up against are things like variable assignment, operators, conditionals and loops. Here are some simple examples of those, in both PHP and Ruby:
    PHP Code:
    // Set a variable
    $name 'Bill Gates';

    // simple operation
    echo 5;

    // Conditional
    if ($hungry) {
        
    eatFood();
    }

    // Loop
    for ($i 0$i 5$i++) {
        echo 
    "There's no place like home.";

    Code Ruby:
    # Set a variable
    name = 'Bill Gates'
     
    # simple operation
    puts 5 * 5
     
    # Conditional
    if hungry
        eatFood()
    end
     
    # Loop
    5.times { puts "There's no place like home" }

    To me, Ruby doesn't seem to be more complicated than PHP and as I mentioned previously, there are some ways in which I think the Ruby syntax is nicer. Take the loop code for example, it's more readable. You can also make simple conditional statements even more readable:
    Code Ruby:
    eatFood() if hungry

  13. #13
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,900
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    I must agree with fretburner.
    For me, Ruby's syntax was considerably easier to wrap my head around than PHP's.

    For example:

    You can also invert conditional statements with unless
    Code ruby:
    puts "I love PHP" unless ruby_better

    and the last expression evaluated within a method is the return value
    Code ruby:
    def ruby_better
      true
    end

    You don't need parenthesis after your method names, semi-colons are optional, the list goes on ...

    Also, due to the fact that virtually everything in ruby is an object, chaining is much easier which makes for very readable code:

    Take for example a case when you have a hash where you want the first 3 alphabetically sorted key values. In PHP you'd do the following:

    PHP Code:
    $foo = array("zulu" => "1""alpha" => "4""golf" => "8""bravo" => "3");
    $keys array_keys($foo);
    sort($keys);
    $bar array_slice($keys03); 
    This seems incredibly verbose mainly due to -the fact that PHP doesn't return the sorted array from sort.

    Compare this to the ruby equivalent:

    Code ruby:
    foo = {"zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3"}
    bar = foo.keys.sort.slice(0,3)

    Example taken from here: http://andyjeffries.co.uk/articles/4...ter-than-phps-

  14. #14
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,900
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    I just read a cool article on SitePoint (formerly RubySource) about Ruby’s Top Self Object.
    It examines the value of self in the top lexical scope, explains why all functions are actually methods and concludes that this is one of the reasons that Ruby is easy to learn and use.

    Thoughts?

  15. #15
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Really? PHP, Python, Ruby? Mheah! Pffftt!

    JavaScript, now that's what I'm talking about.

    For self Ruby, take this Javascript window/global(nodejs) object, all functions are methods for the containing object, global or not, and memoization should really be a thing to teach from the start when it comes to recursion!
    Code:
    var f = [];
    
    function factorial(n) {
        console.log(this);
        return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
    };
    
    console.log(factorial(10));
    Prototypical nature of JavaScript is actually pretty easy to put in practice. The inheritance mechanism makes much more sense to me in JavaScript than in other languages (Golang for example), it's simpler and clearer. All in all, JavaScript kicks ****!

  16. #16
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Pullo View Post
    I must agree with fretburner.
    For me, Ruby's syntax was considerably easier to wrap my head around than PHP's.

    For example:

    You can also invert conditional statements with unless
    Code ruby:
    puts "I love PHP" unless ruby_better

    and the last expression evaluated within a method is the return value
    Code ruby:
    def ruby_better
      true
    end

    You don't need parenthesis after your method names, semi-colons are optional, the list goes on ...

    Also, due to the fact that virtually everything in ruby is an object, chaining is much easier which makes for very readable code:

    Take for example a case when you have a hash where you want the first 3 alphabetically sorted key values. In PHP you'd do the following:

    PHP Code:
    $foo = array("zulu" => "1""alpha" => "4""golf" => "8""bravo" => "3");
    $keys array_keys($foo);
    sort($keys);
    $bar array_slice($keys03); 
    This seems incredibly verbose mainly due to -the fact that PHP doesn't return the sorted array from sort.

    Compare this to the ruby equivalent:

    Code ruby:
    foo = {"zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3"}
    bar = foo.keys.sort.slice(0,3)

    Example taken from here: http://andyjeffries.co.uk/articles/4...ter-than-phps-
    First of all, I agree with you that ruby has more elegant syntax than PHP on various aspects, the fact that its pure object oriented makes it quite attractive to OO programmers like me. However, I believe your argument was no different from fretburner in a way that both of you are advanced/professional programmers with a good talent in coding. I never said a computer genius can not grasp Ruby as easy as he/she does with PHP or python, we see it happens all the time.

    Unfortunately, this does not apply to an average beginner coder. Dont get me wrong, I like ruby's number iterator such as 2.times{print something}, I also use method chaining in lots of my projects, but most newbies dont understand such concepts easily. Method chaining for instance, is quite confusing if you dont know what you are doing with it. I work on a PHP application/software myself, the userbase consists mostly noncoders or beginners. Its quite common that a programming concept that takes a few mins for me to interpret will take them forever to understand, even with simple PHP.

    In fact, Ruby's flexibility in writing conditional statements like unless and loops like until is a hindrance for newbies to grasp the very basic concepts. Same reason why you teach one language for starters at once, not two, three or more. Its more important for newbies to understand the concepts rather than syntax, ruby promotes coding with fluent interface which is a bless for advanced coders but just makes newbies life more difficult. Difficulty in focusing on what they should be focusing can be a real problem at times.

    Also keep in mind that Ruby's nature as pure object oriented language makes it hard if not impossible to introduce the basic computer science concepts to starters without talking about objects and classes. Reality is, absolute beginners do not grasp the concepts like objects and classes as fast as we believe they should.

    On the other hand, ruby code may be easier to read for programmers, but I am talking about how to write a working program for absolute starters. The ability to read a program is vital, but you have to be able to write your own piece of code to become an intermediate coder rather than stay as a newbie. Again I emphasize that I am not talking about ivy league students who are expected to learn new skills fast enough. Its more about newbies who come from backgrounds with no more than HTML and CSS, its not an easy job to understand the mindset of newbies/starters when you are already an expert programmer, especially if you possess the talents they normally do not when it comes down to coding. There's a reason why superstar athletes do not make better coaches than role players, as they do not understand how average athletes play their games.

  17. #17
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,900
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    @myty ;

    Could you explain this bit to me:

    Code:
    return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
    I understand it more or less, but the f[n] bit has me confused.

  18. #18
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    @Pullo ;
    It's the memoization part.

    Let's break it down. First, a stack of recursive calls is build, until n hits 1. Then the stack gets calculated (imagine putting back together Matroshka dolls, not taking them apart, to understand the stack resolve), from n low to n high, but on every step, the previous same range values are calculated over and over.

    To avoid that, we memorize the previously processed inputs. Imagine that for each Matroska doll you add, you then disassemble them all and start all over again in order to get to next step, next bigger doll. Memoization helps avoid that. The f array holds just that, the previous processed inputs. This way, on the next recursive call, we skip the calculation part and just use the previously stored value.

    One other thing to note here is how easy the conditional or ternary operator can be nested in Javascript. One of them can be an expression for another.

  19. #19
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    First of all, I agree with you that ruby has more elegant syntax than PHP on various aspects, the fact that its pure object oriented makes it quite attractive to OO programmers like me. However, I believe your argument was no different from fretburner in a way that both of you are advanced/professional programmers with a good talent in coding. I never said a computer genius can not grasp Ruby as easy as he/she does with PHP or python, we see it happens all the time.
    The real question is: for any given programming concept, is there anything about Ruby syntax that makes it harder to learn or implement than the equivalent in PHP? So far you’ve failed to convince me that there is.

    Quote Originally Posted by Hall of Famer View Post
    In fact, Ruby's flexibility in writing conditional statements like unless and loops like until is a hindrance for newbies to grasp the very basic concepts. Same reason why you teach one language for starters at once, not two, three or more. Its more important for newbies to understand the concepts rather than syntax, ruby promotes coding with fluent interface which is a bless for advanced coders but just makes newbies life more difficult. Difficulty in focusing on what they should be focusing can be a real problem at times.
    If you mean it’s confusing that there are several different ways to do something, then in that respect Ruby is no different from PHP. How many different ways are there to write a loop in PHP? I can think of at least four.

    Quote Originally Posted by Hall of Famer View Post
    Also keep in mind that Ruby's nature as pure object oriented language makes it hard if not impossible to introduce the basic computer science concepts to starters without talking about objects and classes. Reality is, absolute beginners do not grasp the concepts like objects and classes as fast as we believe they should.
    Take a look at the article Pullo linked to on Ruby’s Top Self object and you’ll see that’s just not true. You can learn all the basics without knowing anything about classes or objects.

    Quote Originally Posted by Hall of Famer View Post
    On the other hand, ruby code may be easier to read for programmers, but I am talking about how to write a working program for absolute starters. The ability to read a program is vital, but you have to be able to write your own piece of code to become an intermediate coder rather than stay as a newbie.
    A line of code that’s easy to read and understand is also easier to write. To take Pullo’s example
    Code Ruby:
    puts "I love PHP" unless ruby_better
    is so close to a plain English sentence that my grandmother could work out what was going on.

  20. #20
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    @Pullo ;

    Here's a legitimate reference, maybe the master explains it better.
    http://my.safaribooksonline.com/book...ns/memoization

  21. #21
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    @myty ;

    Could you explain this bit to me:

    Code:
    return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
    I understand it more or less, but the f[n] bit has me confused.
    Code:
    (if n === 1) ? then return 1 : else if previously calculated, f[n] > 0 ? then don't call recursive, return f[n] : else build the recursive stack and store every calculation in f so it can be reused when f[n] > 0 condition is checked
    There are three return there: 1, f[n] or the recursive call f[n] = factorial(n-1) * n, depending on the value of n and f[n].

  22. #22
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,900
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Hi myty,

    Thanks for the explanation!
    The link to the section on memoization was also very interesting.

    So, it seems then that memoization is a form of caching that is used to reduce duplication of effort by your program, as previously calculated results don't need to be recalculated.

    Just to help this sink into my brain, I wrote a small script to compare the performance of a memoized function against that of the same non-memoized version.
    The results were quite interesting:

    Code JavaScript:
    var f = [],
        timesCalledMemoizedFactorial = 0,
        timesCalledrecursiveFactorial = 0;
     
    function memoizedFactorial(n){
      timesCalledMemoizedFactorial++;
      if(n==1){
        return 1;
      } else {
        if(f[n]>0){
          return f[n];
        } else{
          return f[n] = memoizedFactorial(n-1) * n;
        }
      }
    };
     
     
    function recursiveFactorial(n){ 
    	timesCalledrecursiveFactorial++;
      if (n <= 1){
        return 1;
      } else {
        return recursiveFactorial(n-1) * n;
      }
    } 
     
    //Calculate the factorials 1 - 10)
    for(var i=1; i<=100; i ++){
      memoizedFactorial(i);
      recursiveFactorial(i);
    }
     
    console.log("memoizedFactorial was called " + timesCalledMemoizedFactorial + " times.");
    console.log("recursiveFactorial was called " + timesCalledrecursiveFactorial + " times.");

    Output:

    Code:
    memoizedFactorial was called 199 times.
    recursiveFactorial was called 5050 times.
    Cool!

    Anyway, memoized or not, you can still blow the call stack by passing it too large a number:

    Code JavaScript:
    var f=[];
     
    function factorial (n) {
     return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
    }
     
    console.log(factorial(30000));

    Code:
    Uncaught RangeError: Maximum call stack size exceeded
    Whereas in Ruby, as of version 1.9.2 you can handle this with tail recursion:

    Code Ruby:
    RubyVM::InstructionSequence.compile_option = {
      :tailcall_optimization => true,
      :trace_instruction => false
    }
     
    eval <<EOF
      def factorial(n, result = 1)
        if n == 1
          result
        else 
          factorial(n - 1,  n  * result)
        end
      end
    EOF
     
    p factorial(30_000)

    Output (in about 1.5 seconds):

    Code:
    27595372462193845993799421664254627839807620445293309855296350368000758688503605 ... 000
    Although Ruby 1.9.2 actually ships with native support for tail recursion, it’s disabled by default and you have to either enable it through a compile-flag or by specifying the compile options at runtime (as above).

    JavaScript does indeed kick a**e, but saying that, you gotta love Ruby!

  23. #23
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    JavaScript does indeed kick a**e, but saying that, you gotta love Ruby!
    In Javascript, normally I would look for an exception in this case:
    Code:
    var i = 0,
        f = [];
     
    function factorial (n) {
     i = i + 1;
     return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
    }
    
    try {
        console.log(factorial(30000));
    } catch(e) {
        console.log("That's more than I can handle!", i);
    };
    fact(171) is already Infinity... but you can trampoline your way into TCO in Javascript (http://raganwald.com/2013/03/28/tram...avascript.html). So Javascript is no slacker with big integer arithmetic... until ES6 brings us Proper Tail Calls.

    For different runs there's slightly different results, but on a side note, for me (Win8 x64) IE10 is the champion: it chokes on around 27000 (26477..27728). Op17 is stagnant: 15667. Surprise, surprise, Ch30 is also stagnant... at 15665. So Op, on the same Blink engine, allocates 2 more.

    The worst is FF24 with Firebug: it stays at 6620, but it takes a lot longer to recognize its limit. With normal Firefox Developer Tool is returns undefined and Infinity, but it's instant to resolve the stack.

    I've also tested the nightly build of FF24 x64 and it shows a lot of promise: 26711, close to IE.

    node.js 0.10.20.0 is performing slightly worse than Ch: 13973.

  24. #24
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Also see this performance test and algos for fib: http://jsperf.com/tco-for-fibonacci/6

  25. #25
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by fretburner View Post
    The real question is: for any given programming concept, is there anything about Ruby syntax that makes it harder to learn or implement than the equivalent in PHP? So far you’ve failed to convince me that there is.



    If you mean it’s confusing that there are several different ways to do something, then in that respect Ruby is no different from PHP. How many different ways are there to write a loop in PHP? I can think of at least four.



    Take a look at the article Pullo linked to on Ruby’s Top Self object and you’ll see that’s just not true. You can learn all the basics without knowing anything about classes or objects.



    A line of code that’s easy to read and understand is also easier to write. To take Pullo’s example
    Code Ruby:
    puts "I love PHP" unless ruby_better
    is so close to a plain English sentence that my grandmother could work out what was going on.
    Syntax that looks like plain English may not be easier to write, especially for newbies. Like I explained, for absolute starters understanding the concepts of programming is more important than learning the syntax. With Rudy's 'do something unless otherwise' the programming flow logic is not clear compared to 'if...else' statement. It's easier to write once you already know what programming is about, but using such flexible and shortcut syntax to teach newbies will only make their lives harder. Good chance they learn how to write such code but don't know when or why to use it. Just like ternary operator, I love it but refrain from using in my examples when presenting the code to amateur coders since it confuses them.


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
  •