numo-narray icon indicating copy to clipboard operation
numo-narray copied to clipboard

Convention for abbreviation

Open masa16 opened this issue 8 years ago • 3 comments

a = Numo::DFloat.new(20,30).seq

This style is right as a Ruby code, but I prefer less typing.

First idea:

include Numo
a = DFloat.new(20,30).seq

In this case, you can omit Numo module name. However, Numo module functions like Numo.max(a,b) become top-level methods.

Another idea:

DF = Numo::DFloat
a = DF.new(20,30).seq

It is able to write more shortly. But it requires assignment. Collision of constant name may happen.

What is Numo-convension for abbreviaton corresponding to import numpy as np ?

New method for constructor is possible. Old NArray style:

a = Numo.dfloat(20,30).indgen!

Numpy style:

a = Numo.arange(600).reshape!(20,30)

masa16 avatar Jun 12 '17 12:06 masa16

AFAIK the is not such thing like import numpy as np - require is file-based, and include is modules based but does not support renaming.

Naming collision can also come from such statements in the same way as with your expression, so I dont really see a difference here. in fact, i like expressions ;-)

Ok, it's one additional line, but thats all. IMO the difference between Numo::DFloat and DF is neglectable, because I use autocompletion during editing all the time - so I don't really type it. And it's even easier to read, if the long form is used.

I see these import-renamings all the time in python scripts and it usually confuses me more than it helps. Perhaps it reminds me to much of this bad-but-still-so-popular habit of fortran programmers (around me) to shorted every variable or functions name to the very unreadable minimum.

Try2Code avatar Jun 14 '17 10:06 Try2Code

I think it is important to make the code smaller. To type Numo :: DFloat, you need to press the keyboard 12 times at all times. No 14 times (I forgot to press the shift key). This is a waste of life. And life is short. I think that "NArray" must be a tool that can be enjoyed even by school children. Children know which toys are the most interesting.

kojix2 avatar Jun 14 '17 14:06 kojix2

I consider NArray is not just like a library accessed through descriptive API. It will be a tool used also in command line or Jupyter notebook. I have already seen a code including include Numo, but I do not know they understand a side effect. So I think it requires the right manner of writing shortly. And it influences the design of Numo module.

masa16 avatar Jun 16 '17 02:06 masa16