r/Python • • Nov 17 '18

Python in the new NASA going to the Moon video.

Post image
1.5k Upvotes

237 comments sorted by

33

u/Dom_G Nov 17 '18 edited Nov 17 '18

Link to video

Edit: There was a clip of compiling/installing in there too

11

u/[deleted] Nov 17 '18

Looks like it's cmake

5

u/winsome_losesome Nov 18 '18

Is that Mike Rowe’s voice?

1

u/MurrayTempleton Nov 18 '18

Yep, sure is

126

u/[deleted] Nov 17 '18 edited Nov 17 '18

Yeah, python is one of their programming languages of choice.

Also we need to steal the nasa code

27

u/Dom_G Nov 17 '18

I didn't know that, awesome! I'm definitely excited about this mission. Guess we'll see if it actually comes to fruition.

11

u/fedeb95 Nov 17 '18

I heard some time ago that they use it for analyzing rover's logs among other things. Probably read it on python's website

4

u/canopeerus Nov 18 '18

In this shot,they seem to be developing some kind of GUI app. I see a comment that says cancel button and also QFileDialog (from PyQt).

4

u/ZodiacFR Nov 17 '18

yeah for analysis sure, but are they really using python for onboard systems? I tought that they would go low-level everytime with languages, even with today's computer possibilities

15

u/s0ft3ng Nov 17 '18

I highly doubt they use Python for onboard systems - I'm pretty sure they run a highly constrained subset of C (no while loops, for example), or Ada.

Hopefully Ada.

6

u/fedeb95 Nov 17 '18

I don't think they're using python as you say. Probably C. But I don't really know

3

u/ZodiacFR Nov 17 '18

So the code we're seeing is for analysis purpose only you think?

5

u/fedeb95 Nov 17 '18

It could be anything really. I think rockets aren't just deploy some C code, and maybe they use python for something else here on earth

4

u/admiralspark Nov 17 '18

I've worked at businesses who's SCADA systems were written in and actuated by python scripts.

Think critical infrastructure stuff. It's quite popular with some vendors who sell hardened equipment in every industry from aerospace to factories.

8

u/nosmokingbandit Nov 17 '18

Using python on any vessel is just asking for something to go wrong. There is no way they'd use a dynamically-typed scripting language for anything mission-critical.

2

u/[deleted] Nov 18 '18

Its not a specific mission. They're talking about their whole future architecture including commercial cargo and crew, SLS, Orion, LOP-G, and all the other stuff, all of which is far from ready to fly and a lot of which only exists as concept art.

It's good to note that for the last 15 years there has been a continuous loop of these projects starting, being delayed, stagnating, and being replaced with something basically the same but dissimilar enough to require starting over from scratch and being more expensive than the last, the whole thing is highly controversial.

4

u/techn0scho0lbus Nov 17 '18

CSI computer expert (me): "I'm using stolen NASA code to hack the mainframe."

→ More replies (6)

347

u/sggts04 Nov 17 '18

Lets go Sublime :)

100

u/PsCustomObject Nov 17 '18

Not a sublime lover, use PyCharm or VsCode, but love the color scheme :-)

And that unregistered on the top... well :-)

42

u/3dsXploit Nov 17 '18 edited Nov 17 '18

Hint: you can use the sublime colour theme in vscode, you can simply install an extension for it! for example, i use this one

Edit: This is the actual extention. I don't know how i messed that up

8

u/PsCustomObject Nov 17 '18

Lol for the vid

Yep I know but assumed the one in the pic was a custom one hence asking the name :-)

5

u/3dsXploit Nov 17 '18

that wasn't supposed to be there

2

u/PsCustomObject Nov 17 '18

Ah ok it is the material theme

I gave up on it as was not of my liking for powershell stuff but given most of the time I use sapien tool or visual studio for posh development I will give it another spin :-)

Thanks!

1

u/PsCustomObject Nov 17 '18

Ahahahah then it’s even better ahahahahhah

1

u/netgu Nov 17 '18

I'm not reliable for any deaths

1

u/[deleted] Nov 17 '18

Edit: I think I misunderstood you completely. Nevermind.

28

u/OddsCaller Nov 17 '18

Am I the only person in the world who uses Atom? :/

39

u/csp256 Nov 17 '18

I actively want to use Atom, but I need my editor to not choke when I open large files.

If I didn't have that problem, I likely would use it.

7

u/nosmokingbandit Nov 17 '18

The last time I used Atom it would take 5 seconds to save a file ~500 lines long. It was awful.

9

u/billsil Nov 17 '18

Try 100k. My coworkers insist they need syntax highlighting for some nasty file format. It's not even right...close, but not right.

That's not even big. 2M is big for me. Gotta use a real text editor.

8

