• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

King of Men

Resident Opportunist
82 Badges
Mar 14, 2002
7.642
78
ynglingasaga.wordpress.com
  • Cities: Skylines - After Dark
  • Victoria: Revolutions
  • Semper Fi
  • Victoria 2
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • 500k Club
  • Cities: Skylines
  • Crusader Kings II: Holy Knight (pre-order)
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mare Nostrum
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Hearts of Iron IV: Field Marshal
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: No Step Back
  • Divine Wind
  • Hearts of Iron II: Armageddon
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Deus Vult
  • Europa Universalis III
  • Arsenal of Democracy
  • Europa Universalis IV
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • For the Motherland
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Heir to the Throne
  • Europa Universalis III Complete
It is sometimes claimed that "Effect X is just two lines of code, surely Johan can do that easily." I thought I'd take a moment to pontificate on just what can be involved in two lines of code. Those of you who are programmers yourself can either nod and chuckle ruefully, or just ignore me; the rest of you 'orrible lot, sit up straight and pay attention!

First, of course, there's the question of just where those lines of code should be added. A game on the scale of CK contains humongous amounts of code; it is just plain impossible to keep in your head what all of it, or even a large part of it, does. Especially when coming back after a couple of months of coding something else. And if the part you are modifying was coded by someone else, finding what you want to modify can be a truly serious pain in the butt. Of course, all programmers comment their code so you can easily figure out what a given line does. Hah.

Searching through several thousand lines of source code (assuming you can narrow it down that much!) to find the particular subroutine you want can be a real pain. If you are lucky, it was given a descriptive name and good commenting. If you are several patches into the release cycle, the subroutine might do something entirely different from what its name suggests, but the name couldn't be changed because other parts of the code would have to be changed also - this sort of thing can ripple into a week of hunting down all the places that need to be changed. And if the coder who programmed it originally was in a hurry, or thinking about his girlfriend, or had one too many beers the night before - good luck with the descriptive name.

Assuming you can clear this hurdle, there's the actual programming. Here is where the "it's only two lines" has something going for it. Adding two lines really is pretty quick, once you've figured out what variable you need to change - and again, pray for descriptive names and good comments! Of course, you want to be sure you're not changing anything you need further down the subroutine, much less a global that isn't reset. (And Johan, that 'Initialising Globals' part of starting CK takes forever - bad designer, no cookie!) If you created an object, be sure to release the memory for it, or you'll create a subtle and elusive crashbug that won't manifest until the game has been played for quite some time, enough to call that particular code many times over and use up a lot of memory.

So, we've coded. Done, right? Oh no! Now we need to compile. It is to be hoped that your code is nice and modular, and changing one part of it only means recompiling one or two files. Bwah-hah-hah. In reality, as projects get big and crufty, the dependencies stretch out like an SP player grabbing the good bits of Europe. You are certainly looking at a coffee break's worth of compiling, which can easily stretch to half an hour. If you're in a central part of the code, overnight is not unheard of. You had better hope you didn't use the . operator when you meant ->, or some similarly trivial mistake.

As errors go, though, that kind of thing is pretty easy to catch - even a compiler, not exactly the most subtle of the beasts of the field, can do it. Logic errors are much more difficult. Suppose you forgot a de-reference, and are hitting the character instead of the character's father? And, incidentally, did you remember to test that the character's father actually exists? If not, you have a nice little crashbug on your hands. Better check that your test-of-existence actually tests for the existence of your target, and not his grandmother's uncle.

So you need to test your program. That takes time. At the very least, enough time to load up CK, set up the situation you want, and trigger the event. Then you need to check that it does what it's supposed to. In various circumstances, to be sure. Does it work with Moslems? With unmarried people? With bastards? It's surprising what kind of thing can make a difference in a vast project like CK. All kinds of things are coupled to each other and do unexpected things.

So you've tested the code, and it doesn't crash the game. At least not immediately. Let's run for a few hundred years, just to see if we've introduced any nice subtle memory leaks or other long-term effects.

