learning to code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • justin_ator
    🥓<strong><span style="col
    • Mar 2007
    • 7648

    #16
    Re: learning to code

    Originally posted by reuben_tate
    -Comment your code. First, by commenting your code, it forces you to think about what the piece of code is actually accomplishing. Second, comments help for when other people (including future versions of yourself) have to read your code.
    This may not seem important at the time, but it truly is an incredibly helpful thing - it allows you to not only "explain" your code to someone else but also allows you to recall later on how you solved a particular problem or how your output was coming about. Logic (once you get used to it) may make sense to you one day when you're slaving away at making something work how you want it to, but when you come back to it you could be looking at it like you are reading Greek. I coded a battleship program in C++ and the "AI" I was developing was not overly intuitive. I didn't bother commenting well the first time through, and the next time I went in to work on it and debug something for an issue I was having, it was a nightmare. I had to essentially re-learn the process I was using.

    Originally posted by reuben_tate
    -Learn how to trace your code (by hand). Given a piece of code, you should be able to tell what the output is going to be. This is a good skill for debugging, especially for small test cases and edge cases.
    I do this all the time. If you think you should be getting a certain output and you're not, trace through piece by piece and gather your expected output and behavior at each point. Once you've done that, add in catches or change minor things to test or display your output along the way, allowing you to see where things went wrong if they weren't popping out to you before.

    Originally posted by reuben_tate
    -When trying to program, sometimes it helps to not jump straight into coding. In essence, you want to create an algorithm. In cooking, people call this a recipe. If you can write a recipe, you can code. First, think about how you would describe the algorithm ("recipe") to another person, in English terms. It can even be an algorithm that involves the other person using a paper/pencil setup. Now, for each step in the algorithm you came up with, clarify the step and/or break down the step into smaller steps such that every step is unambiguous. Once you have your collection of unambiguous steps, then they should easily translate into code.
    This is probably my #1 used thing when writing new code on something. If it's a simple project that uses concepts I already know I may dive into writing code, but almost 95% of the time I am going to actually start by writing "pseudo-code", or paraphrased steps of what I need to accomplish to reach the goal. You absolutely want to break this down to the smallest pieces for every step along the way, and over time you'll be able to start filling things in with code (ie I need a variable for this, or I need to loop through a function for this outcome, etc).

    Best of luck with things. Practice really does make perfect.

    Comment

    • rushyrulz
      Digital Dancing!
      FFR Simfile Author
      FFR Music Producer
      • Feb 2006
      • 12985

      #17
      Re: learning to code

      Guys he's in java 1, basically learn to regurgitate the following:

      pretty much copy paste this into template.java and cp it to whatever you're working in
      Code:
      import java.util.Scanner;
      
      public class PROGNAME{
      
      	public static void main(String args[]){
      		Scanner input = new Scanner(System.in);
      	}
      }
      Object reference creation code:

      Code:
      Objname refname = new Objname(args);
      and to call the object's methods:

      Code:
      refname.someMethod(args);
      use appropriate scoping or you'll regret it. Learn the difference between public, private, protected in variable and method declaration.

      Java is verbose as shit and I hate it. The syntax can get pretty messy, especially with exception handling. Commenting, tracing, and pseudocoding are good practices that have been suggested in this thread.


      Comment

      • Reincarnate
        x'); DROP TABLE FFR;--
        • Nov 2010
        • 6332

        #18
        Re: learning to code

        Honestly, I recommend Python to most people learning to code, because it's about as close to pseudocode as you can get. Once you get the hang of actually making stuff, it's much easier to introduce things like C++, Java, etc.

        Comment

        • Jonlovesddr
          h
          • Sep 2008
          • 1631

          #19
          Re: learning to code

          thank 2 all
          if i pass this final i can take the next course in the sequence in the spring and i have 6 weeks to prepare and get ahead
          if i fail then ill have to wait until next fall to retake it which is really shitty...

          Comment

          • llyair
            Wiki Staff
            • Jun 2014
            • 307

            #20
            Re: learning to code

            Everyone starts from somewhere and just trying to ask for info/help is definitely the right mindset for improving! To re-emphasize what everyone else said, it's important to think about how you want to code the solution before jumping in and realizing halfway through that it doesn't work and you have to start over again. One of my professors used to recommend about 50/50 ratio for planning/implementing, and from experience I pretty much agree give or take depending on the problem, because usually if you design or do pseudocode correctly, implementing isn't too bad.

            I think at this point it's just important to ask as many questions about your code as possible. Don't just read books about Java, do lots of practice, some OOP concepts/data structures that are hard to memorize without context (inheritance, polymorphism, interfaces, abstract classes, lists, hashmaps, etc.) can become a no-brainer once you see how they're used.

            And also try implementing (or thinking about implementing) things different ways. Then ask, "well why does this way not work?" Or, "Why is that way better?" If you still don't get it, look for a different way of explaining that makes sense to you - everyone thinks differently, and that's okay.

            And if you run into any weird syntax you don't understand, GOOGLE IT! In Java, keywords (final/constant/protected/etc.) have vastly different meanings, and learning how to properly use them can prevent bugs... And another nice thing is, a lot of the keywords' concepts carry over into other languages, so it's usually worth it to try understanding them. I definitely recommend investing the time to ask the questions now, when you're in your first semester, rather than later when a good foundation will be critical and you'd also be busier with other upper level classes xD

            Another big thing that was very helpful for me was learning how to debug properly to find out what's not working. Adding print statements is fine at first, but a debugger is much more powerful. Eclipse has a good debugger.
            Last edited by llyair; 12-14-2015, 06:47 PM.

            Comment

            Working...