If the user is a beginner I usually point at the low hanging fruits, fixes the glaring mistakes and reffer them to some links regarding best practices.
@DanPantry In the end, if there's things that can be improved and you know about it, it should probably be added to your review. I'm actually in the process of expanding my (already kind of long) answer here: codereview.stackexchange.com/a/134241/88422
It's very hard to actually review this because it's one of those typical javascript apps where the view logic and business logic are not separate at all
I@DanPantry I don't think you have to reimplement the code, you've already given a good review, but if you do find the time and actually do it, you can just put it at the end with a "this is what it looks like after changes" comment.
As in, your review already shows what could be better without explicitly having to show the changes.
So it's up to the guy who asked the question to apply it.
Also with the preface that the code on it's own won't likely work on it's own without modifications as I haevn't tested it, but it's a pointer towards how it might look with the points I've given taken into account.
@N3buchadnezzar I wasn't clear, I meant that you don't need to post the code with changes since you already gave suggestions, that is to say that the question's creator should be the one to actually implement it.
I can't guarantee they've read my review; they might as well have copied pasted.
If they've done that though they were never interested in the review in the first place, and would likely have: "oh, no complete code samples? give checkmark out to random person, close tab"
I find the paragraph about tailoring the answer to the apparent level of the code writer somewhat confusing. Specifically when before the question answer is ready. — pacmaninbw44 mins ago
@DanPantry Don't think I could have said it better myself (although I could have provided a link with more information). There's no way you can keep that much data in memory at once.
@SimonForsberg >_> i have a bad feeling it's gonna be "stop writing bad code and come to CR"
Side note, I've written a utility method to prime-factorize a number in C#, it's not a lot of code, but it's kind of slow and I feel I could be doing things better, is posting just one method too short for a code review? About 25 LoC counting the braces
I have written this PrimeFactorize utility method in C# (using LINQPad) which appears to work great, but feels like it is a bit slow, I was wondering what might be improved. Also looking for any criticism not related to efficiency to make the code better.
// Generate prime factors for a number, ...
I did initially think that, but OP is only using calculations - there's nothing about UI work in there at all.
The only winforms related thing is the method name - you could copy paste that code and put it in a normal main method and you'd see nothing different.
I'm trying to use JOGL and Java to draw a hexagonal based game. I currently have it so that it displays correctly, however it seems to run poorly and needs optimization.
Currently I create a glList that has objects for the cells, the cell walls and the player. When I draw one these objects, I ...
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
I wrote the following code with help of some Java 8, I'll explain the equivalent to Java 7 under the code. I'd like general comments. One note to give up ahead is that I did not...
@Mat'sMug No I don't have the Apple anymore, bought a Windows 10 laptop a few months ago, remember? ;P
I think firing up Visual Studio to do Project Euler problems is probably overkill though. I was going to use those just for benchmarking, but I think I found a workaround
This question is probably better-suited for the Code Review stack exchange site, since that allows detailed discussions of improvements to working code. — TheBlackCat47 secs ago
def prime_factors(num):
if isprime(num):
yield num
limit = int(num**0.5) + 1
# Import some magic list of primes
primes = generate_primes(limit)
i = 0
prime = primes[i]
while prime <= int(num**0.5):
while num % prime == 0:
num //= prime
yield prime # Returns the next factor
i += 1
prime = primes[i]
yield num
I think this is something what you are looking for. I tried to write it as close as possible to your implementation.
@Phrancis Yeah, exactly. I just used it to avoid importing math.sqrt
Just ask if something is unclear. THe only change should be that you refer to prime by index instead of iterating over them. Hopefully that made sense :p
Every number not a primes n has at least one factor less than sqrt(n). Assume by contradiction that this is false. Since n is composite then n has atleast two factors right? So n = a*b. Since the statement is false a > sqrt(n) and b > sqrt(n)
To start with Common Lisp I am doing Project Euler using this language. Usually I manage to solve problems but I am quite sure that my code is not as efficient as it could be in Common Lisp. That is why I need a review from experienced lispers.
This is my code for problem 35. Please offer any im...
I looked some more into C#'s Math stuff and finding out it's really not been designed with math in mind. I'm only at PE5 so maybe I should switch now instead of later
All the Math stuff has to be Doubles, and Doubles don't support any of the regular operators like == or >= instead it has to be Equality(x, y) and GreaterThanOrEqual(x,y)
I wrote a Java FX application that translates binary to and from String and numbers in Java. Whenever the program is translating large amounts of text to binary it takes a very long time, and leaves the application unresponsive. Could a more efficient algorithm be used to speed up the process?
...
All the Math stuff has to be Doubles, and Doubles don't support any of the regular operators like == or >= instead it has to be Equality(x, y) and GreaterThanOrEqual(x,y)
In other words, integer math is very limited, you pretty much have to roll your own functions
Math specific items like that have their own equality systems because the internals of most languages want a value to compare which usually goes back to a general int, for example, comparing Dates in JS works because they give unix timestamp ints to compare