82

Hey there!

I'm a chemical physicist who has been using python (as well as matlab and R) for a lot of different tasks over the last ~10 years, mostly for data analysis but also to automate certain tasks. I am almost completely self-taught, and though I have gotten help and tips from professors throughout the completion of my degrees, I have never really been educated in best practices when it comes to coding.

I have some friends who work as developers but have a similar academic background as I do, and through them I have become painfully aware of how bad my code is. When I write code, it simply needs to do the thing, conventions be damned. I do try to read up on the "right" way to do things, but the holes in my knowledge become pretty apparent pretty quickly.

For example, I have never written a class and I wouldn't know why or where to start (something to do with the init method, right?). I mostly just write functions and scripts that perform the tasks that I need, plus some work with jupyter notebooks from time to time. I only recently got started with git and uploading my projects to github, just as a way to try to teach myself the workflow.

So, I would like to learn to be better. Can anyone recommend good resources for learning programming, but perhaps that are aimed at people who already know a language? It'd be nice to find a guide that assumes you already know more than a beginner. Any help would be appreciated.

(page 2) 20 comments
sorted by: hot top controversial new old
[-] Turun@feddit.de 1 points 9 months ago* (last edited 9 months ago)

As a researcher: all the professional software engineers here have no idea about the requirements for code in a research setting.

I recommend you use

  • git. It's nice to be able to revert changes without worry.
  • descriptive variable names. The meaning of descriptive is highly dependent on your situation. Single letters can have an obvious meaning, but err on the side of longer names if you're unsure. The goal is to be able to look at a variable and instantly know what it represents.
  • virtual environments and requirements.txt. when you have your code working you should have pip (or anaconda or whatever) take a snapshot of your current python installation. Then you can install the exact same requirements when you want to revive your code a few months or years down the line. I didn't do that and it's kinda biting me in the ass right now.
[-] QuadriLiteral@programming.dev 1 points 9 months ago

As a researcher: all the professional software engineers here have no idea about the requirements for code in a research setting.

As someone with extensive experience in both: my first requirement would be readability. Single python file? Fine with that. 1k+ lines single python file without functions or other means of structuring the code: please no.

The nice thing about python is that your IDE let's you jump into the code of the libraries you're using, I find that to be a good way to look at how experienced python devs write code.

load more comments (5 replies)
[-] Asudox@lemmy.world 0 points 9 months ago* (last edited 9 months ago)

I'd say go with Go or Rust. Go is like Python (garbage collection) but compiled. Rust is kind of like C++ but not exactly. It does not have garbage collection or manual memory management but something called "ownership and borrowing". It's as fast as C++ or even faster and has a modern syntax. Though Rust is harder than Go since it is under the hood a systems programming language. If you want something faster than Python, Go is good. I specifically chose Rust over Go since I wanted performance and just wanted to try how it was. I'm still a beginner in Rust but I wrote a few projects at reasonable scale for my level. And also, Rust's error messages are extremely nice. It really lives up to the memes.

To learn Rust: https://www.rust-lang.org/learn

To learn Go: https://go.dev/learn/

[-] Turun@feddit.de 1 points 9 months ago

No.

I have written rust for my research (one does not simply calculate 4 million data points in python), but just no.

My main code is still python, because it's just so much nicer to write and iterate on.

[-] Fal@yiffit.net 0 points 9 months ago

Rust syntax is way closer to Python than go. Go's syntax is awful imo. It's like objective C

[-] Asudox@lemmy.world 0 points 9 months ago

Okay, my bad. Go's syntax sucks now that I take another look at it compared to Rust's.

load more comments (1 replies)
[-] abhibeckert@lemmy.world -4 points 9 months ago* (last edited 9 months ago)

Can anyone recommend good resources for learning programming

Honestly? No. The best resource is you. Ask questions. Get experience. Ask questions. Get experience. Repeat.

It's not enough to learn. You also have to do. And you really should learn by doing in this field.


First of all - fuck Python. I'm sure it's possible to write good code in that language, but it's not easy and it requires a lot of discipline. I don't mean to be mean to Python, it's a truly wonderful language, arguably one of the best languages, when used properly. But it sounds like you're not using it properly.

Pick a language that:

  1. Has static typing
  2. Does not do garbage collection

Static typing forces you to have more structure in your code. You can have that structure in a dynamic language but nobody ever does in practice and part of the reason is all of the libraries and third party code you interact assume you have dynamic typing as a crutch to quickly and easily solve hard to solve problems.

It's far better to actually solve those problems, rather than avoid them. You'll tend to create code where bugs are caught when you write the code instead of when someone else executes the code. That "you vs someone else" distinction is a MASSIVE time saver in practice. It took me about 20 years, but I have learned dynamic typing sucks. It's convenient, but it sucks.

For more info: https://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7

On garbage collection - it's a similar issue. It's really convenient to write code where "someone else" deals with all that memory management "garbage" for you but the reality is you should be thinking about memory when you write your code because, at it's heart, 99.999% of the code you write is in fact just moving memory around. Garbage collection is like "driving" a Tesla with autopilot active. You're not really driving at all. And you can do a better job if you grab that wheel and do it yourself.

I recommend starting with a manually memory managed language (like RUST) to learn how it works, and then from there you might try a language that does most of the work for you without completely taking it out of your hands (for example Swift, which has "automatic" memory management for common situations but it's not a garbage collector and in some edge cases you need to step in and take over... a bit like cruise control in a car if we're going to use that analogy.

It's getting harder these days to find a language that doesn't have garbage collection. The industry has gone decades thinking GC is a good idea and we just need one more fix, which we're working on, to fix that edge case where it fucks up... and then we find another edge case, and another, and another... it's a bit of a mess and entire papers have been written on the subject. But anyway some of the best and newest languages (Rust, Swift, etc) don't have Garbage Collection, which is nice (because writing code in C or Fortran sucks — I'm not recommending that).


That's enough for now. Just keep muddling about learning those languages first before trying to tackle bigger problems. Programming is a difficult task, just like a baby learns to sit up, then roll over, then crawl, then stand, then walk with assistance, then stumble around, then walk, then run, then ride a bicycle with three wheels, then a two wheel one with no pedals, then a bicycle with pedals, then a car after that...

You skipped all those steps and went straight to driving a car (with autopilot). To learn properly, you don't need to go all the way back to "sitting up and crawling", but you should maybe go back just a little bit. Figure out how to get code to run, at all, in a language like rust, get familiar with it.


After you've done that come back here and ask what's next. We can talk about SOLID, Test Driven Development, all the intricacies of project management in git, exceptions vs returning an error vs failing silently, and when to use third party code vs writing your own (phew boy that's a big one...).

But for now - just learn a lower level language. Programming is a bit like physics. You've got elements, and under that atoms, and under that... well I don't even know what's under that (you're the scientist not me). There are "layers" to programming and it's important to work at the right layer and it's also important to understand the layer below and above the one you're working at.

If Python is at layer x, then you really need to learn layer x-1 in order to be good at Python. You don't need to go all the way down - you can't go all the way down (how do magnets work?).

load more comments
view more: ‹ prev next ›
this post was submitted on 14 Mar 2024
82 points (97.7% liked)

Programming

17668 readers
174 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS