2

I have been coding in python for a little over a year, and I have learned a lot and developed quite a few applications, in the process.

I do not program for my profession, I simply program recreationally. With that said, I am not exposed to new programming techniques/data structures etc., that I would be learning if my day job was in the field, for example.

I have become quite good at figuring out what I want to do by trial and error in python, and I am usually pretty successful at figuring it out!

However, sometimes when I learn something new, I will find that I was doing it the long way or with way too much code that could be much more easily accomplished with fewer lines or a technique that makes an algorithm more efficient.

When you are developing software, do you strive to find the most efficient way to do something first, or do you simply code the way you are familiar?

I don't have many programmer friends, so I have been doing this all pretty much on my own.

I watch a few twitch streams, but beside that I do not really know anyone in person.

Hopefully that adds some context why I am asking.

Doc Brown
  • 199,015
  • 33
  • 367
  • 565
NewCoder18
  • 139
  • 4
  • "Does it bother you" is not a useful question. It's tantamount to asking "Are you a lazy person who doesn't care about their work?" – Robert Harvey Jul 28 '21 at 22:57
  • Changed the wording, thank you. – NewCoder18 Jul 28 '21 at 23:00
  • 5
    There are many goals in software development, some of which compete with each other. You have to decide which goals are the most important to you, and favor those. For example, do you prefer high performance, or code that is the most readable and clear? You can't always have both. Software developers are always under time pressure to produce, and sometimes perfection is sacrificed so that a product can ship. – Robert Harvey Jul 28 '21 at 23:05
  • 2
    So none of us can categorically say that we always strive to produce the most efficient code, because efficiency is not always the most important goal we're trying to achieve. – Robert Harvey Jul 28 '21 at 23:07
  • That is a great answer, I had not thought of it from a goal-oriented perspective. I have been working to achieve my goals with the software I am creating, but I am unsure at times the way real programmers look at problems or techniques they use. I know I could learn a thing or two from all of you and your experience. Thank you for your view! – NewCoder18 Jul 28 '21 at 23:08
  • 1
    I changed the title to make it match the question body. But if the question gets reopened, I would vote to close it as a dupe of this older one: [Clean readable code vs fast hard to read code. When to cross the line?](https://softwareengineering.stackexchange.com/questions/89620/clean-readable-code-vs-fast-hard-to-read-code-when-to-cross-the-line) – Doc Brown Jul 29 '21 at 07:47
  • If you have written some code, making it easier, more straightforward, less complicated will often tend to make it faster. Unnecessarily complex is often unnecessarily slow. The next step is to extract the unreadable bits into one function with a clean , well defined interface. Keeping 99,9% of your code readable, and 0.1% as fast as possible. – gnasher729 Jul 29 '21 at 10:05
  • In practice code is often slow because you did something stupid, and not doing the stupid thing is enough to make it fast. – gnasher729 Jul 29 '21 at 10:06
  • Whenever I've built anything - you get it working first, even if its slow - then you refactor as you learn more. Write, Refactor, Release is the never ending development cycle. – alilland Jul 29 '21 at 19:55
  • 1
    The problem with the question as written, is it's too loosely defined. By what standard is 'efficiency' measured? By which paradigm is the OP programming that is 'familiar'? @DocBrown I see the questions as fundamentally different. The other question asks when to break "the rules". In this case, the OP seeks guidance about whether it's better to just throw any old code together to make something work, or whether to fine tune it from the start. If the question is written in this context, it would be easy to cite several Agile sources as to why it's OK to do anything first, then improve. – S.Robins Jul 30 '21 at 09:57
  • 1
    @NewCoder18, It's not really a good question in the sense that it doesn't really clarify what you are asking for, which is to understand how to write better code up front. I'll answer the question though: you are trying to run before you can crawl. Even after 30+ years of software development, I still look at old code and realise I could have done something better. If you want to master programming, you practice it constantly, and learn from others, as well as from your own mistakes. You rarely get it right first go, so you test, refactor, and improve incrementally. – S.Robins Jul 30 '21 at 10:10
  • 1
    @S.Robins: in case of reopening, we can also vote for closing with "needs more focus" or "educational advice", if you prefer this. – Doc Brown Jul 30 '21 at 10:14

1 Answers1

10

First I code something that seems like it works correctly to me.

Next I code something that seems like it works correctly to others.

I never think about performance until I’m on the second step because if I start doing that in the first step I never make it to the second step.

candied_orange
  • 102,279
  • 24
  • 197
  • 315
  • I appreciate this, very much! – NewCoder18 Jul 29 '21 at 04:00
  • 2
    You never think about performance at all before the second step? I would guess you select acceptably performant data-structures and algorithms even at the start, or it might never get off the ground anyway. – Deduplicator Jul 29 '21 at 11:13