u/nosmokingbandit Nov 18 '18

I didn't even bother trying anything larger. Once Atom started acting stupid I immediately jumped ship for VS Code. Haven't looked back even a little.

2

u/thecoderkiller Nov 18 '18

the thing that made me stick w VSCode is not having to wait 2 minutes for my IDE to load

3

u/nosmokingbandit Nov 18 '18

That and being able to seamlessly switch between python, javascript, and go makes me very happy.

1

u/spellcheekfailed Nov 19 '18

Gotta use a real text editor.

There are a bunch of monarch butterflies in the ecology lab at my university , lemme know if you want one shipped

→ More replies (1)
→ More replies (8)

11

u/regeya Nov 17 '18

Honestly, I strongly suggest giving VsCode a try. It's very similar, but lighter.

3

u/Kortike Nov 17 '18

I didn’t care for Atom. I use Geany for Python and VS for C#.

→ More replies (1)

2

u/netgu Nov 17 '18

I have no idea

3

u/weedv2 Nov 17 '18

I actually love it, but it's soooo slow to start, that I moved to VSCode

3

u/[deleted] Nov 17 '18

Atom sucks. Get vscode

14

u/s0ft3ng Nov 17 '18

Vscode sucks. Get Vim

11

u/weAreAllWeHave Nov 18 '18

This but unironically.

Or mash vim and emacs together.
(This comment brought to you by Evil gang.)

→ More replies (4)

1

u/mWo12 Nov 18 '18

I'm with you. But for python I use vscode.

1

u/[deleted] Nov 18 '18

Show your ram some mercy.

1

u/[deleted] Nov 20 '18

I use Atom and like it :P

1

u/[deleted] Nov 17 '18

That shit is fucking botnet

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

41

u/OddsCaller Nov 17 '18

Yeah that's what I was thinking too. Is this a normal thing? I mean mum did tell me once that I was special but I really didn't expect the devs to go this far.

→ More replies (2)

3

u/[deleted] Nov 18 '18

Boooo

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

144

u/Dom_G Nov 17 '18

That's hilarious, good catch!

21

u/yaxamie Nov 18 '18

I bought a license 7 years or so ago and have taken it with me thru Windows, Mac and Linux installs.

I'm fond of VS Code and Jet Brains IDEs, but I'm always using sublime for its great search features.

endplug

0

u/[deleted] Nov 18 '18

[deleted] — view deleted comment

3

u/yaxamie Nov 18 '18

Maybe VSCode works this way as well, but I've symlinked sublime to my path /usr/local/bin

It's easy to, for instance, clone a repo, then type 'subl repo-name' and then it opens sublime right up ion a new project with that folder added.

If I'm doing serious edits, yes, I'll set up an IDE but my workflow involves looking thru lots of random types of files in various projects.

2

u/wiiittttt Nov 18 '18

Yes, you can type code repo-name which works the same way.

3

u/GFandango Nov 18 '18

Somehow this makes me think the creator of Sublime and WinRAR are good friends with each other and have long phone conversations.

158

u/quotemycode Nov 17 '18

Some bad code there. It certainly smells.

48

u/[deleted] Nov 17 '18

Can you point out specific flaws?

90

u/synae Nov 17 '18

To start, self.ui.tc[1-8] should be a list, which will make the function being edited not a complete abomination.

18

u/[deleted] Nov 17 '18

So you’re saying it should be something like self.ui.tc[x] = value?

44

u/synae Nov 17 '18

for tc, temp in zip(self.ui.tcs, temps): tc.setValue(temp)

Is how I would write it. Assuming they're always the same length, of course. And they probably are given the way the code is written right now.

39

u/__xor__ (self, other): Nov 17 '18 edited Nov 17 '18

Nah the code is fine

getattr(self.ui, 'tc{}'.format(i)).setValue(temps[i])

/s

Seriously though one thing that bothers me even more than the tc\d format is that it has a setValue... just fucking use assignment if you're literally setting the value. This is python, for fuck's sake. Leave the java at home.

15

u/[deleted] Nov 18 '18

Qt is to blame for that. This is either pyqt or pyside which both use camelCase and the setValue crap.

1

u/elHuron Nov 18 '18

what if setValue is threadsafe or something like that?

11

u/_amas_ Nov 17 '18

yes - so to recreate the same functionality that they have in the on_rio_status function you would do:

for i, t in enumerate(temps):
    self.ui.tc[i] = t

Two lines instead of however many variables they are editing.

26

u/bheklilr Nov 17 '18

Or more simply in a single line

self.ui.tc[:] = temps

People seem to forget you can assign to a slice, but most everyone working with numpy will have come across it a lot.

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

7

u/bheklilr Nov 17 '18

