this post was submitted on 14 Mar 2024
82 points (97.7% liked)

Programming

17503 readers
23 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 [email protected]



founded 1 year ago
MODERATORS
 

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.

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 8 months ago* (last edited 8 months ago) (1 children)

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.
[–] [email protected] 1 points 8 months ago (1 children)

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.

[–] [email protected] 2 points 8 months ago (1 children)

You can jump to definition in any language. In fact, python may be one of the worst ones, because compiled libraries are so common. "Real signature unknown" is all you will get some times. E.g. Numpy is implemented in C not python.

[–] [email protected] 1 points 8 months ago (1 children)

My point about the jumping into was that you can immediately start reading the sources. Most alternative languages are compiled in some form or other so all you'll see is an API, not the implementation.

[–] [email protected] 1 points 8 months ago* (last edited 8 months ago) (1 children)

My comment was not asking for clarification, I am contradicting your claim.

Granted, my experience is mostly limited to python and rust. But I find that in python you reach the end of "jump to definition" much much sooner. Fundamental core libraries of Python are written in C, simply because the performance required cannot be reached with python alone. So after jumping two levels you are through the thin wrapper type and your compiler will give you an "I don't know, it's byte code".
In Rust I have yet to encounter this. Byte code is rarely used as a dependency, because compiling whatever is needed is no issue - you're compiling anyway - and actually can allow a few more optimizations to be performed.

Edit: since wasm is not yet wide spread, JavaScript may be the best language to dig deep into libraries.

[–] [email protected] 1 points 7 months ago (1 children)

Mostly ML or data processing libraries I would assume, I've read tons of REST server and ORM python code for instance, none of that is written in C.

Wrt rust: no experience with that. I do do a lot of C++, there you quickly reach the end as typically you're consuming quite a bit of libraries but the complete sources of those aren't part of what is parsed by the IDE as keeping all that in memory would be unworkable.

[–] [email protected] 1 points 7 months ago

REST server and ORM python code

Fair enough, that can be achieved with pure python.

[–] [email protected] 3 points 8 months ago (1 children)

It's always good to learn new stuff but in terms of productivity: Don't attempt to be a programmer. Rather attempt to write better research code (clean up code, revision control, better commenting, maybe testing...)

Rather try to improve cooperation with programmers, if necessary. Close cooperation, asking stupid questions instead of making assumptions etc. makes the process easy for both of you.

Also don't be afraid to consult different programmers since beyond a certain level, experience and expertise in programming is vastly fragmented.

Experienced programmers mostly suck on your field and vice versa and that's a good thing.

[–] [email protected] 1 points 8 months ago (1 children)

Odd take imo. OP is a programmer, albeit perhaps not a very good one. Did a PhD (computational astrophysics), been working as a professional dev for 10 years after that. Imo a good programmer writes code that solves the problem at hand, I don't see that much of a difference between the problem being scientific or a backend service. It doesn't mean "write lots of boilerplate-y factories, interfaces and other layers" to me, neither in research nor outside of it.

That being said, there is so much time lost in research institutes because of shoddy programming by researchers, or simply ignorance, not knowing a debugger exists for instance. OP wanting to level up their game would almost certainly result in getting to research results faster, + they may be able to help their peers become better as well.

[–] [email protected] 1 points 8 months ago (1 children)

25 years in the industry here. As I said there's nothing against learning something new but I doubt it's as easy as "leveling up".

Both fields profit a lot from experience and it's as much gain for a scientist do become a software dev as an architect becoming a carpenter. It's simply not productive.

there is so much time lost in research institutes because of shoddy programming

Well, that's the way it is. Scientific code and production code have different requirements. To me that sounds like "that machine prototype is inefficient - just skip the prototype next time and build the real thing right away."

[–] [email protected] 1 points 7 months ago

To me that sounds like “that machine prototype is inefficient - just skip the prototype next time and build the real thing right away.”

