Inefficient Code

Inefficient Code
0.0 0

#1

I just finished Sum All Primes and Smallest Common Multiple and I am realizing that my code is probably the slowest possible.

Would you all recommend pushing through and possibly returning later or should I look to other resources to learn about more efficient code and mathing?


#2

Many very smart people have thought a long time about efficient ways of finding primes or calculating the scm so I’d say it’s totally normal that your solution isn’t as elegant as theirs. Of course, one has to differentiate between inefficient code and an inefficient algorithm. The former is comparatively easy to improve, the latter no so much. Of course, the problems you mentioned have been studied for millennia, so you can look up efficient algorithms on Wikipedia :slight_smile: .

Should you push trough? Depends if you think you understand what you were taught. Or maybe you are curious to learn more about the mathematical problems presented in the challenges. If you aren’t, I’d assume the focus is more on basic programming than it is on the sieve of Eratosthenes :wink: Over time you’ll learn to write better code, don’t worry. Experience is a major factor here.


#3

#4

Thanks all for the responses.

It reminds me of another thread else where about using Vanilla Javascript as opposed jQuery. Someone brought up, what is the point of worrying about 241kb of extra code, when you have a site filled with large uncompressed images and video.


#5

keep moving forward. You can always come back and refine later with the things you learn while doing additional projects and algorithms.


#6

My previous answer to this question:


#7

I agree with other posters before me, just keep going. Optimizing a program that finds prime numbers isn’t going to help you make a cool app or get a good job. Computers can handle thousands of iterations like nothing and are getting faster all the time, and I don’t feel bad about making them do some heavy lifting. As long as you don’t cause noticeable lagging I wouldn’t worry about.


#9

In fact, I remember my boss using the term “Intellectual Masturbation”.

Well, I attacked the UK job market and you must know how to code something fast. Know all the well-known pattern, all the algorithms, …
Whatever …

I still think that the user experience is important. And people forget that a lot. And even my code is not fast, I’m very good refactorer coder. That means a good coder should be able to debug, to destroy his code and remake a logic to apply to the current logic like a surgeon. You can see a good developer in an emergency or develop a critical environment.

There is no such thing as an ultimate program. You will always code, debug, modify the code anyway. And I use the SOLID principle where a function does one thing at a times and very well.

I learnt years ago this expression: “Make it works, make it right, make it fast

You can also read this: “Premature Optmisation

You can read this too: “Blub Paradox” or this “Mental Masturbation


#10

I grew up with Paul Graham. Wicked smart.