Now, what about gameplay? Does it unbalance the character? Make him unreasonably powerful? Does it need to be tweaked? Better email your loyal legions of beta testers. It'll take a day or two for them to reply, of course.

Most important of all, is your change fun? Do howls of protest go up every time you mention it? Oh dear, better change it back, or at least nerf it a little. Now, where was that piece of code, again?



Only two lines. Sure.
 

unmerged(6777)

Field Marshal
Dec 10, 2001
12.470
5
That's a pretty good summary, although there are often some other things that come into it...

Let's take a simple example, like when someone asks for a claim to expire in 100 years. Hm...well claims don't have an expiry date at the moment so it would suddenly become necessary to track when they were created. This then simply entails creating a new tag "claim_date" right? Wrong.

You would need to alter your save game code to store the new variable along with each claim, plus you'd need to add a section to your game load routine to pick it back up again.

And of course people would be a bit pissed off if there wasn't a handy tooltip telling you when that claim expires, right? So there's some more code to calculate this and then set up the necessary string to spit it out in a visually pleasing manner.

Plus, of course, the code to do the check as to when the claim was created and how long ago that was so you know when to make it expire.

Assuming you did all of that, you're laughing, right?

Nope...now you're checking expiry of claims -- thousands of them! -- which means that you probably want to test out what that extra code is doing to the game play in trms of bogging down the processor with all sorts of extra math (not to mention that since all that data must be live you're hogging more of your RAM to make it available).

Etc.


* * * *

King of Men said:
(And Johan, that 'Initialising Globals' part of starting CK takes forever - bad designer, no cookie!)

It's worth pointing out that a large portion of the delay when first loading the game and then again when loading the scenario is actually the time required to compile and error-check the files that aren't pre-compiled...eg. all of the event files, data files, etc. (anything with a csv or txt extension has to be compiled at runtime). This is the intended trade-off between speed of getting up and running quickly versus allowing the game to be moddable.

And of course all the graphics have to be loaded into memory too, which takes a while.

:)
 

King of Men

Resident Opportunist
82 Badges
Mar 14, 2002
7.642
78
ynglingasaga.wordpress.com
  • Cities: Skylines - After Dark
  • Victoria: Revolutions
  • Semper Fi
  • Victoria 2
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • 500k Club
  • Cities: Skylines
  • Crusader Kings II: Holy Knight (pre-order)
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mare Nostrum
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Hearts of Iron IV: Field Marshal
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: No Step Back
  • Divine Wind
  • Hearts of Iron II: Armageddon
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Deus Vult
  • Europa Universalis III
  • Arsenal of Democracy
  • Europa Universalis IV
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • For the Motherland
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Heir to the Throne
  • Europa Universalis III Complete
MrT, you are of course entirely correct; however, what you say applies to reasonably large coding projects. I was addressing myself to complaints of the form "You just need to check X at the start of the Y-routine, surely it can't be that difficult?" As for the bit about globals, I wasn't objecting so much to the time, as to the use of globals at all. As a proper OO freak, I believe everything can and should be encapsulated in good classes with no quick way to initialise their internals. Whether or not that adds five minutes to the load time. Performance is not as important as Purity of Design! Globals are an invention of the godless commies, sapping our precious codily fluids.

Byakhiam, I know Finns are supposed to be taciturn :p , but outside those forests, it's often considered a good thing to explain why something is difficult.
 

unmerged(21937)

Your Industrial Friend
Nov 15, 2003
9.557
1
King of Men said:
Byakhiam, I know Finns are supposed to be taciturn :p , but outside those forests, it's often considered a good thing to explain why something is difficult.

Surely, but with such long posts, it's better to have simple versions for the lazy or hurried ones. :D
 

SJG

Temporarily Uninspired
12 Badges
Mar 18, 2003
1.195
0
  • Crusader Kings II
  • Europa Universalis III Complete
  • Europa Universalis IV
  • Hearts of Iron III
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis: Rome
  • Victoria 2
  • 500k Club
  • Europa Universalis IV: Pre-order
  • Europa Universalis: Rome Collectors Edition
  • Stellaris Sign-up
