OperationalBina / PipeRT

MIT License
11 stars 7 forks source link

[Discussion] How to handle Nones? #50

Closed OmriKaduri closed 4 years ago

OmriKaduri commented 4 years ago

Hi all,

Some time ago, @MayoG responded on a question I asked him on this PR. It made me wonder what is the "Pythonic" way of passing nullable variables (i.e., passing variable which might be null, to or from a function).

A quick search and I found the Optional type, which I think is a better way to pass nullable variables. Moreover, using mypy's --no-implicit-optional command will enforce that passing variables which might be None without strictly specifying it won't be allowed. I prefer this way of passing arguments into a function (strictly declaring if they might be null).

Also, regarding returning values from functions I found this StackOverflow question. Again, this way of declaring that a function might return Null seems more robust to our case of development (Hopefully - large number of independent programmers).

What do you guys think?

MayoG commented 4 years ago

To my knowledge and opinion, when using a function it is on the user's responsibility to know what he sends as paramter, if the developer is nice enough to specify if it accepts NULL\None then great.

As u mentioned, Optional type seems a good way for the developers to mark their functions as ones that can handle None as return values and as parameters.

OmriKaduri commented 4 years ago

Hi @MayoG ,

You're making an optimistic assumption regarding the user's responsibility to know what he send (and recieive) to (and from) a function. Yet, In my experience, it's too optimistic, and I don't count (on myself specially) to be that repsonsible every time I write a piece of code.

So I think both of us agree that we want to add Optional types for variables that are passed around (to and from a function).

Any other opinions? @sionovd @ItamarWilf @ItayHoresh

itamarwilf commented 4 years ago

@OmriKaduri @MayoG in general, I'm a fan of python standard library typing module, since it really helps to make the code easier to understand and maintain, and also because some IDE's can alert you when you are doing something wrong.

Also, by the zen of python:

Explicit is better than implicit.

So I would go with Optional, as well as making sure that the methods returning Optional are well documented.

OmriKaduri commented 4 years ago

@MayoG @ItamarWilf @ItayHoresh

Thanks for your responses. Glad we made an agreement.

So, instead of refactoring all existing code - let's go with the boy scout rule. From now on, make sure you validate that in every PR parameters are passed using Optional when needed.

Thanks!