ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
418 stars 42 forks source link

Convention for abbreviation #64

Open masa16 opened 7 years ago

masa16 commented 7 years ago
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)
Try2Code commented 7 years ago

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.

kojix2 commented 7 years ago

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.

masa16 commented 7 years ago

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.