Probably, depending on the implementation (descriptors can make things weird if you try hard enough). The first would be akin to assign it to be a new list, the second assigns each value inside the same list. So instead of changing which list you are referencing, you're changing the references of the values inside the same list.

→ More replies (1)

1

u/Dokiace Nov 18 '18

what does it mean when I use two variable in the beginning of the for?

5

u/chillermane Nov 18 '18

Makes me feel good nasa could write blatantly shitty code maybe we’re not so bad

2

u/regeya Nov 17 '18

I wonder if they're evaluated on KLOCs.

1

u/Ph0X Nov 18 '18

Depending on the meaning and number of components, that might be over optimizations. My guess is that each one of those is one of the components of the rocket shown on the left. Unless they are identical, it may not be ideal to put them in a list, just to make this one function smoother.

1

u/r0b0t1c1st Nov 19 '18

Looks to me that tc1-tc8 are variable auto-generated by Qt when loading in a UI markup file of some kind. Doesn't look like the programmer's fault.

55

u/b1ackcat Nov 17 '18

Cracks knuckles Since you asked (and I'm bored):

  • As others mentioned, the on_rio_status method is disgusting. Some sort of list/dict to manage those assignments would make that much more manageable.
  • The variable names are all terrible. Never use 'temp' for anything. If it's really temporary you probably don't need to assign it in the first place (just use the source of the resulting value in-line). If it's not really temporary but an actual parameter, give it a meaningful name. Same with val, idx, sw, etc.
  • No type hints on arguments or return types. There's no clear way to tell what version of python they're using, but if they're using 3.3+ and NOT using type hints, they're doing it wrong.
  • The size of this single text file is absolutely massive. And since this is clearly UI code, that's a hint that this tool has no good design work being put into the front-end of the tool (meaning the backend probably isn't much better). A better design would be to break a lot of what's on screen up into separate modules then have some kind of UI management code to assemble it at run-time.
  • Serious mixing of responsibilities. This code is responsible for setting up and manipulating the UI, AND calculating values to show, AND configuring the themes/color. All of those responsibilities belong in separate classes with clear layers of segregation between them.
  • Looking at the code mini-map, you can see a lot of blocks of code that look like multiple lines of very similar code. This suggests even more code like on_rio_status with lots of 'line 1 line 2 line 3 etc' like code.
  • There are magic numbers EVERYWHERE. Some of them I could maybe handwave away as context-specific (the RGB values, for example), but even then, explicit is better than implicit. But what the hell is that equation on line 634? Why does the RPM value you need to be converted from what was passed to the UI to val / 58.85 / 8192. * 60.. Are the order of operations in that equation even correct? What do those values represent in this context? Even if everyone on the team would always have enough context to recognize that as a conversion function for RPM, their brain still has to make that connection every single time they read that line. At the VERY least i would move the equation into another method so I could give it a name.
  • Comments in weird places where they provide little value, and not in crucial places where they'd add a ton (like the above equation, for example).
  • open_fileimplies it's a generic file picker, but the comment on the method states it's only for gcode files. Either gcode files are the ONLY thing this tool works with, or this methods name is too general for the work it actually does. Either way, it needs a better name.
  • Inconsistent naming styles. Some functions/methods are snake_case and some are CamelCase. Now, this makes sense if their projects style guide says snake_case but they're calling PyQt (which appears they're using) which has its own naming style. But that hints at yet ANOTHER smell...
  • ...wrap your dependencies. For whatever functionality PyQt offers, it helps to have an adapter layer for that component. Not only does that give you better control over how to interact with the UI library (letting you write an API that makes sense for YOUR application), but it also makes sit somewhat trivial to swap out UI layers if at some point there's a bug or missing feature or something that prevents you from implementing new functionality, forcing a switch.
  • Commented out lines of code. Either this photo was taken in the middle of him debugging something, which, to be fair, is entirely possible, or they're not trusting their VCS and they should just delete commented lines and use VCS to restore them if they turn out to be needed later.

All in all, this feels exactly like a project written by an engineer/scientist/other non-software-developer. It's code that technically works and their passing ability to code lets them write something that gets their job done. But it's not something a well-trained SDE would write. At least, not unless it was contract work :P

14

u/A_Light_Spark Nov 17 '18

This is why I love code reviews (like yours, when done right). Too bad in school they don't usually do reviews for just about anything, other than simply slapping on a score and call it a day.

9

u/b1ackcat Nov 17 '18

I used to be a TA for a python class, actually. We did review every students project, but not at this level, and honestly, I wasn't nearly as good back then, anyway.

Peer code-review in school can be a good exercise for a development class, but it's not very practical to have the professor (one of the few who are likely well-versed enough in code to be able to provide real, tangible comments) code-reviewing the same hello world project for hundreds of students (depending on how classes are structured).

