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...
Announcement
Collapse
No announcement yet.
PHP As A Next-Generation Programming Language?
Collapse
X
-
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.
Comment
-
Originally posted by riklaunim View PostCamelCase is quite common for class names I would say. It's not JavaScript-one-style though.
Originally posted by riklaunim View PostNested 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.
Originally posted by riklaunim View PostThere are "with" and "finally" statements if needed. Plus it's better to be explicit.
Originally posted by riklaunim View PostThere are other solutions/implementations for that if you need it I didn't had any GIL problems with my code.
Originally posted by riklaunim View PostPHP 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.
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
-
Originally posted by blackshard View PostQuite 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 blackshard View PostWell, 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 blackshard View PostI 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 blackshard View PostWell 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.
Originally posted by blackshard View PostMost 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.
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
-
Originally posted by blackshard View PostAnyway also python has its nice pitfalls, like
- mixed naming conventions (camel case and underscore names)
[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
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
-
Originally posted by blackshard View PostSo 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.
Originally posted by blackshard View PostWhat 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.
Originally posted by blackshard View Post- mixed naming conventions (camel case and underscore names)
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
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)
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)
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.
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
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
-
Stupid editing time, now I have to double post.
Originally posted by blackshard View PostWell, 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 blackshard View PostI 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 blackshard View PostWell 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.Last edited by Pajn; 03 October 2014, 11:29 AM.
Comment
-
Originally posted by Pajn View PostShould not is a great point, so why do it? There are loads of great template engines out there.
Comment
Comment