King of Men said:
As a proper OO freak, I believe everything can and should be encapsulated in good classes with no quick way to initialise their internals.
Still a student, eh? Such religious beliefs rarely survive long in the Real World. :)

As to the "two lines of code" thing, it is entirely possible to make a two line change in a few minutes and test it in a few more but, and it's a fairly big but, a great deal of knowledge of the internal workings and structure of the code must be known before the pronouncement can be made with any certainty.

As such the only person who could make such a pronouncement, if I understand correctly how CK is maintained, would be Johan.

Most of the rest of the problems you have described are almost completely irrelevant to a "two lines of code" problem. If even half of the problems you describe are possible (and the programmer should know whether they're possible) then it's certainly more than a "two lines of code" problem.

So yeah, any code change involves more than people might think but a "two lines of code" problem is not as much as you've painted. The problem is that people assume something is a "two lines of code" problem. In most cases without knowing the code intimately it is impossible to say how large the change could be.

On the other hand I'm all for making programming sound really difficult, that way we'll see less clueless idiots trying it and making the rest of our lives difficult. And maybe you could talk to my boss about a payrise. :)

I once knew someone who'd been a programmer for three years and started every method "public static void main(String[] args)". For god's sake, you've been programming in VB for six months now, get a clue!
 

King of Men

Resident Opportunist
82 Badges
Mar 14, 2002
7.642
78
ynglingasaga.wordpress.com
  • Cities: Skylines - After Dark
  • Victoria: Revolutions
  • Semper Fi
  • Victoria 2
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • 500k Club
  • Cities: Skylines
  • Crusader Kings II: Holy Knight (pre-order)
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Mare Nostrum
  • Stellaris
  • Stellaris: Galaxy Edition
  • Stellaris: Galaxy Edition
  • Hearts of Iron IV Sign-up
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Hearts of Iron IV: Field Marshal
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: No Step Back
  • Divine Wind
  • Hearts of Iron II: Armageddon
  • Crusader Kings II
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Deus Vult
  • Europa Universalis III
  • Arsenal of Democracy
  • Europa Universalis IV
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • For the Motherland
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Heir to the Throne
  • Europa Universalis III Complete
I am indeed a student, but I had my tongue stuck just a little into my cheek when posting about the purity of OO. As for the rest, certainly two lines of code can be trivial in the best case, but you rarely get best cases in real life. I just wanted to point out what is involved other than actually coding, for all those people who have never coded Hello World in their life.
 

unmerged(6777)

Field Marshal
Dec 10, 2001
12.470
5
heh

I coded a little two-liner today to show Johan what I meant about something. Some 80 lines later... :p
 

Duuk

Reformed Badboy
23 Badges
Oct 16, 2001
6.137
1.402
  • Majesty 2
  • Europa Universalis III: Collection
  • Crusader Kings II: Holy Knight (pre-order)
  • Cities: Skylines
  • 500k Club
  • Victoria 2: Heart of Darkness
  • Victoria 2: A House Divided
  • Victoria 2
  • Rome Gold
  • Victoria: Revolutions
  • Europa Universalis III Complete
  • Majesty 2 Collection
  • Hearts of Iron Anthology
  • Europa Universalis III Complete
  • Heir to the Throne
  • Europa Universalis III Complete
  • Europa Universalis III
  • Deus Vult
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II
MrT said:
heh

I coded a little two-liner today to show Johan what I meant about something. Some 80 lines later... :p

My issue always seem to be "I'll just add this one line here..." which causes me to look how I wrote the original function, realizing I must have been drunk, overly tired, sexually frustrated, and possibly delusional at the time.

So now a "one line fix" has resulted in my massive recode of an entire section of the game (usually resulting in pages of code being added, removed, modified, and changed with comments like /* I screwed this up badly last time. */ added in).

:D
 

unmerged(6777)

Field Marshal
Dec 10, 2001
12.470
5
Havard said:
I would assume it's C++
Yup. :)

Duuk: that description tends to summarize my coding at times too. :D