I don't think you understand my point, which is that developing the prototype takes e.g. 50% more time than it should because of complete lack of understanding of software development.

[–] [email protected] 4 points 8 months ago

My advice comes from being a developer, and tech lead, who has brought a lot of code from scientists to production.

The best path for a company is often: do not use the code the scientist wrote and instead have a different team rewrite the system for production. I've seen plenty of projects fail, hard, because some scientist thought their research code is production level. There is a large gap between research code and production. Anybody who claims otherwise is naive.

This is entirely fine! Even better than attempting to build production quality code from the start. Really! Research is solving a decision problem. That answer is important; less so the code.

However, science is science. Being able to reproduce the results the research produced is essential. So there is the standard requirement of documenting the procedure used (which includes the code!) sufficiently to be reproduced. The best part is the reproduction not only confirms the science but produces a production system at the same time! Awws yea. Science!

I've seen several projects fail when scientists attempt to be production developers without proper training and skills. This is bad for the team, product, and company.

(Tho typically those "scientists" fail to at building reproducible systems. So are they actually scientists? I've encountered plenty of phds in name only. )

So, what are your goals? To build production systems? Then those skills will have to be learned. That likely includes OO. Version control. Structural and behavioral patterns.

Not necessary to learn if that isn't your goal! Just keep in mind that if a resilient production system is the goal, well, research code is like the first pancake in a batch. Verify, taste, but don't serve it to customers.

[–] [email protected] 5 points 8 months ago

There's a certain amount of fundamentals you need, after that point it's quite easy to hop languages by just looking over the documentation of that language. If you skip those fundamentals, you end up with a bunch of knowledge but don't realize you could do things way more effectively.

My recommendation: check out free resources for beginners and skip the atuff you already know thoroughly, focusing only on the stuff you don't know.

source: I'm self-taught and had to go through this process myself.

[–] [email protected] 19 points 8 months ago* (last edited 8 months ago)

Most of the "conventions" (which are normally just "good practices") are there to make the software easier to maintain, to make teamwork more efficient, to manage complexity in large code-bases, to reduce the chance of mistakes and to give a little boost in productivity.

For example, using descriptive names for variables (i.e. "sampleDataPoints" rather than "x") reduces the chances of mistakes due to confusing variables (especially in long stretches of code) and allows others (and yourself if you don't look at that code for many months) to pick up much faster what's going on there in order to change it. Dividing your code into functions, on the other hand, promotes reusability of the same code in many places without the downsides of copy & paste of the same code all over the place, such as growing the code base (which makes it costlier to maintain) and, worse, unwittingly copying and pasting bugs so now you have to fix the same stuff in several places (and might even forget one or two) rather than just fixing it in that one function.

Stuff at a higher, software design level, such as classes, are mean to help structure the code into self-contained blocks with clear well controlled ways of interaction between them, thus reducing overall complexity (everything potentially connecting to everything else is the most complex web of connection you could have) increasing productivity (less stuff to consider at any one point whilst doing some code, as it can't access everything), reduce bugs (less possibility of mistakes when certain things can only be changed by only a certain part of the code) and make it easier for others to use your stuff (they don't need to know how your classes works, only to to talk to them, like a mini library). That said, it's perfectly feasible to achieve a similar result as classes without using classes and using scope only, though more advance features of classes such as inheritance won't be possible to easilly emulate like that.

That said, if your programs are small, pretty much one use (i.e. you don't have to keep on using them for years) and you're not having to work on the code as a team, you can get away with not using most "conventions" (certainly the design level stuff) with only the downside of some loss in productivity (you lose code clarity and simplification, which increases the likelihood of bugs and makes it slower to transverse and spot stuff in the code when you have to go back and forth to change things).

I've worked with people who weren't programmers but did code (namelly with Quants in Finance) and they're simply not very good at doing what is but a secondary job for them (Quants mainly do Mathematical modelling) which is absolutelly normal because unlike with actual Developers, doing code well and efficiently is not what their focus has been in for years.

[–] [email protected] 2 points 8 months ago

Use an IDE if you aren't already. Jetbrains stuff is great. Having autocomplete is invaluable.

[–] [email protected] 0 points 8 months ago* (last edited 8 months ago) (3 children)

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/

[–] [email protected] 1 points 8 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.

[–] [email protected] 3 points 8 months ago

Why not just stick with Python until there's a need to learn something else?

[–] [email protected] 0 points 8 months ago (1 children)

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

[–] [email protected] 0 points 8 months ago

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

[–] [email protected] -4 points 8 months ago* (last edited 8 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?).

[–] [email protected] 2 points 8 months ago* (last edited 8 months ago)

Computer scientist here. First, let me dare ask scientists here a question from a friendly fellow: do you have reference to your suggestions?

Code Complete 2 is a book on software engineering with plenty of proper references. Software engineering is important because you learn how to work efficiently. I have been involved in plenty of bad science code projects that wasted tax payers money because of the naivety by the programmers and team management.

The book explains how and why software construction can become expensive and what do about it, covering a vast range of topics agreed by industrial and academic experts.

One caveat, however, is that theories are theories. Even best practices are theories. Often, a young programmer tries to force some practice without checking the reality. You know you can reuse your function to reduce chance of bugs and save time. But have you tested if that is really the case? Nobody can tell unless you test, or ask your member if that's a good idea. I've spent a good chunk of time on refactoring that didn't matter. Yet, some mattered.

That importance of reality check is emphasized in the book Software Architecture: The Hard Parts, for example.

Now, classes, or OOP, have been led by the industry to solve their problems. Often, like in case of Java, it was a partly a solution for a large team. For them it was important to collaborate while reducing the chance of shooting someone accidentally. So, for a scientific project OPP is sometimes irrelevant, and sometimes relevant. Code size is one factor to determine the effectiveness of OOP, but other factors also exist.

Python uses OOP for providing flexibility (here I actually mean polymorphism to be precise), and sometimes it becomes necessary to use this pattern as some packages rely on it.

One problem with Python's OPP is that it inherits implementation. Recent languages seem to avoid this particular type of OOP because the major rival in OOP, what is called composition, has been time-proven to be easier to predict the program's behavior.

To me, writing Python is also often easier with OOP. One popular alternative to OOP is what is called a functional approach, but that is unfortunately not well-supported in Python.

Finally, Automate the Boring Stuff With Python is a great resource on doing routine tasks quickly. Also, pick some Pandas book and get used to its APIs because it improves productivity to a great extent. (I could even cite an article on this! But I don't have the reference at hand.)

Oh, don't forget ChatGPT and Gemini.

[–] [email protected] 7 points 8 months ago (1 children)

The thing to think about is reusability. Are you copying and pasting code into multiple places? That's a great candidate to become a class. If you have long lived projects (i.e. something you will use multiple times over a lot of years) maintainability is important. Huge functions and monolithic applications are very hard to maintain over time.

Break your functionality out into small chunks (methods and classes). Keep it simple. It may take a while to get used to this, but your time for adding additional functionality will be greatly improved in the long run.

A lot of great programmers were terrible at one time. Don't let your current lack of knowledge of principles stop you from learning. One of the biggest breakthroughs I had as a programmer is changing how I looked at architecting applications. Following SOLID principles will assist a lot in that. Don't try to understand and use these principles all at once, take your time. Programming isn't what you make your living with, it's a tool to help you be more efficient in your current role.

Realize that becoming a more effective programmer is different for everyone. Like you, I was self taught. I was a systems and network engineer that decided to move into software development. I've since moved into a role that takes advantage of all the skills I've learned through the years in SRE. like you, a lot of what I write now is about automation and analysis.

[–] [email protected] 0 points 8 months ago (1 children)

Careful with this. Not everything needs to be reusable, and copy/paste isn't inherently bad.

https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction

[–] [email protected] 1 points 8 months ago (1 children)

You aren't wrong... But everything with extended use needs to be maintainable. Making a change in 5 places sucks.

Plus, that's what open-closed principle is all about. Instead of adding additional functionality to current working code, you extend and modify.

[–] [email protected] -2 points 8 months ago

Making a change in 5 places sucks, making it in 2 could be reasonable. If 2 pieces of code are similar but different enough, I've seen way too often people try to force them into a common abstraction. That's more what the article is about.

[–] [email protected] 3 points 8 months ago

How to think like a computer scientist may help.

https://www.openbookproject.net/thinkcs/python/english3e/

[–] [email protected] 5 points 8 months ago

If you don't already, use version control (git or otherwise) and try to write useful messages for yourself. 99% of the time, you won't need them, but you'll be thankful that 1% of the time. I've seen database engineers hack something together without version control and, honestly, they'd have looked far more professional if we could see recent changes when something goes wrong. It's also great to be able to revert back to a known good state.

Also, consider writing unit tests to prove your code does what you think it does. This is sometimes more useful for code you'll use over and over, but you might find it helpful in complicated sections where your understanding isn't great. Does the function output what it should or not? Start from some trivial cases and go from there.

Lastly, what's the nature of the code? As a developer, I have to live with my decisions for years (unless I switch jobs.) I need it to be maintainable and reusable. I also need to demonstrate this consideration to colleagues. That makes classes and modules extremely useful. If you're frequently writing throwaway code for one-off analyses, those concepts might not be useful for you at all. I'd then focus more on correctness (tests) and efficiency. You might find your analyses can be performed far quicker if you have good knowledge about data structures and algorithms and apply them well. I've personally reworked code written by coworkers to be 10x more efficient with clever usage of data structures. It might be a better use of your time than learning abstractions we use for large, long-term applications.

[–] [email protected] 5 points 8 months ago (1 children)

All the other comments are great advice. As an ex chemist who does quite a bit of code I'll add:

Do you want code that works, or code that works?! It's reasonably easy to knock out ugly code that only works once, and that can be just what you need. It takes a little more effort however to make it robust. Think about how it can fail and trap the failures. If you're sharing code with others, this is even more important a people do 'interesting' things.

There's a lot of temporary code that's had a very long life in production, this has technical debt... Is it documented? Is it stable? Is it secure? Ideally it should be

Code examples on the first page of Google tend to work ok, but are not generally secure, e.g doing SQL queries instead of using prepared statements. Doesn't take much extra effort to do it properly and gives you peace of mind. We create sboms for our code now so we can easily check if a component has gained a vulnerability. Doesn't mean our code is good, but it helps. You don't really want to be the person who's code helped let an attacker in.

Any code you write, especially stuff you share will give you a support and maintenance task long term. Pirate for it!

Code sometimes just stops working. - at least I'm my experience. Sacrifice something to the gods and all will be fine.

Finally, you probably know more than you think. You've plenty of experience. Most of the time I can do what I need without e.g. classes, but sometimes I'll intentionally use a technique in a project just to learn it. I can't learn stuff if I don't have a use for it.

I'm still learning, so if I've got any part of the above wrong, please help me out.

[–] [email protected] 1 points 8 months ago (1 children)

"Pirate for it" was probably the wrong phrase. "Plan for it" was probably what you were thinking when your fingers did something else.

[–] [email protected] 3 points 8 months ago

Thought I did so well on my phone. It kept auto correcting code to coffee. Maybe it was telling me something.

Yes, plan for it!

[–] [email protected] 16 points 8 months ago (2 children)

The O'Reilly "In a Nutshell" and "Pocket Guide to" books are great for folks who can already code, and want to pick up a related tool or a new language.

The Pocket Guide to Git is an obvious choice in your situation, if you don't already have it.

As others have mentioned, you're allowed to ignore the team stuff. In git this means you have my permission to commit directly to the 'main' branch, particularly while you're learning.

Lessons that I've learned the hard way, that apply for someone scripting alone:

  • git will save your ass. Get in the habit of using if for everything ASAP, and it'll be there when you need it
  • find that one friend who waxes poetic about git, and keep them close. Usually listening politely to them wax poetically about git will do the trick. Five minutes of their time can be a real life saver later. As that friend, I know when you're using me for my git-fu, and I don't mind. It's hard for me to make friends, perhaps because I constantly wax poetically about git.
  • every code swan starts as an ugly duck that got the job done.
  • print(f"debug: {what_the_fuck_is_this}") is a valid pattern that seasoned professionals still turn to. If you're in a code environment that doesn't support it, then it's a bad code environment.
  • one peer who reads your code regularly will make you a minimum of 5x more effective. It's awkward as hell to get started, but incredibly worth it. Obviously, you traditionally should return the favor, even though you won't feel qualified. They don't really feel qualified either, so it works out. (Soure: I advise real scientists about their code all the time. It's still wild to me that they, as actual scientists, listen to me - even after I see how much benefit I provide.)
[–] [email protected] 3 points 8 months ago (1 children)

Along a similar vain to making a git friend, buy your sysadmins/ops people a box of doughnuts once in a while. They (generally) all code and will have some knowledge of what you are working on.

[–] [email protected] 1 points 8 months ago

That is great advice that has served me well, as well!

[–] [email protected] 3 points 8 months ago (1 children)

print(f"debug: {what_the_fuck_is_this}") is a valid pattern that seasoned professionals still turn to. If you’re in a code environment that doesn’t support it, then it’s a bad code environment.

I've been known to print things to the console during development, but it's like eating junk food. It's better to get in the habit of using a logging framework. Insufficient logging has been in the OWASP Top 10 for a while so you should be logging anyway. Why not logger.debug("{what_the_fuck_is_this}") or get fancy with some different frameworks and logger.log(SUPER_LOW_LVL, "{really_what_the_fuck_is_this}")

You also get the bonus of not going back and cleaning up all the print statements afterward. All you have to do is set the running log level to INFO or something to turn all that off. There was a reason you needed to see that stuff in the first place. If you ever need to see all that stuff again the change the log level to whatever grain you need it.

[–] [email protected] 3 points 8 months ago* (last edited 8 months ago)

Absolutely true.

And you make a great point that: print(f"debug: {what_the_fuck_is_this}") should absolutely be maturing into logger.log(SUPER_LOW_LVL, "{really_what_the_fuck_is_this}")

Unfortunately I have found that when print("debug") isn't working, usually logging isn't setup correctly either.

In a solidly built system, a garbage print line will hit the logs and raise several alerts because it's poorly formatted - making it easy for the developer to find.

Sadly, I often see the logging setup so that poorly formatted logs go nowhere, rather than raising alerts until they're fixed. This inevitably leads to both debug logs being lost and critical but slightly misformatted logs being lost.

Your point is particularly valuable when it's time to get the system fixed, because it's easier to say "logging needs to work" than "fix my stupid printf", even though they're roughly equivalent.

Edit: And getting back to the scripting scientist context, scripting scientists still have my formal official permission to just say "just make my print('debug') work".

[–] [email protected] 3 points 8 months ago

I've got two tips to add to the pile you've already read.

I recommend you read the manuals related to what you are using. Have you read the python manual? And the ones for the libraries you use? If you do you'll definitely find something very useful that you didn't know about.

That and, reread your code. Over and over until it makes total sense, and only run it then. It might seem slow, and it'll require patience at first. Running and testing it will always be slower and is generally only useful when testing out the concept you had in mind. But as long as you're doing your conceptual work right, this shouldn't happen often. And so, most work will be spent trying to track down bugs in the implementation of the concept in the code. Trust me when you read your code rigorously you'll immediately find issues. In some cases use temporary prints. Oh and avoid the debugger.

load more comments
view more: next ›