Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like the constructor property promotion, union types, improvements to exceptions and try/catch. Lots to like here.

Attributes worry me. Annotations are generally an eye sore to me, but in some places could be justified. For the most part, outside of Symfony, they were not used much. I'm worried that some developer will go bonkers with them, create a nightmare, and that will be the next legacy code base I inherit 5 years down the line.

Named arguments is okay I suppose, but IDEs solve knowing the order of arguments. I guess the IDEs will implement an auto complete for named arguments? I guess thats okay, but it will require more vertical code if you care about your lawn and keep your code in the PSR margins.

All in all I think this is a solid major, not the quantum leap we got from 5 to 7, but these are good additions. I'm sure we'll see plenty of decent additions in the minors.



> Named arguments is okay I suppose, but IDEs solve knowing the order of arguments.

Named arguments are incredibly helpful for functions with a bunch of optional parameters, like setcookie() -- instead of

    setcookie("cookiename", "value", 0, "", "", false, true);
to set httponly (the last argument), you can now skip over the unused parameters and write:

    setcookie("cookiename", "value", httponly: true);
Not only is this more concise, but it's also self-documenting!


I would have personally been happy with

    setcookie("cookiename", "value", , , , , true);
As I used in VB.Net 15 years ago, I have no idea if other languages (C#?) support that


Name parameters can benefit when you are reviewing code, beyond just when writing code; it makes clear what every parameter is for as you scan through code. This is most helpful with function calls with lots of optional parameters.

Another benefit is name parameters can replace the current pattern of passing a "parameter bag" array. Code checkers can catch mistakes here at time of compile, rather than runtime.

The negative of named parameters as implemented here is that the names are defined by the variable names in the function definition. So, renaming variables in the function definition will break code that calls the function using named parameters.


Named parameters along with property promotion allows for a pretty nice “Struct”-like pattern




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: