none
Couple questions about programming in general, and one specifically about turtle fractle? RRS feed

  • Question

  • So I just got into programming about a week ago and so far its been... exhausting. I started out not knowing where to go at all. Then I read a couple of tutorials for "beginners" but their vocabulary was far beyond mine (yes English is my first language, im just not the smartest person in the world)

    Anyway, after a couple of those, and being completely lost, I shamelessly looked up "programming for kids" and found small basic.

    I read and copied all the exercises in the PDF "Intro to small basic. Can I ask something? Was I suppose to understand all of it? Because some of the things like fractals and arrays blew my mind completely. ALTHOUGH I DIDNT GIVE UP. I KEPT ON GOING JUST LIKE MY MOM USED TO TEACH ME. 

    I got to the end of the PDF to where it says "Fun samples" and I thought now would be a good time to start asking questions. So if you do answer my questions please phrase it like I am a child, because I think i may have borderline dyslexia (BUT THATS NOT GONNA STOP ME FROM TRYING!!)

    My ultimate goal is to create games, which is why I am so determined to learn programming. But there is something I am concerned about and that is the math..... I have heard when progamming games there is a lot of math involved.. and math is 101% my worst subject :( 

    So is this true? Is there a lot of math involved? What do you recommend? Should I just forget about it now and spare time? because math is really hard for me, (to give you an idea of how much I know; im about at an 13 year olds mind level about math)

    Ok enough blabbering and on to the program that has kept me up most the night: The Turtle Fractal program

    I have already read this thread: http://social.msdn.microsoft.com/Forums/en-US/e071c124-391e-4d8e-bd27-336d8dc31722/help-understanding-program-flow-of-fractal-tree-program

    and I dont seem to understand much of what they said, haha

    angle = 30
    delta = 10
    distance = 60
    Turtle.Speed = 9
    GraphicsWindow.BackgroundColor = "Black"
    GraphicsWindow.PenColor = "Green"
    DrawTree()

    Sub DrawTree
      If (distance > 0) Then
        Turtle.Move(distance)
        Turtle.Turn(angle)

        Stack.PushValue("distance", distance)
        distance = distance - delta
        DrawTree()
        Turtle.Turn(-angle * 2)
        DrawTree()
        Turtle.Turn(angle)
        distance = Stack.PopValue("distance")

        Turtle.Move(-distance)
      EndIf
    EndSub

    Ok, so what I dont understand is why the program doesnt end after the turtle moves back after the first 6 times he moves 30 degrees.

    What I mean is why the program doesnt end after:

        distance = Stack.PopValue("distance")
        Turtle.Move(-distance)
      EndIf
    EndSub

    Ok well not sure if anyone is reading this but thanks in advance! :)


    Thursday, December 12, 2013 4:30 AM

