r/AskEngineers • • Mar 16 '19

Mechanical Is it worth learning Python as a Mechanical Engineer?

Greetings, I am a freshman in Mechanical engineering and I've already finished my MATLAB course, and I find coding fun, so I was wondering if I should learn python? But of course I won't waste my time learning it if it isn't beneficial to me. So my fellow MEs, how useful would it be learning python? And what are these benefits. Thank you!

296 Upvotes

165 comments sorted by

View all comments

Show parent comment

67

u/[deleted] Mar 16 '19

Please tell me more on how matlab teaches bad habits

0

u/[deleted] Mar 16 '19

[deleted] — view deleted comment

30

u/[deleted] Mar 16 '19

We were actually taught to write reusable code in Matlab... Or at least our professor told us to, i never really got it to work...

8

u/Awsome306 Mar 16 '19

Does Python have an equivalent of the "help" or "doc" command in MATLAB? I'm currently trying to learn Python, but learning the syntax has been way slower than it was for MATLAB.

20

u/Gh0stw0lf Mar 16 '19

No, and no real programming language will ever have that.

You can’t rely on all your help to be neatly in one screen. Python has arguably more robust tutorial system but they exist in internet searches.

Strange that you’re having issues with syntax, it’s one of the most simplified languages

9

u/What_Is_X Mar 16 '19

Documentation should be close to code. R does this well.

→ More replies (10)
→ More replies (5)

9

u/F5x9 Mar 16 '19

Just write functions for generalized inputs.

4

u/[deleted] Mar 16 '19

Of course. It's just that i never actually used anything i wrote more than once, so why bother?

24

u/old_sellsword Mar 16 '19

Also 1-indexing????

It’s called Matrix Laboratory. When’s the last time you saw a matrix with a 0th index?

22

u/PM_ME_UR_SWEATERPUPS Mar 16 '19

Say hello to my old friends C and C++...

19

u/old_sellsword Mar 16 '19

Those are arrays. A matrix in those languages is just an array of arrays.

MATLAB is essentially a big calculator, it makes total sense for it to have 1-indexing. I’ll never argue that MATLAB is a good language for actual programming, but it’s great for quick and dirty data analysis and modeling.

9

u/PM_ME_UR_SWEATERPUPS Mar 16 '19

A matrix really is an array, with a new set of operations to manage it.

Matlab is a very high level language and that is one of the reasons the OP suggested it teaches bad habits. Engineers, of the non-software variety, are terrible programmers. Because if it works, it is good enough.

14

u/SoraDevin Mar 16 '19

As an electrical engineer I feel personally attacked

→ More replies (1)
→ More replies (2)

4

u/ArrivesLate Mar 16 '19

For real. Also I seem to remember my machine code classes start at 0.

14

u/gurenkagurenda Mar 16 '19

Nothing really wrong with 1-indexing. Both conventions have pros and cons. The rest of that sounds just awful though.

→ More replies (3)

3

u/[deleted] Mar 17 '19

I have worked with Matlab quite a bit and currently working with Java.

I think most people won't understand what you really mean since I don't think you took the proper time to explain.

I'll add my thoughts:

Matlab users will try to use functions and whatnot but you are correct - even the best Matlab users don't have the same habits as a real 'programmer' when it comes to not 'copy-paste'

That being said, if you're using MatLab, you're quite literally scripting rather than building 'software' so yes, I agree with you but most MatLab users won't understand unless they come across a real 'programmer' that refuses to copy-paste a single line of code.

→ More replies (2)

27

u/gjsmo Mar 16 '19
  • No namespaces.
  • No indexing inside return values.
  • No pass by reference
  • Expensive, $3000 for a single seat or $12000/yr for a network license.
  • Each toolbox (basically a library) is often an additional $800 or so.
  • Parallel processing is a separate toolbox.
  • Performance on non-numerical code is abysmal
  • Syntax is frequently inconsistent, if it makes sense at all
  • (minor) GUIs are awful. Can't make a spinner box, can't set limits on text boxes, can't (easily) format text apart from font/size. AND it's just worse Java, or a web app if you use the newer App Designer instead of GUIDE.

30

u/rlbond86 Electrical - Signal Processing Mar 16 '19 edited Mar 16 '19

Let's not forget: every function has to go in its own file, and that file has to be in your path.

Edit: what's with the downvotes? It's true.

3

u/MalakElohim Mar 16 '19

Wait until you see overloaded functions in MATLAB. In different file paths.

→ More replies (10)
→ More replies (3)

18

u/Warfared Mar 16 '19

Ambiguous syntax (indexing at 1, names for functions are dodgy etc.), rough use of semi-colons, no handling of errors and lots more.

It's good for solving mathematical equations and such but that's about it from a software perspective.

→ More replies (13)

7

u/meerkatmreow Aero/Mech Hypersonics/Composites/Wind Turbines Mar 16 '19

Matlab itself didn't necessarily cause the bad habits (though it doesn't help since it mixes a lot of features and concepts from different languages to be all things to all people). Mainly it's the way it's taught to engineers. You learn a few basic concepts and then start hacking shit together until it works. That works ok for homework assignments but not for large codes that you need to maintain. The amount of global variable using spaghetti code I've seen is horrifying. Python is the language of choice for computer programmers so much of the infrastructure around it teaches things like code modularity, testing, documentation and version control