November 13th, 2019, 10:49
Posts: 3,008
Threads: 27
Joined: Jun 2012
(November 6th, 2019, 15:36)Charriu Wrote: Everytime there's a whitespace the compiler knows that this is a new code element. By the way this also the same reason
There's another topic about writing style, but I will leave it for next time. ![wink wink](https://www.realmsbeyond.net/forums/images/smilies/wink2.gif)
Same reason what?!?!
There is no way to peace. Peace is the way.
November 13th, 2019, 14:35
(This post was last modified: November 13th, 2019, 14:36 by Charriu.)
Posts: 7,602
Threads: 75
Joined: Jan 2018
Sorry for that, naufragar. That sentence should have been deleted.
Digging into the code
Fractal (Actual name: CvFractal) 417 lines
For once this is actually what you expect. This class helps in creating Fractal maps, you know the map type Fractal. Some of the calculations during map creation were most likely a bit performance intensive, so the developers outsourced this code to the C++ code. The reason for that is that C++ is able to micromanage those performance issues better then a high level programming language such as python.
You remember back at the city of DiploParameters that there is another reason for the "crazy" writing styles in programming languages. These styles are called Case Styles and there are quite a few:
- camelCase
- PascalCase
- snake_case
- kebab-case
- lowercase
- UPPERCASE
- Capitalizedcase
Depending on you programming language there are more or less restrictions of which writing style you use, but normally you are not limited to one style. The main reason - and mostly the only one - for using these styles is to quickly differentiate between, which names belong to classes, methods or variables. Take this snippet of code from the CvFractal class:
Code: int CvFractal::getHeight(int iX, int iY)
{
int iErrX;
int iErrY;
int iSum;
int iHeight;
int iLowX;
int iLowY;
FAssertMsg(0 <= iX && iX < m_iXs, "iX out of range");
FAssertMsg(0 <= iY && iY < m_iYs, "iY out of range");
iLowX = ((m_iXInc * iX) / FLOAT_PRECISION);
...
Because I know the conventions of the writing style, it is very easy for me to immediately notice what is what. For example:
- I immediately know that CvFractal and FAssertMsg are classes because all classes are written in PascalCase
- I know that iHeight and iLowX are local variables (meaning belonging only to this method). I know that because they are written in camelCase
- I know that m_iXs and m_iXInc are member variable of the CvFractal class (meaning belonging only to this class). That I know because they are written in camelCase and begin with an m_
- I know that FLOAT_PRECISION is a constant variable, because it's written in snake_case and UPPERCASE
- Lastly I know that getHeight is a method, because it is written in camelCase followed by braces.
Using different writing styles therefore increases the readability of code.
November 13th, 2019, 15:13
Posts: 5,323
Threads: 22
Joined: Feb 2012
(November 13th, 2019, 14:35)Charriu Wrote: Sorry for that, naufragar. That sentence should have been deleted.
Digging into the code
Fractal (Actual name: CvFractal) 417 lines
For once this is actually what you expect. This class helps in creating Fractal maps, you know the map type Fractal. Some of the calculations during map creation were most likely a bit performance intensive, so the developers outsourced this code to the C++ code. The reason for that is that C++ is able to micromanage those performance issues better then a high level programming language such as python.
You remember back at the city of DiploParameters that there is another reason for the "crazy" writing styles in programming languages. These styles are called Case Styles and there are quite a few:
- camelCase
- PascalCase
- snake_case
- kebab-case
- lowercase
- UPPERCASE
- Capitalizedcase
Depending on you programming language there are more or less restrictions of which writing style you use, but normally you are not limited to one style. The main reason - and mostly the only one - for using these styles is to quickly differentiate between, which names belong to classes, methods or variables. Take this snippet of code from the CvFractal class:
Code: int CvFractal::getHeight(int iX, int iY)
{
int iErrX;
int iErrY;
int iSum;
int iHeight;
int iLowX;
int iLowY;
FAssertMsg(0 <= iX && iX < m_iXs, "iX out of range");
FAssertMsg(0 <= iY && iY < m_iYs, "iY out of range");
iLowX = ((m_iXInc * iX) / FLOAT_PRECISION);
...
Because I know the conventions of the writing style, it is very easy for me to immediately notice what is what. For example:
- I immediately know that CvFractal and FAssertMsg are classes because all classes are written in PascalCase
- I know that iHeight and iLowX are local variables (meaning belonging only to this method). I know that because they are written in camelCase
- I know that m_iXs and m_iXInc are member variable of the CvFractal class (meaning belonging only to this class). That I know because they are written in camelCase and begin with an m_
- I know that FLOAT_PRECISION is a constant variable, because it's written in snake_case and UPPERCASE
- Lastly I know that getHeight is a method, because it is written in camelCase followed by braces.
Using different writing styles therefore increases the readability of code.
I've been doing software development since 1990 and this is the first I've heard of snake_case or kebab-case. I love learning new stuff ; ![wink wink](https://www.realmsbeyond.net/forums/images/smilies/wink2.gif) Your explanations are pretty good, btw. I approve the "RB Guide to Software Engineering"
Completed: PBEM 34g (W), 36 , 35 , 5o, 34s, 5p, 42, 48 and PB 9, 18, 27, 57
Current: PB 52. Boudicca of Maya
November 13th, 2019, 15:19
(This post was last modified: November 13th, 2019, 15:23 by Charriu.)
Posts: 7,602
Threads: 75
Joined: Jan 2018
Thanks, I really appreciate that, especially if it comes from somebody, who has more experience in software development. ![smile smile](https://www.realmsbeyond.net/forums/images/smilies/smile2.gif) I'm only working in the field since 2010.
EDIT: Oh and to clarify for everybody else:
Quote:I love learning new stuff
Is one of the foundational principles in software development. You are constantly learning new stuff in software development and this won't stop till your retirement.
November 13th, 2019, 15:46
Posts: 2,110
Threads: 12
Joined: Oct 2015
(November 13th, 2019, 15:13)AutomatedTeller Wrote: I've been doing software development since 1990 and this is the first I've heard of snake_case or kebab-case. I love learning new stuff ; Your explanations are pretty good, btw. I approve the "RB Guide to Software Engineering"
(November 13th, 2019, 15:19)Charriu Wrote: Thanks, I really appreciate that, especially if it comes from somebody, who has more experience in software development. I'm only working in the field since 2010.
Quote:I love learning new stuff
Is one of the foundational principles in software development. You are constantly learning new stuff in software development and this won't stop till your retirement.
Wow, 1990. I thought I was on ... um ... experienced side for this site (IRL) and I've only been doing software dev since 1997 (well, professionally). But absolutely, learning new stuff is one of the nice things about the job.
And yeah, I haven't had anything much to add to Charriu's posts yet, and certainly nothing to disagree with.
It may have looked easy, but that is because it was done correctly - Brian Moore
November 15th, 2019, 04:53
Posts: 8,786
Threads: 40
Joined: Aug 2012
I'm hoping to use Charriu's programming 101 to get a job at some point...
Turn 62
Things are getting a bit hairy now. EventReporter survives and should get reinforcements before any other barbarians can hit it. DiploParameters faces a 92HP Combat 1 warrior though (did it kill Pindicator's scout?) The odds should be 95% in our favour, but that's still 1/20 that we lose the city. The chariot is one turn late to do anything about that, but just in time to stop the second (!) warrior if the first doesn't ruin our game. We debated leaving the worker out as a decoy, but decided the risk was better than definitely losing a quarter of our workforce.
If DiploParameters survives then we've produced the exact optimal number of units to sustain our expansion. ![smile smile](https://www.realmsbeyond.net/forums/images/smilies/smile2.gif) If it falls then we're idiots who took too many chances...
Demos and power. Still number one, just.
Completed: RB Demogame - Gillette, PBEM46, Pitboss 13, Pitboss 18, Pitboss 30, Pitboss 31, Pitboss 38, Pitboss 42, Pitboss 46, Pitboss 52 (Pindicator's game), Pitboss 57
In progress: Rimworld
November 16th, 2019, 03:26
Posts: 8,786
Threads: 40
Joined: Aug 2012
Pbspy is telling me that we're idiots. I can't face logging in to see... The worst bit is the settler that was due in a couple of turns almost makes the city worth two cities.
At least the score decrease was covered by a pop increase so our rivals won't realise.
Completed: RB Demogame - Gillette, PBEM46, Pitboss 13, Pitboss 18, Pitboss 30, Pitboss 31, Pitboss 38, Pitboss 42, Pitboss 46, Pitboss 52 (Pindicator's game), Pitboss 57
In progress: Rimworld
November 16th, 2019, 06:07
Posts: 8,786
Threads: 40
Joined: Aug 2012
Turn 63
Well it could have been worse, the barb won at 3%, but our chariot captures back flawlessly and should have >99% defending against the next warrior. To add compliment to injury the terrace survived both captures so we're really only down one Quechua, one pop and 50 hammers in a settler (essentially that's our eighth city, so the snowball is slowed but not melted). It doesn't feel like a reason to celebrate, but we're not as badly damaged as we'd assumed.
Demos and power. Anyone else who is tracking city founding will assume with that capture that we're on 7 cities now. That's pretty funny given how we're actually feeling.
Completed: RB Demogame - Gillette, PBEM46, Pitboss 13, Pitboss 18, Pitboss 30, Pitboss 31, Pitboss 38, Pitboss 42, Pitboss 46, Pitboss 52 (Pindicator's game), Pitboss 57
In progress: Rimworld
November 16th, 2019, 13:15
Posts: 7,602
Threads: 75
Joined: Jan 2018
(November 16th, 2019, 06:07)Old Harry Wrote: Turn 63
Anyone else who is tracking city founding will assume with that capture that we're on 7 cities now. That's pretty funny given how we're actually feeling.
I wonder if I can keep up that illusion by writing just after you, like I did after every other city founding.
November 17th, 2019, 05:24
Posts: 8,786
Threads: 40
Joined: Aug 2012
Turn 64
Our chariot won flawlessly (it gets the +25% defence against barbs, which helped) and Pindicator got the event where his unit got healed. I'm pretty sure Pindi settled on the highlighted tile, so we should get a trade connection as soon as we settle our peninsula city. Whether we offer open borders is a tricky question. We'll have our overseas city already, so it'll only give him the economic benefit, but it allows us to scout him and make sure he's got no designs on attacking us.
Demos and power. We got graphs on Elkad so all of those are included.
Completed: RB Demogame - Gillette, PBEM46, Pitboss 13, Pitboss 18, Pitboss 30, Pitboss 31, Pitboss 38, Pitboss 42, Pitboss 46, Pitboss 52 (Pindicator's game), Pitboss 57
In progress: Rimworld
|