Inefficient Code

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?

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 .

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 Over time youâ€™ll learn to write better code, donâ€™t worry. Experience is a major factor here.

3 Likes
4 Likes

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.

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

My previous answer to this question:

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.

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â€ť