Giter VIP home page Giter VIP logo

Comments (6)

simPod avatar simPod commented on June 23, 2024 2

I'm the author of the PR so I'm biased but 100% agree with @derrabus

For instance getUser(): ?User naturally reads as "this method will return a user or no user"

getUser(): User|null reads the same.

from coding-standard.

morozov avatar morozov commented on June 23, 2024 1

Yes. int|null is better than int|string because as a set it has less capacity (null is just one distinct value) and often has the same semantics of "no value". The more specific the type is, the better.

The usage of NULL often naturally reflects the nature of the model being programmed. For instance getUser(): ?User naturally reads as "this method will return a user or no user". At the same time, the meaning of setParameter(int|string $parameter, ...) is not that clear.

from coding-standard.

derrabus avatar derrabus commented on June 23, 2024

The type declarations ?SomeType and SomeType|null are 100% equivalent and this rule enforces the latter. If we have multiple ways to express the same thing, it is perfectly reasonable to enforce one of the ways via a CS rule.

union types are often poor

A nullable type is a union. Your arguments apply to nullable types as they apply to any other union and I understand that avoiding unions is probably a good idea. However, I fail to see how this is relevant for our coding standard.

I don't think we should roll back.

from coding-standard.

morozov avatar morozov commented on June 23, 2024

Language shapes the way we think. I do not want the language (the coding standard) to force me into thinking in the broad categories of union types, I want to be able to use more expressive and specific nullable types, where necessary.

In my opinion, union types in PHP are a smell, and I do not want this smell to be enforced. Note, a smell doesn't mean that something is definitely wrong but it's often a sign that something is potentially wrong. As a reader of the code, I want to be able to spot a union without applying extra effort.

If we have multiple ways to express the same thing, it is perfectly reasonable to enforce one of the ways via a CS rule.

Following this logic, we should enforce the alphabetical order of class member declaration.

from coding-standard.

greg0ire avatar greg0ire commented on June 23, 2024

@morozov are you saying int|string and int|null are not equally bad, and that you want to spot the former more easily? In yes, can you please elaborate on why they are not equally bad?

from coding-standard.

greg0ire avatar greg0ire commented on June 23, 2024

I agree that I don't feel the same amount of disgust when I see ?User than when I see User|Car, and that maybe this case deserves a special treatment because it's not the same level of bad, so I'd lean more on the side of ?

getUser(): User|null reads the same.

To me it reads like "this method will return a user or null" … in case of failure?

from coding-standard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.