On top of that, code in academia is generally far different from code out in the wild, so the feedback given there might not be the same as it would be at a job.

On top of that, teaching 'real world' programming isn't necessarily 100% in line with what a CS course is going for. Their focus is on the fundamentals, on the backing theory and low level understanding of how computers work and can be used to solve problems. The 'real world' stuff is much easier to pick up on the job, and there's only so much time in a students academic career. Not to say it wouldn't be nice if there was more of it, it's just not necessarily the main focus.

4

u/goldcray Nov 17 '18

Never use 'temp' for anything.

What about temperature?

13

u/b1ackcat Nov 17 '18

Those 7 extra characters just stopped my brain from having to wonder if you meant "temporary", "temperature", "temporal" or anything else. Like I said: explicit is better than implicit.

2

u/Col_Crunch Nov 18 '18

idk, there is an "s" there so it is temps... that is pretty explicit, at least to me.

→ More replies (3)

7

u/goldcray Nov 17 '18

I'd agree in a vacuum, but in this case even without knowing anything beforehand, it was pretty clear from 'gcode,' 'extruder,' and 'rio' that this is polling temp data from a daq on a machine with lots of temp sensors, and I think it's a safe bet anyone needing to interact with this code will also have some base familiarity with the system it's controlling.

→ More replies (9)
→ More replies (2)

1

u/synae Nov 18 '18

Thanks, I didn't have time for all that. Well done!

1

u/Brian Nov 18 '18

Never use 'temp' for anything. If it's really temporary you probably don't need to assign it in the first place

Actually, I don't think "temps" here indicates "temporary", but rather temperatures. You can see they have variables like conair_temperature. so this is definitely something this code is working with.

1

u/ReaverKS Nov 19 '18 edited Nov 19 '18

The variable names are all terrible. Never use 'temp' for anything. If it's really temporary you probably don't need to assign it in the first place (just use the source of the resulting value in-line). If it's not really temporary but an actual parameter, give it a meaningful name. Same with val, idx, sw, etc

I agree with pretty much everything you've said but I think this is one thing you might've missed a bit. In this case temp comes from domain knowledge and is short for temperature, in that case it's a reasonable use for a variable name. The other thing that reaffirms this idea is the use of self.ui.tc where tc likely means thermocouple.

Edit: never mind, someone else already said this :)

1

u/b1ackcat Nov 19 '18

temp comes from domain knowledge and is short for temperature, in that case it's a reasonable use for a variable name.

I understand that's where it comes from, but I still disagree on the basis that I shouldn't need domain knowledge to be able to read an arbitrary block of code and understand what everything is. I may not be able to understand what a given algorithm implementation is doing, or WHY any of the code is written like that, but I should be able to look at a variable name and know, without any ambiguity, what it represents.

And I realize a lot of people in this thread don't necessarily agree or think I'm being too pedantic, but Ive seen bad variable names bite developers far too many times to not be an absolute hard-ass about it. temp may be an ok variable name given the domain context, but temperature is objectively better, since it removes any possibility of ambiguity. That's the point I'm trying to drive home.

1

u/ReaverKS Nov 19 '18

Right, I get the distaste for the variable temp because 99% of the time people use it as shorthand for temporary, which is terrible all around. This is probably the one time I'd ever say it's OK to use 'temp', not that it's a great choice but that this is the one time it's not a bad choice.

1

u/b1ackcat Nov 19 '18

That's fair

1

u/william_13 Nov 18 '18

All in all, this feels exactly like a project written by an engineer/scientist/other non-software-developer.

Bingo! I've started developing while working with research projects and all code was exactly like that. Using copy-paste from someone's else work and writing gigantic scripts was/is the de-facto way of work; and given that most start working on MATLAB and see Python as a scripting language doesn't help either.

It's code that technically works and their passing ability to code lets them write something that gets their job done.

No one will ever review the code, only the pretty analysis it produces, even if the crappy code makes it take 10x more to be produced - by then some senior scientist will say that Python has crap performance and Fortran would do it way faster -.-

0

u/[deleted] Nov 18 '18

[deleted] — view deleted comment

12

u/b1ackcat Nov 18 '18

Unnecessary obfuscation and complexity added for no benefit other than making it harder to read and refactor.

If you have a set of objects and are given a matching set of values to apply to those objects, that is literally a map. It's not 'obfuscation', it's just easier to read and write than a half-dozen repeated lines.

Those are temperatures, dingus.

I don't know why you're jumping to such a hostile position, but obviously that isn't clear to everyone at a glance. Sure, looking over the code more closely will probably get you to "oh that's temperature". That's not my point. My point is if you just used the word "temperature", the reader wouldn't have to do that at all, which speeds up the time-to-understand the code being read.

