Something that has been impressed upon me recently is the importance of planning out a program before you start writing code. I understood this in principle before, but I didn't realize how easy it is to lose sight of.
When you learn something new, the temptation is to treat it like what you already know. Shoehorn it in to code you already know to work and hope for the best. Thinking as long as your variables and calls look similar to whats been demonstrated to you, things will work out.
Today though, I took the time to really understand Angular before I tried to start using it.
I even went back and cleaned up my existing code to cement my understanding of what I had written so far. I declared all my variables together. Put my master AJAX up top where I could reference it easily. Put all my HTML verb calls together. Wrote all the functions for my edit and delete buttons in the same place. Once I had it all mapped out, it felt like the code wrote itself. It made it so much easier to debug and play with.
After I had everything neat and tidy, it was much easier to see where Angular fit in. I still had some hiccups I needed a classmate to look at, and really for the most part I feel like I'm just adding "$scope." to a bunch of this I'd written before, but things fell into place a lot more gracefully than it would have been had I just kept hammering away at sloppy code.
Now I feel like I could whip up a website that could post to and update from a database in 15 minutes. My HTML, JavaScript, and AJAX has been cleaned up and smoothed out. The seeds of Angular have a peaceful place to grow.
No comments:
Post a Comment