Announcement

Collapse
No announcement yet.

PHP As A Next-Generation Programming Language?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Funny how a PHP article rapidly gets filled by python fanboys spitting all the hatred towards the PHP language, don't you guys get sick of saying the same bullcrap over and over again? Get over it already...

    Comment


    • #22
      Originally posted by blackshard View Post

      What is happening is that many scripting languages (like PHP, but also Javascript) are currently being pushed to a more formal and stricter form. Javascript recently got typed arrays, standard class notation.
      JavaScript does not have classes. It has (or is getting) syntax sugar to make you think it has classes, but it doesn't. Some of the changes coming in ES6 are just silly. JavaScript doesn't need classes and certainly doesn't need another language feature that doesn't do what it says on the tin.

      Comment


      • #23
        Originally posted by riklaunim View Post
        CamelCase is quite common for class names I would say. It's not JavaScript-one-style though.
        Quite common for class names, but method names sometimes have a mixed naming convention. Take a look to threading module, for example. The problem is much more evident in PHP however.

        Originally posted by riklaunim View Post
        Nested try/except in any language means you have bad code. Printing PHP4 style warnings instead of breaking code execution isn't a good thing to do either.
        Well, I have to disagree. I have bad code because I have bad situations to handle. I always try to make things simple. To be a bit more concrete I would describe a common scenario: I receive a json file, parse it and extract some attributes. Naturally, the attributes can be a string, an integer, a float, an object, and so on... unfortunately I can't test or cast all the attributes to their expected type, and I use them inside my loop code. The failure of a part of the script should not propagate, so here the need to code with nested try/except blocks.

        Originally posted by riklaunim View Post
        There are "with" and "finally" statements if needed. Plus it's better to be explicit.
        I agree, but still I don't understand why classes don't behave like any other class instance in other languages. Instead I'm forced to use "with" statement or call the "destructor" manually

        Originally posted by riklaunim View Post
        There are other solutions/implementations for that if you need it I didn't had any GIL problems with my code.
        At the moment I'm developing on a single core machine, so the GIL is not a problem. Unfortunately CPython is mandatory, and this could be a problem when I get an upgrade to a multi core machine. I tried also PyPy, but has terrible performances when it is used with external libraries, and also it is not compliant with Python3.x yet.

        Originally posted by riklaunim View Post
        PHP is not Smarty or $other template language too. Mixing server side with frontend side code give very poor codebase and no one should do that. PHP, Python and $everyone_other sane framework separates those things. Not to mention ember.js or Angular JS frameworks on the rise that make the separation even stronger where frontend and backend can be on separate servers communicating with REST over HTTP.
        Well you can mix server side code with frontend code with PHP, but it is not supposed that you do that, at least if you developed a bit of skill and knowledge. The nice thing about PHP being a template language is that you CAN use PHP files as HTML/XML/CSS/whateveryouwant templates and other PHP files as mere Controller code.

        My opinion is that PHP is perfectly able to implement the MVC pattern and it is not a fault of the language if people can't separate the View part from the Controller part. The best thing is that PHP can do the View part with extreme efficiency and cleanliness, expecially if you use the alternate syntax for the control structures (see http://php.net/manual/en/control-str...ive-syntax.php).

        Most people still use old PHP4 patterns, like spaghetti code, and mixes controller and view code inside the same script. This is a bad practice and the language doesn't prevent this in any way, but it is due to the fact that PHP has to support a lot of legacy code.

        Comment


        • #24
          Oh, no. Kill it with fire!
          And learn Haskell and Yesod.

          Comment


          • #25
            Originally posted by blackshard View Post
            Quite common for class names, but method names sometimes have a mixed naming convention. Take a look to threading module, for example. The problem is much more evident in PHP however.
            I didn't look at standard library that much, there are many things hidden there (even tab-nany ), but in general it's up to the developers how they write their code in any language. In the company where I work now we have good code review and one set of conventions (PEP8, Pyflakes in general) for Python and other languages we use. CamelCase for a method name would get -2

            Originally posted by blackshard View Post
            Well, I have to disagree. I have bad code because I have bad situations to handle. I always try to make things simple. To be a bit more concrete I would describe a common scenario: I receive a json file, parse it and extract some attributes. Naturally, the attributes can be a string, an integer, a float, an object, and so on... unfortunately I can't test or cast all the attributes to their expected type, and I use them inside my loop code. The failure of a part of the script should not propagate, so here the need to code with nested try/except blocks.
            It has to propagate up where something that is using it knows what to do when operation fails. For any exception based solution bad return values (like unexpected None) or multiple type of exceptions should be/can be re-raised as given library/class exception that can be caught by the thing that is using it and has the best knowledge (is the right place) to handle this situation. For example facepy for Facebook Graph API handling is raising only its own exception and not half of the standard library exceptions that can occur in that code. Operation handling is separated from the logic and the logic can easily respond to exceptions without problems of many exceptions etc.

            Originally posted by blackshard View Post
            I agree, but still I don't understand why classes don't behave like any other class instance in other languages. Instead I'm forced to use "with" statement or call the "destructor" manually
            Ask Guido Every language has its own decisions.

            Originally posted by blackshard View Post
            Well you can mix server side code with frontend code with PHP, but it is not supposed that you do that, at least if you developed a bit of skill and knowledge. The nice thing about PHP being a template language is that you CAN use PHP files as HTML/XML/CSS/whateveryouwant templates and other PHP files as mere Controller code.
            Mako templates for Python allow mixing Python with HTML to some extent. Web hosting of Python apps/files is not just as simple like PHP, but Python has different approach (WSGI apps) for nowadays web applications.

            Originally posted by blackshard View Post
            Most people still use old PHP4 patterns, like spaghetti code, and mixes controller and view code inside the same script. This is a bad practice and the language doesn't prevent this in any way, but it is due to the fact that PHP has to support a lot of legacy code.
            Bad code is a problem of any language. mysql_connect probably won't die quickly. Django "noobs" that don't read and learn the correct way of doing things start to write awful code too which is quite annoying when you get such legacy code to fix :]

            When PHP5 came out I wanted it to use for all the cool features, but hosting companies didn't as it broke all of those old PHP4 customer apps. At that time there weren't any more advanced hosting options, phars etc. so it sucked for a long time. What's easier in Python is that it's much easier to have custom virtualenvs per application and it doesn't require editing php.ini to install and use extra modules or different version of binary libraries for different apps (although Python apps aren't hosted on basic shared hosting with no SSH where PHP will be just fine, but with those limitations).


            The point of the article is that someone whats PHP to be where Ruby, Python and probably few other scripting languages are now - as a much more multipurpose language. They have desktop UI toolkit bindings, many system oriented libraries, many specialized ones (scientific, electronics/internet of things, mobile OS bindings/basic solutions) - and community that develops, use and maintain them. On the other hand they aren't as specialized on web as PHP, so if PHP wants to be really multipurpose it will have to take into account that it will loose some of its strong web orientation (and backward compatibility to some extent).

            Comment


            • #26
              Originally posted by blackshard View Post
              Anyway also python has its nice pitfalls, like

              - mixed naming conventions (camel case and underscore names)
              Others have pointed out PEP8. One of the bigger incompatibilities with Python 3 was going back and standardizing on PEP8. Someone mentioned the threading module. Looks consistent except the ones that should've been removed. https://docs.python.org/3.4/library/threading.html
              [QUOTE=blackshard;443817]
              - no data type abstraction. Everything can access every attribute of everything else. Can be nice, but in a cooperative environment it is a pain in the ass
              [\QUOTE]
              Well, you can still access them, but starting the variable w/ __ and not ending in __ basically does this.
              [QUOTE=blackshard;443817]
              - try/except logic. Can be hard to master in complex situations (like nested try/except with various paths)
              [QUOTE=blackshard;443817]
              - presence of a (sort of) instance constructor, but absence of the corresponding destructor. You can initialize your class instance with __init__, but you can't deinitialize it when the instance is disposed (and no, __del__ is not doing that)
              [\QUOTE]
              I would like to hear more about this actually. As others pointed out, there's with statements (ContextManagers), but how is __del__ not called when the object is disposed of? Only scenario I see in the docs is when it's not garbage collected if the object still exists when the interpretter ends. And this appears to only be when the interpretter crashes and isn't exitted nicely. (I would expect C++ would have the same issue?)
              [QUOTE=blackshard;443817]
              - presence of the GIL (at least in CPython) so no concurrent threads and presence of a shared interpreter state.
              [\QUOTE]
              Not as big an issue as you might think. I actually disagree with the PyPy guys on this and think that concurrent threads aren't a good idea and something more like the multiprocessing module, ZeroMQ, OpenCL, Celery, etc are better solutions. Especially in a web hosting environment. Obviously, something more like Erlang will completely beat everyone on this.
              Originally posted by blackshard View Post
              - not a template language. yes, why should you use a language for the web if you have to write tons of print statements, substituting template variables one at a time? Let the job being done by a fast syntax/lexical anaylizer
              [\QUOTE]
              Okay, but there's plenty of good Python templating languages out there. Jinja2, Mako, COG, etc.

              Biggest issues I've had with PHP is the complete lack of concern for security amongst most users. I look at how many security flaws I see against Django, Flask, and Pyramid and compare to Drupal, Symphony, CakePHP, and yes WordPress. Drupal is really bad at this one.

              Next thing is that the Python people typically take the "Readability Counts" to heart. The scientific guys are a little less so, but that's mainly when they make it "look like MATLAB" (ugh)

              Comment


              • #27
                I can't see a bright future for any language where count(false) == 1 - also the darn inconsistences (like everywhere) are a major problem

                Comment


                • #28
                  Originally posted by blackshard View Post
                  So you're suggesting an IDE to solve the issues of a language? Sorry but I would prefer a radical solution, this is just hiding the problems and not solving them.
                  No, not being statically typed isn't a problem, it's a design decision which comes with both pros and cons like everything else. However using a good IDE radically reduces these cons (it's a very few cases PyCharm can't figure out the type and give you suggestions or warnings). But a good IDE is of much help in statically typed languages as well as you don't have to compile to see the errors.

                  Originally posted by blackshard View Post
                  What is happening is that many scripting languages (like PHP, but also Javascript) are currently being pushed to a more formal and stricter form. Javascript recently got typed arrays, standard class notation. PHP is being evolved by facebook into Hack, which has static typing. I sense Java flavour in these things, and java is on the opposite side of python.
                  Previously Java and Python both were my absolute favorite languages (but I couldn't choose which of them were best) and I would hardly say that "java is on the opposite side of python". Sure on typing I agree but in many other cases they are very similar. My current favorite is Dart as it solves problems with both Java (being too static) and Python (being too Dynamic).

                  Originally posted by blackshard View Post
                  - mixed naming conventions (camel case and underscore names)
                  I haven't noticed any i Python 3, can you give an example?

                  Originally posted by blackshard View Post
                  - no data type abstraction. Everything can access every attribute of everything else. Can be nice, but in a cooperative environment it is a pain in the ass
                  This is true in PHP, Java, C# and a lot of other languages. They just provide different syntactic sugar for saying "This is internal, don't mess with it".
                  Python don't have syntactic sugar it have a convention that names starting with _ is internal and shouldn't be messed with.

                  Originally posted by blackshard View Post
                  - try/except logic. Can be hard to master in complex situations (like nested try/except with various paths)
                  What is hard with that? and how does it differ from other languages?
                  Nested situations is always hard and should be avoided. A maximum of one level nesting is okay.

                  Originally posted by blackshard View Post
                  - presence of a (sort of) instance constructor, but absence of the corresponding destructor. You can initialize your class instance with __init__, but you can't deinitialize it when the instance is disposed (and no, __del__ is not doing that)
                  As Python is garbage collected you can't know when (or if) an object is destructed. Personally I would never use __del__ or anything similar in a garbage collected language because of that. Also there is no need for a destructor in a garbage collected language as an objects referenced objects will be cleared automatically too.

                  Originally posted by blackshard View Post
                  - presence of the GIL (at least in CPython) so no concurrent threads and presence of a shared interpreter state.
                  This is too a design decision it have the pro that it makes the language simpler to work with in multiple threads while still giving most of the benefits and it have the con that it makes threads in Python worthless for CPU limited problems. You can work around this by using forks but a better alternative is to use the right tool for the job. Python is designed to be simple and quick to work with, not fast. If you need great performance you need to analyze your problem and choose the threading model suiting it. Rust, Go, C++ or Haskell is all better choices for that kind of job. Javascript and Dart have another solution to the threading problem that is very easy to work with but can still scale to perform good in most cases (an event driven model with isolated threads that may pass messages to each other), which is my personal pick as the by far best model for general purposes.

                  Originally posted by blackshard View Post
                  - not a template language. yes, why should you use a language for the web if you have to write tons of print statements, substituting template variables one at a time? Let the job being done by a fast syntax/lexical anaylizer
                  By saying that I have to wounder how much you have programmed for the web the last ten years?
                  Python, PHP, Ruby, Javascript and others all makes huge use of template engines. Yes even PHP with is a template language of itself is usually used with a separate template engine as it gives better View logic and View render separation by having a more limited feature set of the template engine.

                  Comment


                  • #29
                    Stupid editing time, now I have to double post.

                    Originally posted by blackshard View Post
                    Well, I have to disagree. I have bad code because I have bad situations to handle. I always try to make things simple. To be a bit more concrete I would describe a common scenario: I receive a json file, parse it and extract some attributes. Naturally, the attributes can be a string, an integer, a float, an object, and so on... unfortunately I can't test or cast all the attributes to their expected type, and I use them inside my loop code. The failure of a part of the script should not propagate, so here the need to code with nested try/except blocks.
                    If you have dependencies on how the JSON should look you should validate that, I recommend using JSON Schema as it's a very simple and readable way for describing that. If you have an API or in other way programmers creating the JSON you parses communicating how it should look is very easy by just giving them a schema.

                    Originally posted by blackshard View Post
                    I agree, but still I don't understand why classes don't behave like any other class instance in other languages. Instead I'm forced to use "with" statement or call the "destructor" manually
                    Java, the worlds largest garbage collected language doesn't have destructors for exactly the reasons described above.
                    Originally posted by blackshard View Post
                    Well you can mix server side code with frontend code with PHP, but it is not supposed that you do that, at least if you developed a bit of skill and knowledge. The nice thing about PHP being a template language is that you CAN use PHP files as HTML/XML/CSS/whateveryouwant templates and other PHP files as mere Controller code.
                    Should not is a great point, so why do it? There are loads of great template engines out there.
                    Last edited by Pajn; 03 October 2014, 11:29 AM.

                    Comment


                    • #30
                      Originally posted by Pajn View Post
                      Should not is a great point, so why do it? There are loads of great template engines out there.
                      You should try benchmarking those template engines against plain PHP, if performance matters you will end up not using a third party template engine. Even with some integrated cache mechanism third party template engines have to go thru some loops.

                      Comment

                      Working...
                      X