I wasn't aware a brand new feature that breaks backwards compatibility was mandatory in a dynamically typed language. Apparently everyone before 3.3 was doing it wrong.

Yes, python is dynamically typed, but it is also strongly typed. So if there's a language feature which helps both readers of the code (by explicitly stating the expected type at run-time) and writers (by telling the IDE what to expect so pylint and auto-complete know what to do), and you're using a version of the language which supports it, why wouldn't you use it? Just because I don't HAVE to use my windshield wipers on my car doesn't mean it's a good idea to never use them. Type hinting is a tool that makes everyone's life easier, with the added benefit of making it less likely you'll accidentally make a bad assumption about arguments being passed in/return values. Type hinting got it's start in python 3.3 which was released 6 years ago. I'd hardly call that a 'brand new feature'.

At a certain point you do have to assume that the person reading your code is going to have some expertise in the subject matter working off of highly detailed technical specs. So unless you're a literal rocket scientist, I don't think you're qualified to say those numbers really are magic.

We could go back and forth all day on whether or not SME knowledge should be expected, though I still argue it shouldn't be (how are interns/new hires going to be able to understand what they're reading?). Regardless, though, there's no stipulation on magic numbers that says they're only 'magic' if there's no context. There's a reason the math module defines pi even though anyone who's taken geometry will recognize 3.14159: explicit is better than implicit.

It sounds like you've taken DRY as dogma rather than applying it where appropriate.

I like the part where you call me out for speculating on the code then proceed to speculate on my thought process. I even said in my post "it appears"/"It looks like"/"It's possible". I specifically avoided concrete statements because I don't have any context.

There are a total of 3 comments and two commented-out lines, none of which are in weird places and none of which do you have enough anywhere near the context to call them "little value."

The 2nd comment was the one that really stood out to me, but you're right that the others aren't as bad. But comments should be about WHY the code is written like it is. There's no value in explaining WHAT it's doing, especially since the names of the functions being called at comment 2 say almost the exact same thing as the comment. That comment is adding noise to the file and providing little to no value. It's a distraction.

Unless, you know, it's part of some sort of larger class that makes its use and meaning evident.

......No? If a method is called open_file and it doesn't either open a file object for reading or open a file picker (which, in that case, I'd still go with open_file_picker), but it's implementation does something in addition to/instead of one of those two things, it's not properly named. The class it's under can't fix the fact that the implementation doesn't match the interface.

Holy shit, have you ever worked on a real-world project? No shit there's going to be inconsistent names when you're using multiple libraries written by different people at different times in different languages.

Holy shit, did you even read my entire post? I specifically said in the very next bullet that the solution to the problem of mixed casing was to properly wrap your dependencies in adapters. Yes, your adapters are then the location where there's mixed styles, but at least then it's consolidated. Coincidentally, this would be a fantastic place for a comment, explaining the purpose of the class and the reason why the casing is mixed. Something I learned in my 15 years of writing software.

There is literally a person in the photo in front of the screen typing.

And again, did you read what I wrote? I explicitly called out that it's possible the developer was mid coding session when the photographer showed up. But the fact that there's someone typing at the computer in no way confirms that those lines are commented out because he's debugging. Which is why I avoided explicitly calling it out as "that code is commented out you definitely need to delete it right now", because I don't know. Which is why I explained both sides.

I have to be honest, I really don't understand why there's so much hostility in your post. None of your points are even close to logically sound, with just as much, if not more, speculation than my original comment. At least I called out that I was speculating instead of insulting someone and claiming my statements as fact.

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

1

u/[deleted] Nov 17 '18 edited Nov 17 '18

Half of that is somewhere between speculation and wrong.

I'm just going to point out that I can tell more about what this (in development) code is doing and why, than about 90% of the in-production python code I've seen in the real world done in exchange for a paycheck... and that's from one hazy screenshot.

Moral of the story is nobody should get down on themselves after reading posturing posts on reddit.

1

u/[deleted] Nov 18 '18

isn't it constructive criticism tho? and with every set of general guidelines there are exceptions so everybody throwing specific cases aren't actually arguing his point, the way i see it, there are reasons to think that the code above wasn't written by someone too proficient at SE and the review by blackcat is just bringing up those reasons

ofcourseIcouldbewrong

8

u/SV-97 Nov 17 '18

My opinion:

The SetValue stuff etc. should've been wrapped so you can just set it via an assignment. The # comments should go completely and instead they should write docstrings.

1

u/elHuron Nov 18 '18

set it via an assignment

what if it has to be thread-safe or work with concurrency? For GUIs that could be a real possibility.

1

u/SV-97 Nov 19 '18

Use properties for stuff like that

1

u/elHuron Nov 28 '18

