remi icon indicating copy to clipboard operation
remi copied to clipboard

The editor should have reserved names.

Open emanuelelaface opened this issue 5 years ago • 4 comments

If you use the name, for example, Button for some widget and then you have a Button widget in the interface, the code will not run because the Button class will be re-assigned to the Button variable. It would be useful to have a warning of reserved names for the GUI creation in order to avoid to use variables called as pre-existing classes.

emanuelelaface avatar Dec 13 '18 08:12 emanuelelaface

Hi, I am not the greatest coder, probably not even a mediocre one. BUT, having learned from experience, I can advise you to never ever use generic words for your variables. Not even the words which might have a meaning. From my pascal days (good old Delphi), I have acquired a habit of following a naming convention: If its a button, start your naming with btn_ (i.e. btn_fantastic_button), a label: lbl_ , a string: str_ , an integer: int_ . For most compilers/interpreters it consumes same amount of memory. This way, you will not only be avoiding stepping on reserved names, but your code will also be much easier to read (even after a few months). Just a friendly advice ;)

bashkan avatar Dec 26 '18 18:12 bashkan

I know what is a best practice to code, the problem is that in a compiled language the reserved names are detected by the compiler and the user is warned. In Python you can overwrite any data type, so it is important to construct the libraries to avoid possible confusion with common names. I would never call a button Button, but to add an extra check in the gui builder seems a good idea to me because I do not know which names are used by the author of the library and there is the unfortunate case where I think to be creative enough in selecting a name while I am not.

emanuelelaface avatar Dec 26 '18 19:12 emanuelelaface

I haven't seen other libraries doing the same, if you collide a name it's mostly your fault.

You can always import remi as 'import remi' and reference every object as remi.gui.Button. That way you won't collide. You can also do it the other way around, if you wanna use that reserved name, you can do 'import remi.gui.Button as RemiButton'.

Also by PEP8 (I think) as a convention only class names begin with uppercase, so your variable (if you aren't defining a new class, ofc) should not start with uppercase.

If you use an IDE like PyCharm it may warn you about the collision too (I think).

It's a thing of Python in the end, not really of the library (if I understood the problem correctly). The flexibility of the language comes at a price.

(Sorry for typos, written from mobile).

On Thu, Dec 27, 2018, 06:08 Emanuele Laface <[email protected] wrote:

I know what is a best parctice to code, the problem is that in a compiled language the reserved names are detected by the compiler and the user is warned. In Python you can overwrite any data type, so it is important to construct the libraries to avoid possible confusion with common names. I would never call a button Button, but to add an extra check in the gui builder seems a good idea to me because I do not know which names are used by the author of the library and there is the unfortunate case where I think to be creative enough in selecting a name while I am not.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dddomodossola/remi/issues/257#issuecomment-450010627, or mute the thread https://github.com/notifications/unsubscribe-auth/ABpFdLSnGZZ5hMpJsS4dSGHj-YOHCOI0ks5u88kTgaJpZM4ZRKw7 .

awesomebytes avatar Dec 27 '18 01:12 awesomebytes

I think that reserved names are a good idea. A developer can't be aware of all used names in the framework, and so he could get simply to error. I will implement this in a near future.

dddomodossola avatar Jan 28 '19 08:01 dddomodossola