reading source code

Discussion about everything. New games, 3d math, development tips...
Post Reply
inovermyhead
Posts: 26
Joined: Mon Aug 03, 2009 2:16 pm

reading source code

Post by inovermyhead »

I am trying to look at code so i can learn but some of the code i looked at are so complicated it is next to impossible to understand a thing. This might sound dumb but any tips on reading source codes? (C++)


inovermyhead
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

You can't read a new language untill you learn it's grammar.
So, start learning c++.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

What code are you trying to read? What are you trying to learn? C++? Irrlicht? Both?

Some people write horrible code that no one else would have a hope in hell of understanding. Some people write beautiful code that can be understood by everyone. Sometimes code can't be written beautifully due to the complexity of what the code is doing or has to be written in a fairly unreadable manner for the sake of efficiency.

If you're trying to learn C++ then there's loads of very simple, easy to follow tutorials that you can find by googling for them.

If you're trying to learn Irrlicht then there's the tutorials that come with the SDK which should be pretty easy to follow.
Image Image Image
inovermyhead
Posts: 26
Joined: Mon Aug 03, 2009 2:16 pm

Post by inovermyhead »

Sorry, i should have been clearer but i was in a rush. I know C++ very well, well sort of but reading someone elses code is an education Some people break rules, and make the code more confusing. I am just trying to read code on skeletal animation
I am trying to develop aa aquarium in realtime

inovermyhead
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Source code is always harder to read than it is to write, but the (un)tidiness of any code can usually be attributed to its history. The skinned mesh code started out as the MS3D loader and animation player, Luke built the B3D loader based on it. The B3D loader/player was then refactored to make the SkinnedMesh animation player, the skinned format loaders were adapted to push data into this new mesh type.
If you add up the different programming styles, the bugfixes, optimizations and workarounds, both historic and recent, you've got a reasonable explanation of why it may be untidy or confusing in places.
Once you've read and understood it, feel free to post patches which tidy it up!
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

Well, when I'm trying to learn someone else's code, I'll put a debug break on the line where I want to begin and start stepping through the code in execution order.

If I already understand what the function call does, then maybe I'll 'step over' it, and there's a lot of times where you'll be sent to STL ctors where it is best to just 'step out'.

It's best to include the Irrlicht source into your workspace as a separate project. Be sure to set your dependencies correctly. This is so you can guarantee the debug symbols are loaded and it makes stepping through the code easier.
-James
Post Reply