(10-30-2015, 05:37 PM)Azriel Wrote: I used to write code like that, and actually I used to write it much, muuuch worse than that (to the point my current self got lost reading it ._.). You're on track to getting good; I think you're at the point that you need to see good practise code to produce it.lol, thank you very much, glad to hear. I really need to start getting myself into the git community for feedback in what I do.
Quote:[*]The code you're showing is a parser, so it's going to be longer than "normal", but these functions are still quite big, and not "simple enough to understand by skimming":There you knew it :P. But yes, I see your point. You, as someone who've done this as a profession and have worked with professionals, would you agree to say that it's better to avoid shortforms entirely in naming and stick to full forms even if the names grew long?
Code:AExpression<numeraltype>::processScopeTokens(std::string expression_string)
AExpression<numeraltype>::init
AExpression<numeraltype>::handlePrecedenceOfOperators()
AScope<numeraltype>::getFuncParameter(std::string line, int number)
Quote:[*]Make smaller classes, such that you have one class per responsibility. When I've got time I'll elaborate on this, but google for solid design principles.I don't know what other class I could've had in there. AExpressions compile and evaluate expressions, and AScope stores a scope or a "context" of defined variables and functions.
I have read some guides on structure and design, and together with your points, I started trying out different approaches which will hopefully end with better code.
I appreciate your time =)
@Someone else
(03-10-2014, 09:16 PM)Someone else Wrote: One thing you can do is to split the function parameters across multiple lines like:Were you talking about designing the function so that it takes a struct instead of multiple parameters or about another way to pass parameters, regardless of how many parameters it's prototyped to take, using a single object instance?
This is what I tend to do, but sometimes this can get completely overwhelming (or tiresome for the cpu since it passes a lot of bytes to the function)Code:d3d_set_projection_ext(x,y,z,
x+sin(dir*pi/180)*cos(zdir*pi/180),y+cos(dir*pi/180)*cos(zdir*pi/180),z+sin(zdir),
0,0,1,angle,window_get_width()/window_get_height(),znear,zfar);
In this case you can use a structure to store the values like:
Code:typedef struct {
double xfrom;
double yfrom;
double zfrom;
double xto;
double yto;
double zto;
double xup;
double yup;
double zup;
unsigned int angle;
float aspect;
unsigned int znear;
unsigned int zfar;
} ProjectStruct;
//...
ProjectStruct Projection;
Projection.xfrom = x;
//...
d3d_set_projection_ext(&Projection);
You left me quite confused there, because the compiler complains about the number of arguments, and at the same time the function sounds like something out from a library (direct3d).
![[Image: signature.png]](http://s3.postimg.org/wedqxlk3n/signature.png)
A-Engine: A new beat em up game engine inspired by LF2. Coming soon
A-Engine Dev Blog - Update #8: Timeout

Chat
