6 ms·
Why do they keep adding global functions like "intdiv"? For example in JS, it being another language with a similar compatibility burden, they are moving most o
by egeozcan 11y ago
Why do they keep adding global functions like "intdiv"? For example in JS, it being another language with a similar compatibility burden, they are moving most of the global functions (like parseInt) to "namespaces" (like Number.parseInt) while keeping global references there. When I open the docs (for example, the array functions page[1]), I get frightened by the global functions which do not seem to share a naming convention on first glance.
disclaimer: I haven't written anything significant with PHP since too many years.
[1]: http://php.net/manual/en/ref.array.php http://php.net/manual/en/ref.array.php
- debacle 11y agoThe internals list has a weird combination of die hard "PHP is PHP" people who really prefer for things to not change even if they are bad.
- deleted 11y ago[deleted]
- monk_e_boy 11y agoThis is ongoing in the PHP community. For those who like purity there are tons and tons of wrapper classes that hide all that stuff away. Modern IDEs autocomplete all the functions, I'm using PHPStorm and as soon as I type 'arr' it shows me a list of all the array functions with parameters listed. Not perfect, but if I was worried about that kind of thing I'd use Python (which I love) or RoR (which I also love). The ethos of PHP is to just get stuff done: http://axonflux.com/5-quotes-by-the-creator-of-php-rasmus-lerdorf http://axonflux.com/5-quotes-by-the-creator-of-php-rasmus-le...
- wtetzner 11y ago> The ethos of PHP is to just get stuff done I never understood this standpoint. I hear this from the Go community sometimes too. Wouldn't having some sane organization of functions make it easier to "just get stuff done"? Just like in Go, wouldn't generics make it easier to get stuff done?
- acomjean 11y agoPHP Developers who I've met at conferences and user groups talk about what they're building. Rarely do they seem to care that much about the language. I think many would be happy in many languages, its about being able to build something quickly. If its not elegant, nobody cares. There are a lot of frameworks (too many frankly) and tooling that enable quick building of custom sites.
- scotty79 11y agoWhen you put stuff in namespaces you need to remember in which namespace it is (and which library to refrence). Number.parseInt is not that bad but I'll take to_json() global function instead of (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize() (or was it Newtonsoft.Json.JsonConvert.SerializeObject()?) any day. Sure, names of PHP functions look arbitrary and inconsistent but when you know the name of the function you know everything you need (apart from how to use it which you can quickly and unambigously check like: http://php.net/file_get_contents http://php.net/file_get_contents )
- rjbwork 11y agoI just type JsonConvert and hit Alt-Enter. #JustReSharperThings
- scotty79 11y agohttps://www.jetbrains.com/resharper/buy/ https://www.jetbrains.com/resharper/buy/ But thanks. I was looking for thing that would import me proper namespace and reference proper dependancy. Doesn't help you that much though when Microsoft releases new version of its web stack, naming different things with same class names as before just putting them in different namespace. I still need to guess which of the namespaces I actually need when I'm trying to get running something that I found on the internet.
- taspeotis 11y agoThe basic functionality (given type X import namespace Y) is built into Visual Studio since who-knows-when [1]. In my opinion if you are doing a lot of commercial .NET development then ReSharper isn't an optional extra. Rather, it's money well spent. You get more complete functionality: ReSharper 8 added the smarts to look for NuGet packages in your solution and reference the correct NuGet package. (This is ALT+ENTER and it basically gets the right type and dependency first time around.) ReSharper 9 goes further and allows you to find types in any package on NuGet - JetBrains maintains their own index of NuGet packages for this purpose [2]. [1] http://stackoverflow.com/a/186920/242520 http://stackoverflow.com/a/186920/242520 [2] https://www.jetbrains.com/resharper/whatsnew/whatsnew_9.html#nuget https://www.jetbrains.com/resharper/whatsnew/whatsnew_9.html...
- TazeTSchnitzel 11y agoAll the existing math functions are global. If you add a new one, it's only fitting that it is global too. Having one and only one math function namespaced would be inconsistent.
- trebor 11y agoNot to mention, if they namespaced all math functions it'd break backward compatibility badly. Given that no core PHP functions are namespaced, I don't see why they should start now. Also, with the functions in the global namespace you can implement a namespaced copy that takes precedence within the namespace and its children. It can easily confuse people, but I've seen it used to force people away from string functions to their multibyte equivalents (it threw exceptions).