|
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging
![]() |
|
|
Thread Tools | Display Modes |
|
|
#61 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,099
|
as i previously said i think its every coder choice to do what he/she wants however smaller/compacted code doesnīt mean is less bloated nor advanced etc.. it just mean each coder add his/her special touch to it. also it doesnīt change the behaviour of the code execution either. using slightly more lines have his advantages specially when you want to debug your code in a better way... sadly debugging is necessary as every single coder in this world canīt write a perfect code and therefore debugging is more than necessary in many, many cases. eitherway is your choice and if you like it i donīt see any problems with that ![]() anyways every coder has different tastes and style so i think that even using the same style coders still have differences.. for example i would use "Switch" here instead: Code:
void mVU_ESADD(microVU* mVU, int recPass)
{
if (recPass == 0)
{
mVUanalyzeEFU2(mVU, _Fs_, 11);
}
if (recPass == 1)
{
int Fs = mVU->regAlloc->allocReg(_Fs_, 0, _X_Y_Z_W);
SSE2_PSHUFD_XMM_to_XMM(xmmPQ, xmmPQ, mVUinfo.writeP ? 0x27 : 0xC6); // Flip xmmPQ to get Valid P instance
mVU_sumXYZ(mVU, xmmPQ, Fs);
SSE2_PSHUFD_XMM_to_XMM(xmmPQ, xmmPQ, mVUinfo.writeP ? 0x27 : 0xC6); // Flip back
mVU->regAlloc->clearNeeded(Fs);
}
if (recPass == 2)
{
mVUlog("ESADD P");
}
}
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 3rd, 2009 at 19:14.. |
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
#62 |
|
代言人
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2006
Location: 應許之地
Posts: 7,056
|
I prefer switch when possible too Easy to read, but switch has potency for logical errors if cases are not well defined. Keys are good examples for switch, in my opinion Code:
/* handle special keys handling. (arrows, etc) */
void arrow_keys ( int a_keys, int x, int y )
{
switch ( a_keys ) {
case GLUT_KEY_UP: /* When Up Arrow Is Pressed...*/
screen.Rotate( Vec3f(ROTATE_VERTICAL,0,0) );
break;
case GLUT_KEY_DOWN: /* When Down Arrow Is Pressed...*/
screen.Rotate( Vec3f(-ROTATE_VERTICAL,0,0) );
break;
case GLUT_KEY_LEFT: /* When Left Arrow Is Pressed...*/
screen.Rotate( Vec3f(0,-ROTATE_HORIZONTAL,0) );
break;
case GLUT_KEY_RIGHT: /* When Right Arrow Is Pressed...*/
screen.Rotate( Vec3f(0,ROTATE_HORIZONTAL,0) );
break;
default:
break;
}
redisplay();
}
__________________
![]() |
|
|
|
|
|
#63 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,099
|
well a good coder should know at least that "break;" is needed on every case otherwise un-wanted code is going to be executed
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
#64 |
|
Registered User
![]() ![]() Join Date: Sep 2006
Location: surrey
Posts: 111
|
Pairing heaps. Code:
import java.util.LinkedList;
public class PairingHeap<E extends Comparable<E>>
{
private E min;
private LinkedList<PairingHeap<E>> heaps;
public PairingHeap(E value)
{
min = value;
}
public PairingHeap<E> insert(E value)
{
PairingHeap<E> h = new PairingHeap<E>(value);
return merge(h);
}
public PairingHeap<E> merge(PairingHeap<E> h)
{
if(h.min.compareTo(min) < 0)
return h.addHeap(this);
else return this.addHeap(h);
}
private PairingHeap<E> addHeap(PairingHeap<E> h)
{
if(heaps == null) heaps = new LinkedList<PairingHeap<E>>();
heaps.add(h);
return this;
}
public E findMin()
{
return min;
}
public void deleteMin()
{
if(heaps == null)
min = null;
else
{
LinkedList<PairingHeap<E>> t = new LinkedList<PairingHeap<E>>();
PairingHeap<E> t2;
PairingHeap<E> t3;
for(int i = 0; i < heaps.size()-1; i+=2)
{
t2 = heaps.get(i);
t3 = heaps.get(i+1);
t2 = t2.merge(t3);
t.add(t2);
}
heaps = t;
}
int i = heaps.size()-1;
int i2 = 0;
E minimum = heaps.get(i2).min;
int minLocation = 0;
while(i > i2)
{
if(heaps.get(i--).min.compareTo(minimum) < 0)
{
minimum = heaps.get(i).min;
minLocation = i;
}
if(heaps.get(i2++).min.compareTo(minimum) < 0)
{
minimum = heaps.get(i2).min;
minLocation = i2;
}
}
min = minimum;
PairingHeap<E> minHeap = heaps.get(minLocation);
heaps.remove(minLocation);
heaps.addAll(minHeap.heaps);
}
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("min: ");
sb.append(min.toString());
if(heaps == null)
sb.append("\nHeaps: null");
else
{
for(int i = 0; i < heaps.size(); i++)
{
sb.append("\nHeap:\n{\n");
sb.append(heaps.get(i).toString());
sb.append("\n}\n");
}
}
return sb.toString();
}
}
|
|
|
|
|
|
#65 |
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
switches are useful when you have alot of well defined cases. when you have a limited number of cases, they usually take up more lines of code. switches also look very ugly if you need to declare variables within the case statements. you need to add brackets to the case to give the variables correct scope, so you end up with something that looks very unsymmetrical. my use of macros in the code i posted earlier gave each emulated opcode a definite structure, promoting consistency. Code:
mVUop(someOpcode) {
pass1 {}
pass2 {}
pass3 {}
}
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
|
|
|
|
|
#66 |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,099
|
That is actually the most important thing ....... however other coders may not share your points of view in this case as maybe some of us doesnīt consider such practice as more productive nor make your code more advanced... but hey we should be happy not everyone thinks the same
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
#67 | |
|
これはバタスです
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 6,331
|
Quote:
). Meh, eventually you get used to it.
__________________
CPU: Intel Core 2 Quad Q9450 Mobo: Intel DX48BT2 Memory: 4096 MB PC10600 DDR3 Videocard: PNY Geforce 9800 GX2 Soundcard: On-board SigmaTel High Definition Audio Hard drive: 120 GB OCZ RevoDrive PCI-E SSD & 1 TB Hitachi Optical drive: LG GGW-H20L (2x BD-R DL) PSU: Nexus 1000 Watt PSU OS: Microsoft Windows 7 Ultimate (64-bit) Proud millionaire folder of the NGEmu folding team |
|
|
|
|
|
|
#68 | |
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
some would argue pointers make stuff uglier though. no garbage collecter is arguably uglier too (but used wisely, you can make stuff look cleaner when you need to explicitly delete class objects; too lazy to give an example though) what i noticed about your code is that you use /* */, for your single line comments. i think thats too hard to type for every comment, so i always use // for my single line ones. only time i really use /**/ is when i'm commenting out big chunks of code to test something. or if i need to comment something in a multi-line macro or within a line statement.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
|
|
|
|
|
|
#69 | |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
Quote:
|
|
|
|
|
|
|
#70 | |
|
Crazy GFX coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,099
|
Quote:
__________________
![]() Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 Last edited by @ruantec; December 3rd, 2009 at 21:46.. |
|
|
|
|
|
|
#71 |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Pittsburgh, US. Previously in Mexico City
Posts: 7,160
|
You also have to consider that your teacher, or the poor TA that will have to check your HW, also has to check the HW of God knows how many students out there. If they didn't ask for a standarized and easy to read way of understanding your code, and everyone programmed in whatever hectic way they preferred, they would invest much more time than what they are investing already.
__________________
|
|
|
|
|
|
#72 |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
yeah. bloated code is different from code that is overly verbose. if you use more lines to express the exact equivalent statements, that is not code bloat. and sorry for correcting your grammar @ruantec. its not an attack on you, but red squiggly lines really bother me.
|
|
|
|
|
|
#73 | ||||
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
Quote:
my teacher even said to not make stuff harder on him. if i was a professor and had to grade a lot of papers, i probably wouldn't want to be bothered with too complex code. Quote:
i'm not talking about just the formatting stuff; but rather using a lot more code statements to accomplish the same task is just sloppy. there's plenty of parts of pcsx2 that are just a mess of slop, because some coders just didn't know how to code concise, structured, and to-the-point. its usually a sign that they had no plan, or they didn't know what they were doing. according to wikipedia: Quote:
being overly verbose falls into 'unnecessarily long'. i do not have objections to longer smarter algorithms however. exactly what i consider bloat depends on the situation.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
||||
|
|
|
|
|
#74 | |
|
代言人
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2006
Location: 應許之地
Posts: 7,056
|
Quote:
Allocating memory myself helps me to develop good habit of keeping things clean regardless of the existence of the garbage collector. Garbage collector should be there as an aid and not something to rely on. For commenting, I just type what ever I want, then ctrl-k, ctrl-c to comment my entire thing and ctrl-k, ctrl-u to uncomment the entire thing.
__________________
![]() |
|
|
|
|
|
|
#75 | |
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
not having a GC also helps you understand how memory allocation works. when you code in languages with a CG, and never have experienced a language with coder-controlled memory management; you may not get the full idea of how your memory is being used. stuff like that is why i've expressed that any good coder eventually needs to learn mid-level languages like c/c++; or else they will not fully understand certain concepts (or it will be very difficult to do so). it reminds me of something i read years ago how some programmer (don't remember who, but i think he was some well-known programmer/professor), was arguing that languages like visual basic are spoiling and teaching bad programming habits to new programmers. technically it has some truth; but i think when you start out, its best to start with something easy. then you gradually move on to more difficult languages as you learn more.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
|
|
|
|
|
|
#76 | |
|
Registered User
![]() ![]() ![]() ![]() Join Date: Apr 2007
Location: indiana
Posts: 694
|
Quote:
|
|
|
|
|
|
|
#77 |
|
代言人
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2006
Location: 應許之地
Posts: 7,056
|
format plays a huge role in readability as well Code:
/* Checks the color intensity bounds: {0} <= {[i]} <= {1} */
void Ray::ColorCheck ( Vec3f& color ) const
{
if ( color.r() > 1) color.Set( 1 ,color.g() ,color.b() );
if ( color.g() > 1) color.Set( color.r() ,1 ,color.b() );
if ( color.b() > 1) color.Set( color.r() ,color.g() ,1 );
if ( color.r() < 0) color.Set( 0 ,color.g() ,color.b() );
if ( color.g() < 0) color.Set( color.r() ,0 ,color.b() );
if ( color.b() < 0) color.Set( color.r() ,color.g() ,0 );
}
I know a for loop would work here too now, but apparently I didn't at the time @@" I'm pulling things out from the raytracer I coded last year btw.
__________________
![]() |
|
|
|
|
|
#78 | |
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
verbose means "containing more words than necessary". being overly verbose is essentially 1 of the criteria (arguably the most definitive) for what 'code bloat' is. what enhances readability is subjective to the reader. for me its seeing more on the screen at once, for others its apparently seeing less since they like to spread out their code like writing a double spaced college essay. and no-one said anything about which code makes you look smarter; that's a totally irrelevant comment.
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() |
|
|
|
|
|
|
#79 |
|
代言人
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2006
Location: 應許之地
Posts: 7,056
|
I do a lot of chunking, I group codes together using space to improve readability. Code:
aaaaaaaaaa aaaaaaaaaa aaaaaa a a aaaa bbbbbbbb bbb bb c cc cc cc cccc
__________________
![]() |
|
|
|
|
|
#80 | ||
|
You're already dead...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
|
Quote:
i also spend time arranging code like that. when i code i kindoff feel like i'm playing tetris; aligning all the statements into blocks that look good. i hate it when i can't come-up with something that looks well-aligned (due to the odd code statements) xD. Quote:
__________________
"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein check out my blog ![]() Last edited by cottonvibes; December 4th, 2009 at 03:05.. Reason: Automerged Doublepost |
||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|