Answers

  • Programming is very mathematical in concept and appearance, but not necessarily in complex calculations.  Even NASA engineers use computers and calculators to do the actual math.  However, they DO understand the concepts of what they are working with.

     

    From Algebra, you may recall:

    X = 10

    Y = 5

    What does X + Y equal?  Of course, 15.

    What about X/Y ?  It is 2.

    And X * Y ?  Why 50, of course.

    Functions are another idea from mathematics.  Recall F of X?  That is F(X), where F is the name of the function and X is the value passed into the function F()

     

    Programming is very similar.  Variables may be single letters, whole words, or multiple words.

    V = 1

    MyVariableName = 2

    Functions do things to the values passed into them.

    Function DoubleMe(Value)

        Return Value * 2

    End Function

    So DoubleMe(4) equals 8.

    A subroutine may be thought of a function that does not return a value.

    Both subroutines and functions may be used to group similar line of programming together.

    A fractal is simply a design.  Art.  Something cool to look at.

    If you think of your screen, or a window on a monitor as a grid of rows and columns with dots in it.  Like a piece of graph paper, you can ask the “turtle” to walk from point A to point B.  Recall from math, that a point is an X and Y coordinates?  Think (x,y) = (column, row).  So when you ask the turtle to move, or turn, it is leaving a trail of drawn pixels or dots in the process.

    But your sample code gets fancy.  It contains the function (or subroutine) DrawTree() that calls itself.  That is called recursion.  Google the definition of “recursive.”  It simple means something that goes inside itself.  Thinking about this too hard can make your brain hurt.  But learning is work.  And if the work doesn’t kill you, then it makes you stronger.  Or in this case, smarter.  Learning programming may actually make you better at math.

    A Stack is a software place to save things and pull them off, later.  It is like a Pez candy dispenser.  When you PUSH a candy into the Pez dispenser, to get it out, you must POP it.  Let’s pretend you PUSH three candies into the Stack (Pez dispenser), a red one, a blue one and a yellow one.  You cannot get to the blue one, until you POP or remove the yellow one.  Of course, the red one is buried deep, and you must POP two candies off the stack before you can get to the red one.

    The Stack.PushValue simply saves the value of distance.  The next line changes the UNSAVED value of distance and calls itself, again, with the new value.  Further down, the original value is POPed off the stack and restored.

    Don’t think about this too hard.  It is like Time Travel and going back in time and killing yourself.  It will make your brain hurt.





    Thursday, December 12, 2013 10:06 PM
  • Heyya FatRat27!

    Even though programming involves math, generally it's just a subset of it. Only specialization areas such as fractals, physics, chemistry, etc., we'd really need a deeper knowledge!

    The Turtle example above is very complex and uses a technique called recursive calling,in which a subroutine invokes itself again & again until it reaches its end condition in which it finally starts returning.

    In that case we can see: If (distance > 0) Then. It means once distance becomes 0 or less, that whole block is skipped. Since all of the the recursive callings are there, it starts returning upwards!

    Another technique used there is Stack.PushValue() + Stack.PopValue(). Small Basic doesn't have local variables. That trick pair is a way to overcome the lack of it!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, December 12, 2013 5:44 AM
    Answerer
  • Some programming can have quite a lot of maths, but most of the math for games is just geometry.  However, what makes a good game is fun playing it and this skill is all about imaginative ideas - something like tetris is very addictive but not so complicated.  The fractal example is quite advanced so don't let this put you off.

    Small Basic was aimed at children, but actually a large number of people who use it are adults that are just interested in what programming is about.

    I suggest:

    1. look at and work through the SB curriculum
    2. Some other introductory Technet articles Programming Tips, Event Basics, GraphicsWindow Basics, Array Basics, Stack Basics, Text Basics, Grammar Basics
    3. Solutions to monthly challenges and other posts on this forum - many questions and code snippets will help you
    4. look through the Additional Small Basic Resources and follow the links
    5. Have a go and ask questions
    6. Have fun - some of these may help, some not - people are all different so pick and choose what works.

    EDIT

    The page here has loads of Technet links including some of those above, but also many more Small Basic Portal

    Thursday, December 12, 2013 7:16 PM
    Moderator
  • Some comments:

    1] Use TextWindow.ReadNumber() when the input has to be a number.

    2] For each friend name entered you call the sub friends(), but only output if the current i >= input (i.e the last one.

    Perhaps enter all the friends, then output them at the end.

    TextWindow.Write("How many friends do you have? ")
    input = TextWindow.ReadNumber()
    For i = 1 To input
      TextWindow.Write("Enter the names of your friends: ")
      friends[i] = TextWindow.Read()
    EndFor
    
    friends()
    
    'SUBROUTINES
    
    Sub friends
      TextWindow.Write("These are your holmes: ")
      For i = 1 To input
        TextWindow.Write(friends[i] + " ")
      EndFor
      TextWindow.WriteLine("") ' to start a new line
    EndSub 

    EDIT

    Also it is good practice to use different names for variables and subroutines, don't use a variable friends and a subroutine called friends().  It works in SB, but not a good idea in general.

    Thursday, December 12, 2013 9:57 PM
    Moderator
  • Hello Fatrat

    You mention that you started a week ago and have read the Intro to Small basic. That's very fast. Perhaps too fast which can lead to bad moral which primarily is caused from not being able to code what you want or a program not doing what you want it to. I suspect bad moral/frustration is the underlying cause of people giving up.

    In litdevs post above there's links to the curriculum and other good learning resources. My tip is: download the curriculum and work through every chapter from start to finish. Take your time and be patient. When you get to an exercise or code sample, attempt it yourself and refer/check your code against the sample. Avoid skipping ahead if you don't understand something at 1st attempt. Perhaps take a break, come back to it and ask questions here.

    Start small, read curriculum, practice (learn by doing), do some of the easier monthly challenges and you'll build your skill. Experience at coding is what you'll get with time and practice.

    I've done a little bit of research into learning to be a good programmer here's an article all about learning to become a good programmer. Development Map for Becoming a Good Programmer Using Small Basic and MSDN            

    re math: I recently read a book called Coders at Work, it has biographies of some esteemed and very skillfull developers. Quite a few of them weren't very good at math, yet they were brilliant developers and had a hand in some of the big applications we use today. Besides a lot of the math is already done for us or you can always ask a Mathematician. I just joined a good math forum. So many resources.

    A lot of people on this forum have been learning with sb for a year or 2 first then maybe pick another language after that. Takes 5 years to get any good at it. Same deal for most things, takes 5 years to become a plumber....

    All the best, hope to see you round. Coding is very rewarding and satisfying. Fun. Don't let it ever frustrate you. There's always a reason why something doesn't work.

    Friday, December 13, 2013 9:31 AM
    Moderator

All replies

  • Heyya FatRat27!

    Even though programming involves math, generally it's just a subset of it. Only specialization areas such as fractals, physics, chemistry, etc., we'd really need a deeper knowledge!

    The Turtle example above is very complex and uses a technique called recursive calling,in which a subroutine invokes itself again & again until it reaches its end condition in which it finally starts returning.

    In that case we can see: If (distance > 0) Then. It means once distance becomes 0 or less, that whole block is skipped. Since all of the the recursive callings are there, it starts returning upwards!

    Another technique used there is Stack.PushValue() + Stack.PopValue(). Small Basic doesn't have local variables. That trick pair is a way to overcome the lack of it!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, December 12, 2013 5:44 AM
    Answerer
  • But I want you to know that example got nothing to do w/ game development! I don't understand much that complex logic myself either!

    You should begin w/ simple things like make a Shape moving w/ the arrow keys or something like that!  :D

    You should definetely take a look at this excellent article below:

    Dynamic Graphics

    And even though it's got nothing to do w/ SB, these beginner videos are so good & easy that you should watch them too:

    Hour of Code

    We'll surely help you out if you post a troublesome code. Welcome aboard!  :P


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, December 12, 2013 5:50 AM
    Answerer
  • Yes maths is involved quite a lot but i was in the lowest maths at my school and started the computing courses at my school and i feel it's helped with my maths, So I recommend starting off with smallbasic and just work on your programming and maths.
    Thursday, December 12, 2013 6:45 PM
  • Some programming can have quite a lot of maths, but most of the math for games is just geometry.  However, what makes a good game is fun playing it and this skill is all about imaginative ideas - something like tetris is very addictive but not so complicated.  The fractal example is quite advanced so don't let this put you off.

    Small Basic was aimed at children, but actually a large number of people who use it are adults that are just interested in what programming is about.

    I suggest:

    1. look at and work through the SB curriculum
    2. Some other introductory Technet articles Programming Tips, Event Basics, GraphicsWindow Basics, Array Basics, Stack Basics, Text Basics, Grammar Basics
    3. Solutions to monthly challenges and other posts on this forum - many questions and code snippets will help you
    4. look through the Additional Small Basic Resources and follow the links
    5. Have a go and ask questions
    6. Have fun - some of these may help, some not - people are all different so pick and choose what works.

    EDIT

    The page here has loads of Technet links including some of those above, but also many more Small Basic Portal

    Thursday, December 12, 2013 7:16 PM
    Moderator
  • Hey, thanks for your advice. I'm reading the SB curriculum right now.

    I made this program, (it doesnt work they way i want it to) and I was wondering if you could help.

    What I want it to do is: 

    -Ask how many friends do you have

    -Asks the user to enter the names

    -Tells the users all the names of the friends they entered.

    I know that is simple, but I can't figure it out. Below is how far I have gotten. Thanks!

    TextWindow.Write("How many friends do you have? ")
    input = TextWindow.Read()
    For i = 1 To input
      TextWindow.Write("Enter the names of your friends: ")
      friends[i] = TextWindow.Read()
      friends()
    EndFor


    Sub friends
      If i >= input Then
        TextWindow.Write("These are your holmes: " + friends[i])
      EndIf
    EndSub

    Thursday, December 12, 2013 9:47 PM
  • Some comments:

    1] Use TextWindow.ReadNumber() when the input has to be a number.

    2] For each friend name entered you call the sub friends(), but only output if the current i >= input (i.e the last one.

    Perhaps enter all the friends, then output them at the end.

    TextWindow.Write("How many friends do you have? ")
    input = TextWindow.ReadNumber()
    For i = 1 To input
      TextWindow.Write("Enter the names of your friends: ")
      friends[i] = TextWindow.Read()
    EndFor
    
    friends()
    
    'SUBROUTINES
    
    Sub friends
      TextWindow.Write("These are your holmes: ")
      For i = 1 To input
        TextWindow.Write(friends[i] + " ")
      EndFor
      TextWindow.WriteLine("") ' to start a new line
    EndSub 

    EDIT

    Also it is good practice to use different names for variables and subroutines, don't use a variable friends and a subroutine called friends().  It works in SB, but not a good idea in general.

    Thursday, December 12, 2013 9:57 PM
    Moderator
  • Programming is very mathematical in concept and appearance, but not necessarily in complex calculations.  Even NASA engineers use computers and calculators to do the actual math.  However, they DO understand the concepts of what they are working with.

     

    From Algebra, you may recall:

    X = 10

    Y = 5

    What does X + Y equal?  Of course, 15.

    What about X/Y ?  It is 2.

    And X * Y ?  Why 50, of course.

    Functions are another idea from mathematics.  Recall F of X?  That is F(X), where F is the name of the function and X is the value passed into the function F()

     

    Programming is very similar.  Variables may be single letters, whole words, or multiple words.

    V = 1

    MyVariableName = 2

    Functions do things to the values passed into them.

    Function DoubleMe(Value)

        Return Value * 2

    End Function

    So DoubleMe(4) equals 8.

    A subroutine may be thought of a function that does not return a value.

    Both subroutines and functions may be used to group similar line of programming together.

    A fractal is simply a design.  Art.  Something cool to look at.

    If you think of your screen, or a window on a monitor as a grid of rows and columns with dots in it.  Like a piece of graph paper, you can ask the “turtle” to walk from point A to point B.  Recall from math, that a point is an X and Y coordinates?  Think (x,y) = (column, row).  So when you ask the turtle to move, or turn, it is leaving a trail of drawn pixels or dots in the process.

    But your sample code gets fancy.  It contains the function (or subroutine) DrawTree() that calls itself.  That is called recursion.  Google the definition of “recursive.”  It simple means something that goes inside itself.  Thinking about this too hard can make your brain hurt.  But learning is work.  And if the work doesn’t kill you, then it makes you stronger.  Or in this case, smarter.  Learning programming may actually make you better at math.

    A Stack is a software place to save things and pull them off, later.  It is like a Pez candy dispenser.  When you PUSH a candy into the Pez dispenser, to get it out, you must POP it.  Let’s pretend you PUSH three candies into the Stack (Pez dispenser), a red one, a blue one and a yellow one.  You cannot get to the blue one, until you POP or remove the yellow one.  Of course, the red one is buried deep, and you must POP two candies off the stack before you can get to the red one.

    The Stack.PushValue simply saves the value of distance.  The next line changes the UNSAVED value of distance and calls itself, again, with the new value.  Further down, the original value is POPed off the stack and restored.

    Don’t think about this too hard.  It is like Time Travel and going back in time and killing yourself.  It will make your brain hurt.





    Thursday, December 12, 2013 10:06 PM
  • Yes! This is exactly what I wanted, thank you so much!

    I tried adding some punctuation with commas and periods, tell me if I shouldve done this another way:

    TextWindow.Write("How many friends do you have? ")
    input = TextWindow.ReadNumber()
    For i = 1 To input
      TextWindow.Write("Enter the names of your friends: ")
      friends[i] = TextWindow.Read()
    EndFor

    friends()

    Sub friends
      TextWindow.Write("These are your holmes: ")
      For i = 1 To input - 1
        TextWindow.Write(friends[i] + ", ")
      EndFor
      TextWindow.WriteLine(friends[input] + ".")
    EndSub 

    Is that how you wouldve done it?


    • Edited by FatRat27 Thursday, December 12, 2013 10:09 PM
    Thursday, December 12, 2013 10:08 PM
  • Yep that looks fine - I added a comment on earlier post to perhaps not use the same name for variables and a subroutine, but apart from that your code is good.
    Thursday, December 12, 2013 10:15 PM
    Moderator
  • ok gotchya, thanks. If I have other really small questions about really small programs where should I ask them? Is there like a real time chat or something? THanks
    Thursday, December 12, 2013 10:30 PM
  • Programming is very mathematical in concept and appearance, but not necessarily in complex calculations.  Even NASA engineers use computers and calculators to do the actual math.  However, they DO understand the concepts of what they are working with.

     

    From Algebra, you may recall:

    X = 10

    Y = 5

    What does X + Y equal?  Of course, 15.

    What about X/Y ?  It is 2.

    And X * Y ?  Why 50, of course.

    Functions are another idea from mathematics.  Recall F of X?  That is F(X), where F is the name of the function and X is the value passed into the function F()

     

    Programming is very similar.  Variables may be single letters, whole words, or multiple words.

    V = 1

    MyVariableName = 2

    Functions do things to the values passed into them.

    Function DoubleMe(Value)

        Return Value * 2

    End Function

    So DoubleMe(4) equals 8.

    A subroutine may be thought of a function that does not return a value.

    Both subroutines and functions may be used to group similar line of programming together.

    A fractal is simply a design.  Art.  Something cool to look at.

    If you think of your screen, or a window on a monitor as a grid of rows and columns with dots in it.  Like a piece of graph paper, you can ask the “turtle” to walk from point A to point B.  Recall from math, that a point is an X and Y coordinates?  Think (x,y) = (column, row).  So when you ask the turtle to move, or turn, it is leaving a trail of drawn pixels or dots in the process.

    But your sample code gets fancy.  It contains the function (or subroutine) DrawTree() that calls itself.  That is called recursion.  Google the definition of “recursive.”  It simple means something that goes inside itself.  Thinking about this too hard can make your brain hurt.  But learning is work.  And if the work doesn’t kill you, then it makes you stronger.  Or in this case, smarter.  Learning programming may actually make you better at math.

    A Stack is a software place to save things and pull them off, later.  It is like a Pez candy dispenser.  When you PUSH a candy into the Pez dispenser, to get it out, you must POP it.  Let’s pretend you PUSH three candies into the Stack (Pez dispenser), a red one, a blue one and a yellow one.  You cannot get to the blue one, until you POP or remove the yellow one.  Of course, the red one is buried deep, and you must POP two candies off the stack before you can get to the red one.

    The Stack.PushValue simply saves the value of distance.  The next line changes the UNSAVED value of distance and calls itself, again, with the new value.  Further down, the original value is POPed off the stack and restored.

    Don’t think about this too hard.  It is like Time Travel and going back in time and killing yourself.  It will make your brain hurt.





    Thanks for the kind advice!

    That pez comparison REALLY helped me

    Thursday, December 12, 2013 10:30 PM
  • This forum is the place to ask - there are plenty of helpful and knowledgeable coders ready to help pretty much round the clock on different time zones.

    My advice for the best help is to work on the problem you have a bit first, narrow the question down to a short and concise code example and question (just like you did here).  Ask separate questions on new threads as they are easier for others to follow.

    Thursday, December 12, 2013 10:48 PM
    Moderator
  • Hello Fatrat

    You mention that you started a week ago and have read the Intro to Small basic. That's very fast. Perhaps too fast which can lead to bad moral which primarily is caused from not being able to code what you want or a program not doing what you want it to. I suspect bad moral/frustration is the underlying cause of people giving up.

    In litdevs post above there's links to the curriculum and other good learning resources. My tip is: download the curriculum and work through every chapter from start to finish. Take your time and be patient. When you get to an exercise or code sample, attempt it yourself and refer/check your code against the sample. Avoid skipping ahead if you don't understand something at 1st attempt. Perhaps take a break, come back to it and ask questions here.

    Start small, read curriculum, practice (learn by doing), do some of the easier monthly challenges and you'll build your skill. Experience at coding is what you'll get with time and practice.

    I've done a little bit of research into learning to be a good programmer here's an article all about learning to become a good programmer. Development Map for Becoming a Good Programmer Using Small Basic and MSDN            

    re math: I recently read a book called Coders at Work, it has biographies of some esteemed and very skillfull developers. Quite a few of them weren't very good at math, yet they were brilliant developers and had a hand in some of the big applications we use today. Besides a lot of the math is already done for us or you can always ask a Mathematician. I just joined a good math forum. So many resources.

    A lot of people on this forum have been learning with sb for a year or 2 first then maybe pick another language after that. Takes 5 years to get any good at it. Same deal for most things, takes 5 years to become a plumber....

    All the best, hope to see you round. Coding is very rewarding and satisfying. Fun. Don't let it ever frustrate you. There's always a reason why something doesn't work.

    Friday, December 13, 2013 9:31 AM
    Moderator
  • Also you mention you looked at Arrays and it blew your mind. Of course. Would blow anyone's mind.

    I looked at arrays after about 2 or 3 months and had a reasonable understanding of them after about 5 or 6.

    We're all in the same boat. Takes time. A bit like rolling a snow ball. It just builds as it rolls.

    Friday, December 13, 2013 9:40 AM
    Moderator
  • re Math prerequisite.

    I think everyone has a unique skill set grown upon a sea of dna in an unique environment.

    I think programming (as well as all other things) can help develop unique skill sets and personal attributes. I liked the comment about creativity.

    Some programs are reliant upon approximations as opposed to super accurate and complicated math.

    I've been picking up a bit math as I go, also a bit of physics, some social science (UI), some art and also an open mind to the thoughts of others on how to code something.

    Friday, December 13, 2013 10:07 AM
    Moderator