Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Ripping apart various tutorials and removing errors from them  (Read 2623 times)

0 Members and 1 Guest are viewing this topic.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Needless to say I ran into something rather interesting.  It's common knowledge that most tutorials have some bugs in them, especially ones from people that might not know as much as they are letting on but still want to try their best to help.


Most of the time when I'm hunting for tutorials I'm trying to find out something I didn't know but more often than not I also run into my fair share of ones that have bad coding habits and styles in them that might end up teaching some people those vary bad habits.  So I figured why not rip the thing apart and clear out as many bugs, bad habits, and just plain bad code as I could find.


Wasn't sure where to post this either but it sounded like an interesting discussion topic.  Most of the time we get told to shy away from tutorials due to things like bad code practices and other negative things. 

Here's one I did find while hunting for a state machine design to work with: https://www.binpress.com/tutorial/creating-a-city-building-game-with-sfml-part-1-state-manager/123

Now I'll warn you now that some chunks of the code aren't something you want to just C&P.  Make sure when you run into any tutorial to read the code closely and also how the person that made it did things.  This way you can avoid the same bad habits if there are any.  Like others have said in the past don't just straight up C&P the code.  Make sure you understand it well beforehand and try to correct anything that looks like it needs to be in what you run into.  I've found trying to correct other people's errors helps me learn what I want to better and it helps speed things along later as well.

I have many ideas but need the help of others to find way to make use of them.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10390
    • View Profile
    • development blog
    • Email
Re: Ripping apart various tutorials and removing errors from them
« Reply #1 on: May 28, 2015, 10:57:24 am »
I'm not exactly sure what kind of discussion you want to start here. Can you be a bit more explicit?

I haven't look at many text-based tutorials, but I assume they more often end up being better than video tutorials, because they can be updated and because one has to write down and think about the what has been written, they tend to contain less random babbling, which in video tutorials can lead to people talking about topics they actually have no idea.

The state manager from the City Building tutorial would be a good enough implementation, if he used smart pointers. The use of manual memory management makes it "unsafe" in a few places.
I don't agree with some of the coding conventions (this->, one-line if-statements, etc.) he's using, but then again, that's a personal preference.

To be fair though, the focus of the series is on the city building and not on how to create a generic state manager.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Ripping apart various tutorials and removing errors from them
« Reply #2 on: May 29, 2015, 12:49:18 am »
One thing that was funny was I was trying to change out as much of the normal pointers as I could for smart pointers.  As for the discussion, now that I read it, the thing is confusing me too. :(


The idea was main a discussion about tutorials and how some might need fixing and to not just copy the code. :)

PS: The only thing I haven't figured out in that tutorial how to change to smart pointers is the pointer to game. :(  Other than that I basically turned most of it to smart pointers trying to learn them again in C++11. :)
« Last Edit: May 29, 2015, 12:52:43 am by StormWingDelta »
I have many ideas but need the help of others to find way to make use of them.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10390
    • View Profile
    • development blog
    • Email
Re: Ripping apart various tutorials and removing errors from them
« Reply #3 on: May 29, 2015, 01:52:18 am »
You replace the Game* with a Game&. A State instance can only exist if a Game instance exists, because Game is the state manager, as such Game* will always hold a value. Because of that and because a state doesn't influence the lifetime of Game, a reference is the right choice here.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

 

anything