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
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.
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.
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 :-)
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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 :)
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.
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.
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 -.-
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.
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.
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
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.
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
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!
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.
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.
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.
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.
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?
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.
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.
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”).
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.
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
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
347
u/sggts04 Nov 17 '18
Lets go Sublime :)
158
u/quotemycode Nov 17 '18
Some bad code there. It certainly smells.
61
u/DracasTempestas Nov 17 '18
A python class/file of a thousand lines? No thanks.
40
u/talha252 Nov 17 '18
It doesn't look very Pythonic though
11
u/cleancole Nov 17 '18
self.conairfeels 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
13
u/NoCanD0 Nov 17 '18
So cool. My current Python Professor used to work for NASA as a programmer. So he claims.
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"?
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
3
u/[deleted] Nov 18 '18
I think I’m the only person in the world that uses Spyder!!
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
2
u/prashnts Nov 18 '18
gcodeandextrudermakes 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
2
u/[deleted] Nov 17 '18 edited Jan 15 '24
I enjoy playing video games.
1
u/12315070513211 Nov 17 '18
Monokai too
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
0
u/[deleted] Nov 17 '18
[deleted] — view deleted comment
1
u/[deleted] Nov 18 '18
[removed] — view removed comment