5 ms·
One of the main takeaways I got from the original Fractal of Bad Design post was the myriad of inconsistencies in both representation and execution of code. Thi
by Arbalest 7y ago
One of the main takeaways I got from the original Fractal of Bad Design post was the myriad of inconsistencies in both representation and execution of code. This was barely touched upon, mostly this post focused on how PHP has added features and ecosystem. But then so has Javascript.
- simion314 7y agoUnfortunately this is true and it can't be changed, the functions are named and parameters are soemtimes inconsistent like strpos and str_replace, I would have to use the docs all the time if my IDE wouldn't show me the param names. But after you get productive with PHP there is no feature that I think I am missing from other similar languages.
- richardwhiuk 7y agoIt can be changed. You have some syntax to opt into a later release (e.g. doing `<?php(version=8)` at the start of a script. In a major release, you then get rid of a load of cruft.
- pilif 7y ago> You have some syntax to opt into a later release (e.g. doing `<?php(version=8)` at the start of a script. imagine the exponential complexity as old behaviours need to be kept around for various levels of opting in.
- mgkimsal 7y agoThere's already been a degree of that with php.ini flags, and some of the behaviours available via those flags have been deprecated then removed over a period of years. It's not impossible. Yes, it's complex, but the process for dealing with that complexity has already existed and worked out ... relatively smoothly. The bigger issue is getting people to upgrade - I'm still dealing with a couple of projects - one started in 2017 - that are on PHP 5.6.
- richardwhiuk 7y agoThat's why you want to do it on a per file basis, not on a per interpreter basis, which allows a project to incrementally move. You also want a single version, not a gigantic pile of things to opt in to.
- hrktb 7y agoI would see it as javascript's strict mode, and I think most devs would ok with a binary switch. The only fear I'd have is a lack of big entity committed to PHP. In the heydays there was Yahoo, facebook and other giant companies relying on PHP and guaranteeing that there would be enough man power to weather any type of changes. Now I wonder how many people are left to push through breaking changes and rewrite/modernize the libraries and the ecosystem.
- wvenable 7y agoPHP already has a strict mode as well. It's pretty hard to imagine every developer typing in a long block of compatibility switches at the top of every file and then the mental load of maintaining a code base with some of those on and off.
- ken 7y agoThe complexity still has to exist somewhere, right? By avoiding this, they're just keeping it in all the developers' heads, rather than a legacy mode in the compiler. I'm not sure that's the wrong decision, but it's not a great one, either. Too much complexity in the implementation can kill the project. Too much complexity in the language can kill a person's hope of learning it.
- simion314 7y agoMany complaints are about the PHP standard libraries and not about the language itself, so you can learn the language just fine and just don't learn the old deprecated functions at all unless you hit such a function in a codebase and tehn you research it. . Is not equivalent to compare PHP+ standard library with JS core , PHP included function to read and write files, streams, databases,json,XML, run executables(if enabled), where in JS or other languages most of this functions are not standard.
- int_19h 7y agoThe libraries can also be treated in a similar manner.
- ifoundthetao 7y agoNamed parameters would be nice.
- DCoder 7y agoFeatures that I miss in PHP: - expressive type system with generics, union types, literal types, basically TypeScript. I can say "this function returns a string" or "this function returns an array", but not "this function returns an array of strings". - specialized collection/hashmap data structures with good support across third-party libraries. Having one array() structure acting as both a sequence and an associative array at the same time is awful. - a templating solution similar to JSX. I am spoiled by TypeScript's ability to typecheck my HTML views along with other code.
- simion314 7y agoI am not trying to say PHP > TS, just wanted to let you know in case you still work with PHP codebase that you can get good enough type checks with PHPDoc, here is a good example for the case you mentioned , in Intellij the built in linter will mark as warnings when you use types wrong https://i.imgur.com/NqlAsTd.png https://i.imgur.com/NqlAsTd.png (zoom a bit out and sorry for the bad crop) About the array issue don't we have same situation with JS and TS where you don't have dictionaries or hashmaps in the standard library and you have to use array or object ? I like JSX too, maybe some PHP template would be made to copy JSX , but not all ages need to be that interactive and not all PHP code is rendering HTML, my current project uses angular1 for the frontend (it was something already created so there was no debate what tool to be used where I could have voiced an opinion). As a personal opinion I prefer react to angular because I don't like the angular magic compile stuff, I like that react components are JS functions and I can breakpoint into a render functions. I also done some side toy projects with TS, I like it and I hope it gets more popular so new projects would use it but I am worried that we could get a wave of front end languages and we will not have a standard great language but many non standard languages.
- DCoder 7y agoIntelliJ will detect cases like that, yes. But it is difficult and slow to get IntelliJ to inspect your whole project like `tsc` does. With PHPStan or such tools you can do that more easily, but they still have interop problems due to non-standard annotation syntax. Having native support for such type expressions would be much better. ES6 has Map and Array, which are perfectly sufficient and distinguishable from each other. PHP core only has array() which tries to do everything. You can use array() to build a collection or an associative array and you cannot force it to only behave as one of those. Even Zend's PHP certification contains questions about what happens if you try to push a value into an array that uses associative keys. This is a joke. I prefer React over Angular as well, but interactivity was not on my list of goals. I want a template syntax that combines valid markup, escaping by default, and TSX-style typechecking. Basically, I want XHP [0]. There is no other template engine for PHP that validates "values passed into this template" against "values used in this template" like TSX can, and no engine that ensures you're generating valid XML/HTML markup. I certainly agree that this is far less important than powerful types, but hey, one can dream :) [0]: https://github.com/hhvm/xhp-lib https://github.com/hhvm/xhp-lib
- Kiro 7y agoAnd JavaScript is the best language in the world (with TypeScript).
- tuesdayrain 7y agoIt's sad how many people think I'm crazy when I say this. No other language feels as good as writing JS with ES6+ features.
- pshc 7y agoGradual typing (that you can opt-out from) makes for a smooth prototype-to-production experience. Wish more languages supported it.