pearselab / r-intro-jocelyn-cuthbert

r-intro-jocelyn-cuthbert created by GitHub Classroom
0 stars 0 forks source link

Advice about new styles of programming #6

Closed willpearse closed 7 years ago

willpearse commented 7 years ago

I remember in class we talked briefly about how you had learnt to program in another language before. You might remember that I could tell from the way you were using flags in your code. It was easy for me to recognise because I used to be one of those programmers too!

Maybe if I'm more specific about how to avoid using flags, it'll help you. Please remember that I'm not telling you this because you've done something wrong - quite the opposite. Your code is very good already, and I'm trying to help you get better.

Does that make some sense? I have a lot of sympathy with you because I was taught to use flags too - I promise you, you can get out of the habit :D

willpearse commented 7 years ago

Oh yes, and one more thing: try to avoid using = - instead, use <-. It's less likely to be confused with ==, and is less flexible for other programmers. If you want me to go through the reasons I can in class, but trust me - you'll have a much better time of it if you only use = when you're giving default values for arguments (like in my other comment).

jocelyn-cuthbert commented 7 years ago

Hi Will, So I actually haven't learned any other codes before - I just was working with the girl that had on this problem. So if the flag is unnecessary, which is telling it once the number hits 1 to stop the -1 (because prime numbers is the n/n-1 continuing on until you hit 1)- how do I tell is to break at that point? Instead of flag == 1 would it be if i ==1 then break?

willpearse commented 7 years ago

Ah, sorry. It's quite difficult to see over the webcam, so I'm having a trouble keeping track of people except for through their usernames!

You're exactly right. If you want to break, then just break! There's no need to record that you want to do so, then later check to see if you wanted to do it.