source: at-w96k/content/en/posts/php-review.org@ 8ff16b8

Last change on this file since 8ff16b8 was 8ff16b8, checked in by Mikhail Kirillov <w96k@…>, on Jul 16, 2022 at 12:59:34 PM

Add php article

  • Property mode set to 100644
File size: 9.9 KB
Line 
1#+TITLE: PHP & Symfony: libre development perspective
2#+DATE: <2022-05-28 Сб>
3#+LANGUAGE: en
4
5* PHP and Symfony from libre development perspective
6#+BEGIN_abstract
7In this article I want to emphasise good and bad parts of php as a
8language and ecosystem. This article is mostly non technical and
9contains a lot of personal bias.
10#+END_abstract
11
12I use [[https://www.php.net/][PHP language]] and [[https://symfony.com/][Symfony framework]] at work. I don't like
13web-development at this point, but I have developed skills at that area,
14so I continue to do it. I am free software enthusiast, so it means I try
15to minimize proprietary software in my life, but in some areas it is
16harder than in others, one of them is the need to earn money for a
17living doing programming.
18
19** PHP
20[[../../public/images/php.png]]
21
22PHP is very popular server-side programming language, that being used
23mostly for web-development. It is tied for a use with an http-server,
24think of Rack or WSGI, but built-in.
25
26PHP characteristics:
27- No official updated specification or a standard
28- Weakly typed
29- Optional types with runtime checks
30- Garbage Collected
31- Procedural, but community has a strong bias towards "traditional" Java
32 OOP
33- Java-like autoloaded classes (but done by 3rd party software called composer)
34- OOP support, but not in a standard library
35- Standard library functions are mostly written in C
36- Extended by PHP extensions written in C
37- More static than dynamic
38- JIT Compilation, it is mostly faster than Python and Ruby
39- Documentation is available in many languages including Russian
40- Introspection is not great, but ~var_dump~ function is useful
41- Node.js styled package manager (uses json & installs everything in project folder)
42- Huge surface for different vulnerabilities
43- Uses sigils just for variables, so they are kinda useless
44- Even with OOP bias it doesn't support some OOP features:
45 - You can set fields of an object outside of setter functions
46 - You can't initialize some data types in fields, so you are forced to do that in constructor
47
48You might have read the article called "[[https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/][PHP: a fractal of bad design]]". I
49want to note, that the language is indeed have a feel that it was built
50on top of poor fundament. Most of issues from that article are fixed
51now, but the language still falls under weight of legacy and bad initial
52design choices.
53
54And yet it has good parts and that parts are important for business. That parts are:
55- Support from a big company (Zend)
56- Support of everything in C++ style
57 The language even has ~goto~ statement
58- C-like syntax, so many programmers can be quickly familiar with the language
59- Java-like OOP, so programmers can enjoy reading Martin Fawler
60
61*** Personal observations:
62- PHP feels like Bash or Perl with OOP features
63- Lack of many datatypes. Solve everything with list-hashmap datatype or
64 an object.
65- PHP classes are not first class objects, so you can't pass them as
66 parameters and forced to get strings like ~class::classname~
67- It is similar to Perl, but it doesn't have good regular expression
68 support
69- The language has cryptic error messages and it doesn't show parser
70 error column
71- There is no pipe operator and since most of standard library is a set
72 of function you can't chain/compose functions with each other and need
73 to repeat yourself.
74- Documentation lacks articles about debugging and builtin debugger is
75 not well maintained and difficult to use
76- Most CLI php apps doesn't use GNU Readline, so you can't autocomplete
77 and forced to use rlwrap
78- Most PHP projects and libraries have ads, paid screencasts,
79 certification and other beaties of corporate culture
80- Some PHP libraries includes non-free stuff (symfony cli was
81 proprietary and it advertise proprietary services)
82- Package manager has ads in it (or to be more precise packages have
83 ads)
84- Standard library is a mess because of C naming and lack of OO support
85 (everything is in global namespace)
86- Frameworks like symfony have data types reimplemented. Such stuff
87 should be in standard library.
88- The behavior of programming language is configured by ini config file
89 which is clumsy and not so good in general. Same program can behave
90 differently in a different configured interpreter.
91- Documentation is not versioned and some parts are missed or outdated,
92 but overall it is good documentation.
93- Good debugger is not bundled and built-in debugger is not documented
94 and not being used that much by a community.
95- var_dump function is good
96- Symfony doesn't type check everything. There are parts that can break
97 only in runtime.
98
99** Symfony
100Symfony is a web framework that wants to be Spring from java, but in php
101world. It uses OOP DDD patterns, Dependency Injection, DataMapper
102ORM. It is complex piece of software with good and quite detailed
103documentation.
104
105** Good parts for libre dev
106- PHP is not controlled that much by a single company like Java
107 controlled by Oracle.
108- PHP is fast for scripting language compared to others, but not as fast as Java.
109- Symfony provides backward compatibility promise.
110- Symfony is not highly tighten, so it provides much more flexibility
111 than monolith web frameworks like Django
112- Many developers are available. The language has C syntax and types are
113 optional.
114- Existing ecosystem of packages. There are less things to develop from
115 scratch (not that much packages compared to rails or django)
116
117** Bad parts for libre dev
118- PHP has single implementation and no standard which means that you
119 probably will have to leave if implementators do something wrong with
120 the only php interpreter. There are other implementation, but without
121 a standard it is harder to switch between them (See how it is done in
122 Common Lisp).
123- PHP licensing is a bit complext ([[https://lwn.net/Articles/604630/][LWN]]). You can't patch PHP without
124 changing its name. Devs have dropped GPL license.
125- PHP has extension system which mostly compiled C code. I think many
126 people don't read C code, so projects like Racket, Emacs or SBCL try
127 to minimize C part of implementation.
128- PHP doesn't allow monkey patching by default. You can't redefine
129 standard library at all. No [[https://en.wikipedia.org/wiki/Advice_(programming)][advices]] from Common Lisp / Elisp world.
130- PHP tooling is mostly proprietary. It lacks proper emacs/vim
131 support. Libre LSP servers are unmainteined or too laggy. Most people
132 just use PHPStorm which is proprietary software or proprietary LSP
133 server.
134- Packagist contains non-free packages.
135- Packagist doesn't store packages, it just contains links to git
136 repositories. Haven't checked, but there is a possibility, that
137 packages can be replaced by /git push --force/.
138- Since C standard library is written in C it is hard to reimplement and
139 fix code. It doesn't violate freedom of modification since you can fix
140 your issues in C code, but it makes restrictions in emacs thesis sense
141 where you can redifine everything in available system. It is
142 applicatable to other programming languages too.
143- Same goes to OOP. Property modificators make restrictions to user to
144 modificate some parts of a program even if it is a broken part. There
145 is Reflection API for fixing such issues or you can inherit broken
146 class to a fixed class, but you can't really redefine some properties
147 and methods.
148- Symfony uses Stack Overflow instead of mailing lists. Stackoverflow
149 needs auth, it is proprietary on server side and it uses proprietary
150 javascript on client side.
151- Symfony uses Slack instead of IRC/XMPP. Slack is corporate messaging
152 solution, it is proprietary at server side and it uses proprietary
153 javascript on client side. It is unusable with javascript disabled or
154 with LibreJS extension.
155- Composer and Symfony show ads while installing packages.
156- Symfony has tons of ads on their documentation page. Symfony is
157 promoting their proprietary services in docs pages. There is no
158 documentation in info/man format without additional ads.
159- Symfony requires some javascript to develop it and in some cases to
160 use it as a visitor of your website.
161
162*** Why procedural OOP might be bad
163Symfony and PHP heavily rely on OOP. I don't like several things in that
164paradigm. The first is access modificators which makes a developer of a
165library in charge of its user. Luckily there is reflection in most OOP
166languages, so you can extend anything you want. Many people think it is
167bad, but library devs can do mistakes or just abandon their libraries
168and you want to modify them to work. The second is Inversion of Control
169pattern. It is bad mostly by the same reason as the first one, you lose
170control over some code. Instead of you running the code it is someone
171else running your code (mostly classes).
172
173This is not so critical since all the code is available for free as in
174freedom, but this can be kinda annoying while working with third-party
175code. My motto is that the most useful features that provide freedom to
176developer are: Introspection, Reflection, Macros.
177
178** What to improve
179- Remove ads from Symfony docs and host it elsewhere
180- Remove ads from Symfony docs and make it available in info/man formats
181- Do the same for PHP documentation website. HTML docs are not cool at
182 all.
183- Create licenses file for LibreJS
184- Remove all ads from package manager
185- Remove all proprietary services in symfony cli binary
186- Create mailing lists, because stack overflow requires non-free
187 javascript to read. SO is impossible to use offline.
188- Create IRC <> Slack bridge or just irc room. Slack is proprietary and
189 unaccessible by many people.
190
191** Libre projects using Symfony
192- [[https://www.gnusocial.rocks/v2/][GNU Social v2]]
193
194** Conclusions
195Overall PHP and Symfony is not bad choice for libre development, but I
196would recommend to stick with python if it is available. PHP is better
197than Java in a sense, that it has much less corporate proprietary
198influence. I see corporate influence also in Ruby ecosystem where almost
199every package has sponsors by large companies, Python is much more clear
200in that regard.
Note: See TracBrowser for help on using the repository browser.