Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Improving the Application Code Refactor 1: Create List Items

Bonnie Martin
Bonnie Martin
13,671 Points

This part was really confusing and disappointing for me.

I found this process to be SUPER confusing and it didn't even reduce the amount of code.

I was following along great before this, and I felt like I really understood what was going on. Then with this whole rearrangement, everything is much less clear. If you asked me what each line of code was doing, I couldn't tell you anymore.

Plus, I still have the same amount of code. I saved the original version that we'd been working on previous to this, and made a new version as I followed along with this video. Both have the exact same number of lines of code.

So now I don't know what to think. If this was a real-world situation, what would be the better solution? To keep something I understand, or to use code that is supposedly "better" but in reality is way more confusing?

Ugh.

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

feel exactly the same way :/ its like whatever i learned and understood all along is gone in 10 min, thanks to this "refactoring".... should be called 'reconfusing' instead.

3 Answers

Nicholas Gaerlan
Nicholas Gaerlan
9,501 Points

In the real world, you would refactor using the same general ideas instead of leaving the code as-is. I think this is one of the fundamental ideas in OOP to grasp. Maybe one of the biggest hurdles to clear in order to progress past script / markup languages. It's a challenge, but the "aha!" payoff is worth it. Plus, I think if you can grasp it, then it opens the door to idiomatic programming ideas / design patterns / and other abstract ways of thinking about how to solve problems as a programmer. When you read that programmers end up learning way more than one language, it's because they're all pretty similar and refactoring code into functions and objects is a big part of it. On the other hand, simpler things like wordpress will not require this sort of thing and you can definitely make a living with a simpler combination of wordpress, PHP, and SQL.

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

appreciate your answer here, i just wish it was bit simpler and easier to understand than guil did in this video, may be to make it a whole conceptual explained video like other topics and programs etc. any suggestions to make all this understand alot simpler ? would be alot of help! thanks

Christian van Lierop
Christian van Lierop
13,758 Points

This video was pretty confusing to me too. Although I do understand the basic concept of what he's trying to say, the pace seems to have stepped up to triple, rushing over very important and reasonably complex concepts.

Also, although the code is shorter c.q. takes up less characters (does that speed up the code significantly?), for a beginning programmer like me it's actually MUCH harder to read. Instead of understanding what each line of code does, I now have to go back to every function and decrypt the syntax, to decypher what it actually does...

I can understand that for an advanced programmer, this makes perfect sense. But if I were to see this code fresh out the box, I'm not shure I would be able to decrypt it and understand what it does, at all... I guess I still have a long road ahead of me...

Nicholas Wallen
Nicholas Wallen
12,278 Points

Agree completely. This does not seem aimed at beginners. I was finally to the point where I understood the program up until this point, and even after watching the video, I can't understand it.

Armin Memic
PLUS
Armin Memic
Courses Plus Student 7,481 Points

Yeah, I agree that it was a bit confusing. I think the positives are that the code is easier maintained, especially if you are working with other people or have to change your code in the future. There is a huge difference in coding alone in a text editor and in a project with other people.