46 comments
@IceWolf @woozle some of us are pushing PHP to be better. But improving comparisons is something I want to work sooner than later, but it requires some rework at the engine level. Incredibly early draft is here https://github.com/Girgias/php-rfcs/blob/master/comparison-equality-semantics.md @oschonrock @cptwtf @ramsey @Girgias @IceWolf Since we're on that subject, I'm always curious: what is (are) your preferred language(s)? @oschonrock @woozle @cptwtf @Girgias @IceWolf How do you define "statically typed language," and why don't you consider PHP one? @ramsey @woozle @cptwtf @Girgias @IceWolf I can tell this is going to be very boring already... If you use a statically typed language you will know about it. It will get in your way, the types will be pain, but when you get them right, then you can have a high degree of confidence that the code is already free of entire classes of error. This kind of '==' BS cannot happen. No type juggling. Not everything is a pointer under the hood. Objects have a size. ... TBC @ramsey @woozle @cptwtf @Girgias @IceWolf There is no runtime or interpreter. Non-existent variables in if branches don't compile. Your IDE/LSP can give you meaningful autocompletion and full syntax/type checking..... etc etc etc I used php for 20yrs. It is "not statically typed".. whether you like that term or not... it has a completely different feel to any of those languages I listed above on all of those dimensions. I have decided that for most things, I prefer the above languages. @woozle @ramsey @cptwtf @Girgias @IceWolf yes, the only exceptions to this are the implicit conversions available in c++ via "standard numeric promotions" and "implicitly converting constructors"... and in fact, both of these are mostly considered a "legacy anti-feature", and modern compilers and linters will warn against them.. (they can't be removed for backward compatbility reasons). @oschonrock @ramsey @woozle @cptwtf @IceWolf there is still a runtime in Go, C, C++, etc. To get more of that benefit you need a language that supports dependent types and/or effect types. Which is _far_ from mainstream. PHP is definitely not statically types by default, you can _kinda_ make it with SA tools and using a subset of the language. @oschonrock @ramsey @woozle @cptwtf @IceWolf C's type system is omega jank, and you do have type juggling via integer promotion. @Girgias @ramsey @woozle @cptwtf @IceWolf I did mention integer promotions elsewhere already.. and yes they suck and modern tools warn when you use that. but C's type system is lightyears ahead of php's which was the comparison here. There are other languages with more advanced type systems, but they are less widespread. @Girgias @ramsey @woozle @cptwtf @IceWolf yes, go and scala definitely have a runtime. (at different levels) c and c++ dont' really.... (and don't have to or bare metal) and yes their type system is not perfect with respect to lifetime and thread safety, but it's reasonably advanced and lightyears ahead of php which was the comparison here.. @oschonrock @ramsey @woozle @cptwtf @IceWolf PHP doing runtime coercions is related, but different, to its type system. And C pointer aliasing rules are a *thing* (and this ignoring type punning and void* hell). @Girgias @ramsey @woozle @cptwtf @IceWolf Please refer to my list above. in php a variable can change it's type, even without conversion. So the IDE/compiler/interpreter never knows the type at compile time. that is basically a non-existent type system in my book. And that's from 20yrs of practical experience using the language v4->v8. @Girgias @ramsey @woozle @cptwtf @IceWolf With regards to "nullptr" and "void*"... php just doesn't have an equivalent, because php does not allow manual memory management. Really this is a pointless discussion from my point of view. php and C or C++ are not comparable languages in almost every conceivable way. A more useful questions might be: When would using either language make sense: Would I write a server side webapp in C or C++? Prob not. Like using a tank to squash an ant. @oschonrock @Girgias @ramsey @cptwtf @IceWolf Well... I'd say "usually" or "by default", not "never". You can set the type for a member in a class, and get an error if you try to assign it a value of an incompatible type. ...but that's a pretty new feature. @woozle @Girgias @ramsey @cptwtf @IceWolf yeah.. and it's also "shallow"... because the type information is "lost" as soon as you call a method on that type and chain a few more calls. I have continued to try to use LSPs in php over the last 2 decades, they have very slowly got better, but as soon as you switch to what I call a "compile time statically typed language" the experience is night and day. @Girgias @ramsey @woozle @cptwtf @IceWolf the C "runtime"... is a misnomer... there is nothing "running" while a C-program is running. there is crt0 which runs *before* the c-program runs.. and the other stdlibs are "not required".. and in fact people write c -programs ion embedded systems without them all the time. They are libraries which are C-programs that you didn't write. You are clearly taking a pedantic approach. We don't need to agree. @oschonrock @Girgias @ramsey @cptwtf @IceWolf I think we're using the word "runtime" in two different ways. Both statements are right, but they're talking about somewhat different things. @woozle @Girgias @ramsey @cptwtf @IceWolf maybe... I mean "runtime" as in... there is something that my programme is "running on top of or through", without which it could not work.. That is not the case for systems languages like C,C++ or Rust. php/js/python/ruby and also JVM and .Net languages and to a lesser extent Go ... are just a different category of language. The php interpreter/runtime, call it what you like, is written in C/C++. So is the JVM. Could you write it in php? @oschonrock @woozle @ramsey @cptwtf @IceWolf I mean, someone did it for funsies: https://github.com/ircmaxell/PHPPHP Like nothing prevents it from being done. @Girgias @woozle @ramsey @cptwtf @IceWolf there goes the pedantic approach again.... "This requires that php be in your system path." you still need the php interpreter which is written in C/C++ in order to run the php vm to run the php programme.. have you ever heard of chickens and eggs? so.... "no"... basically. not to mention it would be prob be stupidly slow.. @oschonrock @woozle @ramsey @cptwtf @IceWolf You asked if the PHP VM could be written in PHP, I gave you a repo where someone did this 13 years ago. I didn't say it was a good idea nor that it would be fast. Nor is this even fully fleshed out. People have written a Python interpreter in Python and use it to run Python. There is nothing fundamentally *preventing* you from doing it. Chickens and Eggs exists with statically compiled languages when you need to boostrap it the first time too.... @Girgias @woozle @ramsey @cptwtf @IceWolf This is totally not the same... because you are still running a php interpreter at the outer layer in every case. In a systems language there is only the hardware. You are apparently unable/unwilling to understand the fundamental difference, or just really stubborn and pedantic. And with that I conclude the one thing that always irritated me more than anything else in php: The quality of understanding and discussion. I am out. Have a nice day. @oschonrock @cptwtf @ramsey @Girgias @IceWolf I always did like C++, as over-the-top as it is in some ways ^.^ This seems like good practice, which I will be adopting -- but also it kind of reinforces my point that the @preinheimer @woozle @IceWolf @cptwtf @ramsey @Crell yes, and frankly considering this premises comparing two strings as numerical makes _more_ sense than forcefully casting the string to an int, as it did prior to PHP 8. But more importantly `==` Vs `===` is a nothing burger. The behaviour of `==` is important because this is the behaviour used with the ordering operators (e.g. `=<`). And saying "eh just use `===`" kinda misses the point to why it is a problem. That one always made at least some sense to me -- you're comparing with a number, so of course the string needs to be cast to a number. But comparing two strings makes them into numbers?? Something rotten in the state of Denmark. What happens if you're comparing, say, two password hashes, and they both happen to begin with |
@Girgias @woozle Hahaha wow. And people say JavaScript is bad,,
PHP 8 seems to have a lot of nice stuff! We skipped, like, the entire history of PHP and only picked it up fairly recently.