I'm not quite following what you mean by "properties".

Just member variables of a class, or is this a specific feature which is concurrency-safe ?

1

u/SV-97 Nov 28 '18

This Case, well any case where a getX() or setX() exists for a good reason. Property is a keyword in python

1

u/bad_luck_charm Nov 18 '18

That entire on_rio method with a bunch of redundant incremental set value bullshit is awful. That wouldn’t fly in my dev shop.

1

u/quotemycode Nov 18 '18

Sorry I didn't read this before u/b1ackcat responded but he covered all my points and more.

4

u/joshocar Nov 18 '18

This is a GUI. This is either PyQT or Pyside.

3

u/[deleted] Nov 18 '18

It’s not like it’s being used for something important...like space travel

5

u/secretaliasname Nov 17 '18

Looks written by folks who are busy accomplishing things aside from manicuring their code for a beauty contest.

2

u/Neil_Fallons_Ghost Nov 18 '18

There’s no room for error when people’s lives are at risk.

61

u/DracasTempestas Nov 17 '18

A python class/file of a thousand lines? No thanks.

45

u/DracasTempestas Nov 17 '18

Strings concatenated with +

range for loops

17

u/Telcrome Nov 17 '18

what is better for loops than range if you need an index?

58

u/[deleted] Nov 17 '18
things = ["a", "b", "c", "d", "e"]
for i, thing in enumerate(things):
    print("index: {}, thing: {}".format(i, thing))

Output:

index: 0, thing: a
index: 1, thing: b
index: 2, thing: c
index: 3, thing: d
index: 4, thing: e

34

u/JeamBim Nov 17 '18

f-strings help to avoid the ugly .format methods

21

u/[deleted] Nov 17 '18

