Hacker News new | past | comments | ask | show | jobs | submit login

If you rely on naming function to know if things can be mutated you're doing things wrong. The only source of truth is the type received.



Why? Let's say I have a table full of cars and have a method

> func Car(id string) Car

How do I know whether it fetched that from the database or created a new one and returned that to me?


Only the type Car matters, why would the function name tells you anything about mutation? It does not tells you if you receive *Car or Car or if it's a Car but pointers inside.


Because I want to know what function does?


Assuming Car() is a receiver function, you should be able to infer "how" the Car is "fetched" based on the type receiving the function call.

func (d CarDB) func Car() (Car, error)

The above tells you everything you need to know. As for usage, again, the type and now also the variable names should let you infer everything you need.

func f(db *CarDB) { c, _ := db.Car() }

The function name makes as little of a guarantee as to the underlying "how" as these other factors.


I think it's not possible to achieve with func name on its own, the closest thing I see would be comments on the function but again not reliable imo.


Absolutely not reliable. Comments get stale faster than anything else in the codebase.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: