View Full Version : Critique my code sample!
Viridian
02-13-2006, 10:57 AM
I'm currently on the job hunt and over the weekend I wrote up a code sample to submit to potential employers. It's an A* demonstration program. I tried to write it in such a way that it could compile easily on multiple platforms. It does not require anything beyond the STL.
If anyone wants to take a look at it and give me any feedback, I'd be grateful.
http://www.viridiangames.com/bin/astar.cpp
Viridian
Michael Flad
02-13-2006, 12:02 PM
Just some minor points
- I'd separate pathfinding from the map, not a big thing for just sample code though
- qualifiers starting with an underscore are reserved for implementation (stdlibrary/compiler etc.)
- it's more readable to use constants/enums or even defines instead of hardcoded magic numbers (if(_LowestScoreHelper == 2147483647)).
- you do return/call by value (list<int,int>) resulting in additional copys of your objects where I think a reference/pointer type would be the appropriate way.
I didn't have a really close look at the implementation details but just one small note. A* does a lot of search for nodes in open/closed lists, so you can get a huge speedup by just adding 2 bitflags (inopen/inclosed) to each mapcell for fast rejection of nodes before searching the lists (should be enough to just put that as a small comment somewhere).
Good luck for your job search
GBGames
02-13-2006, 01:12 PM
I haven't looked at your code sample, but you did mention that it needed STL. When I was at a panel over a year ago, Midway had some representatives, and they said that if you wanted to submit code, keep in mind that you should be able to show them you can do so without STL. STL might be badly implemented on certain compilers, and when it comes to console development, you should be able to show how to make code tight if needed. I think using STL is perfectly fine, but it would be nice to show that you can implement something if it isn't available or useful.
GameStudioD
02-13-2006, 01:52 PM
If you are writing an A* example, I assume you are looking for an entry level job. I would not recommend writing code samples. If you have demo applications, fine. If they want to see the code for a demo application, fine. But, as a person looking for an entry level position, your code samples will not impress engineers with years of experience. That's the truth. On their own terms, an employer will grill you on the fundamentals (datastructures, search algorithms, linear algebra, etc), you can count on that. Your time is much better spent studying the fundamentals and preparing for the common interview questions.
Rule number 0 of programming (as well as rules 1-10) "no copy and paste".
While you did not do this excessively, did you find yourself using text-copying when you wrote "list<pair<int, int> >" so often ?
typedef pair<int,int> Point;
typedef list<Point> PointList;
Would be a good start, however a simple Point class (struct actually) would be better than pair<int,int>. This would then be used in your AStarNode class (instead of m_X,m_Y), with operator== etc, compressing your code and making it more readable.
Agree with above comments about leading underbar, explicit constants - even a #define (MAX_INT ?) would be better than an explicit number and also return-by-value makes me squirm a bit.
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.