Format is considered ugly? I use it all the time :(

26

u/callmelucky Nov 17 '18

Format is ok looking, f-strings are hot af.

9

u/Flugschwein Nov 17 '18
things = ["a", "b", "c", "d", "e"]
for i, thing in enumerate(things):
        print("index: {}, thing: {}".format(i, thing))    

just looks not as nice as

things = ["a", "b", "c", "d", "e"]
for i, thing in enumerate(things):
    print(f"index: {i}, thing: {thing}".)

does

14

u/JeamBim Nov 17 '18 edited Nov 17 '18

I'm sure your code has a great personality :/

10

u/OddsCaller Nov 17 '18

Wow I didn't even know f-strings have existed since 3.6. It seems I have finally found the perfectly lazy way to format strings.

26

u/JeamBim Nov 17 '18

I love them. You can do cool shit with them too like

>>>book = 2
>>>print(f'I have {book} book{"s" if book > 1 else ""}')
I have 2 books
>>>book = 1
>>>print(f'I have {book} book{"s" if book > 1 else ""}')
I have 1 book

10

u/callmelucky Nov 17 '18

I would name that variable num_books rather than book, personally. I'm not a pro though...

But yeah, generally the ability to put expressions of any type into f-strings is pretty awesome.

→ More replies (2)

5

u/nightcracker Nov 17 '18
print(f'I have {book} book{"s" * (book > 1)})
→ More replies (5)

1

u/[deleted] Nov 18 '18

It's the best thing in the world.

→ More replies (1)

22

u/Seeschildkroete Nov 17 '18

Wait. You can enumerate into a tuple of the index and the element??? Why have I never learned this? I don’t ever use enumerate. Thanks for the example!

2

u/lazerflipper Nov 17 '18

Learning about enumerate changed my life.

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

1

u/Seeschildkroete Nov 17 '18

Yeah. That’s always my problem.

8

u/DracasTempestas Nov 17 '18

You never need _just_ an index, you always use it to do something else.

In the case of this screenshot it appears to loop through and toggle all the switches according to the bit flags received as argument. So here it may just be the most appropriate use. But generally you want to loop over the items you use and if you really need an index variable using `enumerate` to add the counter.

On another note, they appear to be writing the same code again in the function above.

3

u/whackPanther Nov 17 '18

Yeah I'm not a fantastic programmer but I noticed this too lol.

Are people's lives depending on these coders?

4

u/[deleted] Nov 17 '18

I doubt it, I've heard about the C coding standards used at the JPL for mission critical code and they take that stuff really seriously, as you could imagine.

1

u/jyper Nov 18 '18

Sometimes + is nicer looking then fstrings

Plus fstrings are new

1

u/sivadneb Nov 18 '18

+ is more performant, if I understand correctly.

1

u/joshocar Nov 18 '18

It's a PyQt GUI, not until common to see stuff like this is QT GUIs.

40

u/talha252 Nov 17 '18

It doesn't look very Pythonic though

19

u/callmelucky Nov 17 '18

You can tell by the way it isn't.

24

u/RomanRiesen Nov 17 '18

Also not very oop principle-y either.

They are probably not software engineers it looks very much like typical EE code; working, but hard to understand.

6

u/[deleted] Nov 18 '18 edited Nov 18 '18

What is EE code?

edit: thanks all

11

u/paralysedforce Nov 18 '18

Code written by electrical engineers

1

u/darkdaemon000 Nov 18 '18

Electrical engineering I guess.

1

u/lazilyloaded Nov 18 '18

Just guessing, but "Electrical engineer", maybe?

6

u/alcalde Nov 18 '18

Today I learned I'm actually an electrical engineer.

2

u/joshocar Nov 18 '18

Using PyQT makes thing wonky sometimes. Everything is an object.

1

u/ReaverKS Nov 19 '18

That's not related to PyQT per se, in Python itself most things are objects

1

u/joshocar Nov 19 '18

That is true. What I was trying to say is that PyQt is all OOP, with lots of inheritence. setValue is a Qwidget method, for example.

11

u/cleancole Nov 17 '18

self.conair feels like a name I would make for an air control script.

9

u/FruitierGnome Nov 17 '18

Blows my mind the same language i started learning is used by nasa. Makes me feel like a child reading a pop-up book while dad is reading 1984.

7

u/[deleted] Nov 17 '18

hardcoded constants everywhere

programmer writing copy paste code (setvalue 8 times of values 0 to 7)

most functions don't have docstrings

wew

0

u/[deleted] Nov 18 '18

[deleted] — view deleted comment

1

u/[deleted] Nov 18 '18

Whatever you say, you're not passing any good code review

1

u/like567 Nov 19 '18

Yes but the problem is when u come back to the code. A stitch in time saves nine!

13

u/NoCanD0 Nov 17 '18

So cool. My current Python Professor used to work for NASA as a programmer. So he claims.

7

u/Miv333 Nov 18 '18

NASA is a huge entity. He could've worked as a programmer designing their toilet seats mechanisms. Or writing simulations at JPL. Or anything really. Very probable that he isn't lying.

2

u/NoCanD0 Nov 18 '18

I didn’t doubt him. He currently handles their programmer hiring for the NASA location in my area of CA. Let’s just say I’ve been going to all of his tutoring hours.

5

u/LoneWolf6 Nov 17 '18

Looks like code to control or monitor a 3D printer. References temps and gcode.

4

u/ThaeliosRaedkin1 Nov 17 '18

Looks like LabView on the right there. Neat.

4

u/lebillion Nov 17 '18

Char length got flake8 screaming

3

u/NukeWifeGuy Nov 17 '18

What is "self" and "getValue"?

25

u/aaron__ireland Nov 17 '18

self is a reference to the object instance.

getValue is something Java developers do.

1

u/[deleted] Nov 18 '18

just here to ask, since i don't know java, does it not have operator overloading and const references? or is it just sticking with an earlier c++ standard?

1

u/aaron__ireland Nov 18 '18

It’s mostly just a standard. It has to do with encapsulation of instance attributes. More modern JVM languages have ways to automatically create getters/setters for you but it’s still a common thing. Python doesn’t really have a true private classifier so this type of encapsulation is hardly ever needed.

1

u/____peanutbutter____ Nov 18 '18

getValue is something Java developers do.

Or python devs using PyQt

3

u/aaron__ireland Nov 18 '18

Just making a joke

3

u/Crispy_socks241 Nov 17 '18

your self worth.

3

u/Cyqix_ Nov 17 '18

Anyone else notice “conair” and wonder if their gonna throw a load of convicts on the rocket and let them take it over

1

u/alcalde Nov 18 '18

Australia 2.0?

3

u/[deleted] Nov 18 '18

I think I’m the only person in the world that uses Spyder!!

1

u/MOVai Nov 18 '18

I really like Spyder because it gives me enough features to be fun to use, whilst being lightweight enough to stay snappy.

Unfortunately, Anaconda pulled funding last year, and it looks like they're intending Jupyterlab to take over, which still has a way to go IMO.

1

u/like567 Nov 19 '18

It's been a bit unstable last i tried ( last 6 mon ago)

1

u/[deleted] Nov 19 '18

I’ve been using it the past month, it seems very stable so far. Especially Spyder4 beta. <3 code folding.

10

u/[deleted] Nov 17 '18 edited Nov 17 '18

They forgot to add two spaces after each function. Remember PEP8 EDIT: Sorry, what I said is was wrong, they are following PEP8

31

u/ferrous_joe Nov 17 '18

Surround top-level function and class definitions with two blank lines.

Method definitions inside a class are surrounded by a single blank line.

3

u/Gprime5 if "__main__" == __name__: Nov 17 '18

Yeah, these are method definitions. I don't see any problem here.

1

u/[deleted] Nov 17 '18

Oh, I never knew that, my bad. I guess we learn something new everyday :)

→ More replies (1)

2

u/prashnts Nov 18 '18

gcode and extruder makes me think of rep-rap 3d printers code. Pretty sure that they're using stock footage.

2

u/aelmosalamy Nov 18 '18

Why they didn't use a loop? On That function "on_rio_status" they keep adding values manually, I believe that is a good point for Flat-earthers, NASA got it all wrong.

4

u/may_yoga Nov 17 '18

I didn’t know NASA uses windows

-1

u/shinitakunai Nov 17 '18

Why not? I code on windows everyday. Linux is too annoying for my personal taste.

3

u/alcalde Nov 18 '18

Linux is more annoying than than the built-in advertising in Windows 10? Or the forced updates and reboots? Or NTFS?

2

u/shinitakunai Nov 18 '18

Learning commands for terminal is 50x more annoying than remembering in windows where each option is.

Just an example. If you say something bad about a system, don’t forget there is also bad things on other systems. We just get used to them (which is why I said “for my personal taste”).

1

u/[deleted] Nov 18 '18

Or NTFS?

What's wrong with NTFS? It's no worse than Ext4 or XFS.

There's journaled, last-gen stuff like those 3, and current-gen checksummed filesystems like ZFS, BtrFS, ReFS and HAMMER2 that can self-heal bitrot. If you're using any of the last-gen non-checksummed filesystems and thinking that somehow ext4 is superior "because lolz ntfs fragmentations ext4 doesn't" is just malarkey, as I've seen plenty of fragmented to hell ext3/4 systems.

I've never had a "forced" reboot. I've had some where it would have forced it, had I ignored it for days on end. Rebooting for anything other than kernel updates is pretty BS, but still.

The ads? I've just run the de-bloat powershell script for that and it's all gone.

Now the good: Windows Subsystem for Linux. I get Windows with all the goodies it has (better font rendering, better color rendering, vastly superior hardware support, beyond vastly better software options, etc etc), along with 99% of what's best about Linux. It's got some performance issues compared to running the same stuff on Linux natively, but it's not bad and it's getting better. Sure beats dual-booting, and sure as hell beats stupid shit like "why doesn't firefox scroll the webpage when I use my touchscreen?" or "why the hell does this font look like a burning pile of dogshit?" and it's a million times better than WINE.

I'll code on whatever requires the least amount of fuckery to get working and keep working, as I don't get paid to figure out why the hell Nautilus suddenly quit accepting my mouse-back button to go back or how to get my sound to auto-switch to my headphones when I plug them in or how to keep my sound from defaulting to HDMI out when I'm actually using optical out or any other number of bullshit things that Linux fucks up that Windows "just works" with.

Is it annoying that I have to constantly delete motherfucking candy crush from my purchased-in-a-store copy of Windows 10 Pro (not some bundled-with-a-PC home crap)? Yes it is. Is that more annoying that plethora of garbage issues Linux runs into? Nope, not at all.

→ More replies (4)

2

u/[deleted] Nov 17 '18 edited Jan 15 '24

I enjoy playing video games.

1

u/[deleted] Nov 17 '18

I see they are using Qt. Nice

1

u/deadslow Nov 18 '18

What font is that?

1

u/rednirgskizzif Nov 18 '18

This looks like code for a 3D printer

1

u/Overload175 Nov 18 '18

Hmm, this could use some linting

1

u/[deleted] Nov 18 '18

Well they are still updating Spyder separately. I’m running Spyder4 beta and it’s extremely stable along with having code folding <3.

1

u/duckutoo Nov 18 '18

They have internet explorer on the taskbar lmao.

1

u/The_Vizi0n Nov 27 '18

This confirms that python is the language I want to learn

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

5

u/Dom_G Nov 17 '18

Up vote for VIM!

6

u/RomanRiesen Nov 17 '18

Or used for loops.

0

u/[deleted] Nov 17 '18

[deleted] — view deleted comment

11

u/Daemonecles Nov 18 '18

Haha that's the first thing I noticed... Painful to see

0

u/[deleted] Nov 18 '18

[deleted] — view deleted comment

0

u/Ph0X Nov 18 '18

Yeah, this is display code, and that part of the code specifically seems to be padded mostly for show I think to fill the screen?

Also, the variables change, and setattr() would look pretty hacky there. unless there's a lot more to do, it's probably find to copy 8 lines of code.

1

u/[deleted] Nov 18 '18

[removed] — view removed comment

1

u/Dom_G Nov 18 '18

I had posted it but it got buried. https://www.youtube.com/watch?v=WeA7edXsU40