Most active commenters
  • paulluuk(3)
  • hot_gril(3)

←back to thread

490 points jarmitage | 14 comments | | HN request time: 1.078s | source | bottom
1. paulluuk ◴[] No.40681492[source]
While this is really cool, I have to say..

> import warp as wp

Can we please not copy this convention over from numpy? In the example script, you use 17 characters to write this just to save 18 characters later on in the script. Just import the warp commands you use, or if you really want "import warp", but don't rename imported libraries, please.

replies(5): >>40681523 #>>40681706 #>>40681974 #>>40683394 #>>40685824 #
2. dahfizz ◴[] No.40681523[source]
Strongly agreed! This convention has even infected internal tooling at my company. Scripts end up with tons of cryptic three letter names. It saves a couple keystrokes but wastes engineering time to maintain
replies(2): >>40681717 #>>40682973 #
3. dr_kiszonka ◴[] No.40681706[source]
Interesting. That is a good point. However, if I saw someone writing numpy.array() or pandas.read_csv(), my first reaction would be to think they were a beginner.
4. physicsguy ◴[] No.40681717[source]
The convention is a convention because the libraries are used so commonly. If you give anyone in scientific computing Python world something with “np” or “pd” then they know what that is. Doing something other than what is convention for those libraries wastes more time when people jump into a file because people have to work out now whether “array” is some bespoke type or the NumPy one they’re used to.
replies(1): >>40682003 #
5. hoosieree ◴[] No.40681974[source]
The more Python I write, the more I feel that "from foo import name1,name2,nameN" is The Way. Yes it's more verbose. Yes it loses any benefits of namespaces. However it encourages you to focus on your actual problem rather than hypothetical problems you might have someday, and the namespace clashes might have a positive unintended consequence of making you realize you don't actually need that other library after all.
replies(2): >>40683519 #>>40712466 #
6. paulluuk ◴[] No.40682003{3}[source]
There is no way that "warp" is already such a household name that it's common enough to shorten it to "wp". Likewise, the libraries at OP's company are for sure not going to be common to anyone starting out at the company, and might still be confusing to anyone who has worked there for years but just hasn't had to use that specific library.

Pandas and Numpy are popular, sure. As is Tensorflow (often shortened to tf). But where do you draw the line, then? should the openai library be imported as oa? should flask be imported as fk? should requests be imported as rq?

It seems to happen mostly to libraries that are commonly used by one specific audience: scientists who are forced to use a programming language, and who think that 1-letter variables are good variable names, and who prefer using notebooks over scripts with functions.

Don't get me wrong, I'm glad that Python gets so much attention from the scientific community, but I feel that small little annoyances like this creep in because of it, too.

7. hot_gril ◴[] No.40682973[source]
It doesn't really matter
replies(1): >>40688163 #
8. Y_Y ◴[] No.40683394[source]

    import warp as np
Now you can re-use your old code as-is!
9. water-your-self ◴[] No.40683519[source]
> the namespace clashes might have a positive unintended consequence of making you realize you don't actually need that other library after all.
10. 2cynykyl ◴[] No.40685824[source]
This math is not adding up for me...isn't import warp necessary? So you only 6 more characters to write as wp. And anyway, to me savings in cognitive load later when I'm in the flow of coding is worth it.
replies(1): >>40726630 #
11. m463 ◴[] No.40688163{3}[source]

  import os as o
  import sys as s
replies(1): >>40699929 #
12. hot_gril ◴[] No.40699929{4}[source]
Those are already short enough, but if someone really wants to rename os to o, I won't mind.
13. hot_gril ◴[] No.40712466[source]
It's unlikely that two things with the same name in different packages do the same thing. It's also kinda unlikely that you have a collision in the first place. And if the theoretical problem with `import numpy as np` is that you forget what `np` is, then using `array` instead of `np.array` will have the same problem.

At the end of the day, this is a minuscule issue either way. I won't import stuff your way, but if you hand me code like that, I won't change it.

14. paulluuk ◴[] No.40726630[source]
Well it depends whether you're going to import all of warp or just the functions you need. But you're right for the most part, if you're just going to do "import warp" then my math is off indeed.

Anyway, I also don't really care that much about character count -- but it's the only reason I could think of for why someone would want to rename "warp" to "wp". If anything, abbreviating libraries like this will add more cognitive load because you have to remember what all the abbreviations mean and how to import them.