Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShir Ekerling
1,769 PointsWhere is all the code gone?
Is the video, he explains stuff regarding the class and objects he did in the first explanation but his editor is blank, he just 'assumes' it is there somewhere.
Why is that? And even if this is really how you work with It, it is very hard to understand when you also need to remember in real time something that he has shown just few minutes ago and is completely new which you had no idea exist only 2 minutes ago..
4 Answers
Kuhrt Cowan
23,796 PointsI think he was just giving an example of how you can call a method to store or echo its value. He was just showing what the code for calling a method would look like and then in his last example he brings it all together with his method coded at the top, then calls it underneath. Basically saying, "If we had a method that looked like this (shows the method code)....we would call it like this (shows the calling code)....this is what it looks like all together (shows all the code)". I think he was just trying to add focus to those specific code snippets by having a blank editor with only that code. Though I agree, it is a bit confusing the way it's put together!
Ted Sumner
Courses Plus Student 17,967 PointsThis is not one of the most clear courses. I think I have it down after watching the videos a number of times, answering questions on the forum, and working on programming my own classes for a project. Here is my understanding.
A class is a family of code that you will use repeatedly. Thus, you group it all together so you don't have to write it over and over (DRY) and support MVC (Model, View, Controller) programming. It has the advantage that you can use the same code and variables multiple times at the same time.
The constructor, __construct(), is how you pass arguments into the class. This is magic through the $this->variable = $var;
code because the $this variable has different values for each instance even if it is used at the same time. It makes the whole thing work in my opinion.
The rest of the methods are just functions as normal except that they use the $this variables. Any code in the class that is not the constructor should go in a method so it can be called either in the class or from outside the class.
Hampton calls the class from the same file, but you would normally have the class in a separate file that is either included or required. If you use namespaces, then I think you can also use the 'use' keyword, but I am not clear on that. I got an error when I tried to use 'use' instead of require or include, so I know there is a difference that I have not taken the time to nail down.
Let me know if there is anything else I can help explain.
Shir Ekerling
1,769 PointsTed, thank you. You have cleared up some things for me, Actually, i watched the course several times and also took another on code academy, Both together helped it sink.
A little question if you don't mind - as long as what our skills 'should' me up to that part of the course (OOP) are not enough (or maybe they are?) to start our own projects. I think that not working or not practicing it on several different occasions is what making it so hard to understand. Of course, i have created my own environment with WAMP to work on as well as we have the workspaces but what we (Or i) can write is just 'dummy' classes and objects that do nothing, more like 'Practicing the syntax' instead of practicing programming.
You have mentioned that you are working on your own projects, what kind of projects can you (Or me) do with the current skills? I believe working on something will help a lot to the understanding.
Thanks mate.
Ted Sumner
Courses Plus Student 17,967 PointsI believe that the best approach is to build something as you learn. It really makes it sink in. I regret that I did not follow that advice. You can always refactor as you learn.
As far as projects, I am building a site for my son's cub scout pack. There are many options. You can find a site and build a copy, find a non-profit and build them a site as a volunteer, build a personal site. You are only limited by your imagination. My project is currently live on this site, but will be moved to the proper domain later today most likely.
I still have work to do on it, but appreciate any comments.
Shir Ekerling
1,769 PointsShir Ekerling
1,769 PointsWow this course is EXTREMELY hard to understand. Am i the only one? Is there any where i can find further explanation regarding those topics within treehouse?