create account

Swinging the Code Axe by ravonn

View this thread on: hive.blogpeakd.comecency.com
· @ravonn · (edited)
$14.96
Swinging the Code Axe
As a code base ages it is natural for its [SLOC count](https://en.wikipedia.org/wiki/Source_lines_of_code) to increase or, at best, not move as more functionality is added. This is inevitable but also perfectly fine. If we look at the [Gridcoin source tree](https://github.com/gridcoin/Gridcoin-Research) we can see that even though a lot of things have been added, much of the obsolete has been removed which is why the graph is sort of flat up until The Great Code Removal of 2017:

<center><img src="https://steemitimages.com/DQmZ6TvByjm9tEUSRC7cLDadJH4yoggdB867WedT3c3vL7c/chart.png"/></center>

Those who have followed me on IRC or [Slack](https://teamgridcoin.slack.com) know that I have an almost sickly obsession with code removal. To me, removing dead, or zombie code is the easiest and most relaxing form of [refactoring](https://en.wikipedia.org/wiki/Code_refactoring) and offers instant gratification with almost zero risk involved. Occasionally the worst thing that can happen happens; you removed code which is used on another platform and you just add it back. This removal has become a part of my daily routine and is something I do when I'm too tired to think but want to do _something_.


Code complexity
===============
Every line added to a program introduces complexity but in return you gain functionality. Inversly, every line removed removes the functionality but also reduces complexity, right? It seems pretty straight forward but there is an exception to this though. I would argue that removing all _references_ to a piece of code while keeping the piece of code itself (thus making it a zombie) actually increases the overall complexity of the code base in addition to what the piece of code adds in itself. What used to be a useful member of society is now an ambiguous blob of text. The piece of code now imposes questions to the reader.

- Why is this still here if nobody uses it?
- Should I use this or is there something wrong with it?
- Is the intention to use it later on?
- Who the hell authorized this?

In order to understand why the code is unused you suddenly have to see a much greater picture and be aware of historical decisions. You have to move towards becoming an expert when you really shouldn't have to.

Another thing to keep in mind is the complexity perspective from a new viewer. The more code you have to absorb and consider, the harder it becomes to understand the flow.

Build times?
========
This is probably the most obvious reason for code removal.

> More code = more lines to compile = longer build times.

Since we have undergone so many removals you would expect to see an equal drop in build times. The reality is that the sheer amount of source in c/cpp files actually has less of an increase on build times than you might think. Sure, a lot of code increases the times, but a small reduction doesn't do much which becomes apparent when you add it to the chart:

<center><img src="https://steemitimages.com/DQmcVBUzwHJdHDN1SRTWNQfEFqDvPKobPpHfPszsGGxK1t1/chart%20(1).png"/></center>

Compilers are usually quite fast so removing 20 lines of code is not going to have a noticable impact. The drop in 3.5.8.9 comes from [improved header discipline](https://github.com/gridcoin/Gridcoin-Research/commit/d2bd2ae970e72a5c1627f3374c3b3932473087cf) which does much, much more for the build speeds. Before that all versions compiled with a difference of +/- 1 second.

Maintenance
===========
It may sound counter intuitive but unused code has to be maintained almost as much as live code, except for refactoring for performance or readability. Every time you do a refactoring task which involves the dead code you have to make sure it still compiles, that its unit tests are working and that its documentation is still valid. If the code you refactor does not add value you are doing the work for nothing.

Conclusions
===========
I am not alone in this crusade. [ifoggz](https://github.com/Foggyx420) and [TomΓ‘Ε‘ Brada](https://github.com/tomasbrod) have removed both unused RPC commands and a slew of obsolete Proof-of-Work code. The result of that is the reason for the massive code dip in the development branch. As a result we now have ~5000 fewer lines. That is code we never have to see again, never have to consider and never have to explain. It's a great time to be alive.
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorravonn
permlinkswinging-the-code-axe
categorygridcoin
json_metadata{"tags":["gridcoin","code","refactoring","beyondbitcoin"],"image":["https://steemitimages.com/DQmZ6TvByjm9tEUSRC7cLDadJH4yoggdB867WedT3c3vL7c/chart.png","https://steemitimages.com/DQmcVBUzwHJdHDN1SRTWNQfEFqDvPKobPpHfPszsGGxK1t1/chart%20(1).png"],"links":["https://en.wikipedia.org/wiki/Source_lines_of_code","https://github.com/gridcoin/Gridcoin-Research","https://teamgridcoin.slack.com","https://en.wikipedia.org/wiki/Code_refactoring","https://github.com/gridcoin/Gridcoin-Research/commit/d2bd2ae970e72a5c1627f3374c3b3932473087cf","https://github.com/Foggyx420","https://github.com/tomasbrod"],"app":"steemit/0.1","format":"markdown"}
created2017-08-17 13:06:36
last_update2017-08-21 05:18:54
depth0
children10
last_payout2017-08-24 13:06:36
cashout_time1969-12-31 23:59:59
total_payout_value13.092 HBD
curator_payout_value1.867 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,339
author_reputation1,551,172,951,761
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id12,082,770
net_rshares4,259,228,758,590
author_curate_reward""
vote details (38)
@bullshark ·
You are doing an excellent job @ravonn cleaning up the code base. There's nothing worse than wading through spaghetti, especially if it's a bit rotten :-)

Looking forward to the next release with the V8 staking kernel and TheCharalatans depends build system.
πŸ‘  
properties (23)
authorbullshark
permlinkre-ravonn-swinging-the-code-axe-20170817t203638750z
categorygridcoin
json_metadata{"tags":["gridcoin"],"users":["ravonn"],"app":"steemit/0.1"}
created2017-08-17 20:36:36
last_update2017-08-17 20:36:36
depth1
children0
last_payout2017-08-24 20:36:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length259
author_reputation325,035,457,007
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,118,195
net_rshares2,709,832,780
author_curate_reward""
vote details (1)
@captain-hammer ·
This type of work is just as vital as adding new features.  Right up there with adding more unit tests and making sure the code coverage is up there.  The outside world never sees this type of work, but I assure you it should be applauded and encouraged as much as possible.  Well done, team!
πŸ‘  
properties (23)
authorcaptain-hammer
permlinkre-ravonn-swinging-the-code-axe-20170817t184139859z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 18:41:39
last_update2017-08-17 18:41:39
depth1
children0
last_payout2017-08-24 18:41:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length292
author_reputation42,165,048,864
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,110,261
net_rshares435,925,381
author_curate_reward""
vote details (1)
@dtbahoney ·
This is a really interesting peek behind the scenes. Thanks for this
properties (22)
authordtbahoney
permlinkre-ravonn-swinging-the-code-axe-20170817t191044660z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 19:10:42
last_update2017-08-17 19:10:42
depth1
children0
last_payout2017-08-24 19:10:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length68
author_reputation84,062,481,578
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,112,232
net_rshares0
@jefpatat ·
$0.02
Zombie code (e.g. unreferenced code) should impact compile time marginally since it will be the first to be optimized away. The most important reason to remove is what I refer to as "Write code for people, not for computers". Readability, being able to follow/understanding the code is very important. Header discipline has often a great influence on compile time, certainly when those headers contain implementation.

Glad you were able to do some massive refactoring. Maintaining a good code base is often two steps forward, one step back.

You got me interested to take a look at it. (maybe involved if in need of support)
πŸ‘  
properties (23)
authorjefpatat
permlinkre-ravonn-swinging-the-code-axe-20170817t150026212z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 15:00:21
last_update2017-08-17 15:00:21
depth1
children1
last_payout2017-08-24 15:00:21
cashout_time1969-12-31 23:59:59
total_payout_value0.018 HBD
curator_payout_value0.005 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length625
author_reputation26,609,526,234,408
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,092,662
net_rshares7,077,413,417
author_curate_reward""
vote details (1)
@ravonn ·
$0.22
Absolutely! Join us on Slack in #development. There is lots of activity these days and we need all the help we can get.
πŸ‘  
properties (23)
authorravonn
permlinkre-jefpatat-re-ravonn-swinging-the-code-axe-20170817t150325720z
categorygridcoin
json_metadata{"tags":["development","gridcoin"],"app":"steemit/0.1"}
created2017-08-17 15:03:27
last_update2017-08-17 15:03:27
depth2
children0
last_payout2017-08-24 15:03:27
cashout_time1969-12-31 23:59:59
total_payout_value0.168 HBD
curator_payout_value0.055 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length119
author_reputation1,551,172,951,761
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,092,951
net_rshares64,172,526,013
author_curate_reward""
vote details (1)
@saidulakbar ·
I really like your post, I will wait for the next posting
πŸ‘Ž  ,
properties (23)
authorsaidulakbar
permlinkre-ravonn-swinging-the-code-axe-20170817t142130100z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 14:21:42
last_update2017-08-17 14:21:42
depth1
children0
last_payout2017-08-24 14:21:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length57
author_reputation2,723,254,609,795
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,089,245
net_rshares-146,334,871,392
author_curate_reward""
vote details (2)
@sc-steemit ·
$4.64
# Great work guys!
I did know you where removing code and reducing the overall zombie code, but that the build times where that drastically decreased in a previous bild **I did not know**. 

You keep it simple, precise and don't wander of from the topic of the post, which is code refactoring and build times. And some very descriptive and relevant graphs, love it.

#### Just what I expect from a post from a developer πŸ‘

Looking forward to more exiting topics from the inside πŸ€“
πŸ‘  , , , , , , , , , , ,
properties (23)
authorsc-steemit
permlinkre-ravonn-swinging-the-code-axe-20170817t133535535z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 13:35:51
last_update2017-08-17 13:35:51
depth1
children2
last_payout2017-08-24 13:35:51
cashout_time1969-12-31 23:59:59
total_payout_value3.533 HBD
curator_payout_value1.110 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length479
author_reputation28,448,644,499,713
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,085,280
net_rshares1,322,768,104,639
author_curate_reward""
vote details (12)
@ravonn · (edited)
$4.52
Thanks :D It's hard to know if you're stating the obvious but hopefully some things were news.
πŸ‘  , , , ,
properties (23)
authorravonn
permlinkre-sc-steemit-re-ravonn-swinging-the-code-axe-20170817t134454520z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 13:44:54
last_update2017-08-17 14:51:00
depth2
children1
last_payout2017-08-24 13:44:54
cashout_time1969-12-31 23:59:59
total_payout_value3.474 HBD
curator_payout_value1.048 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length94
author_reputation1,551,172,951,761
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,086,101
net_rshares1,288,797,863,281
author_curate_reward""
vote details (5)
@sc-steemit ·
$0.02
####  One mans common thing is another mans news? πŸ˜‹ 
Understandable when your involved in it and think its just the most obvious and common.
πŸ‘  
properties (23)
authorsc-steemit
permlinkre-ravonn-re-sc-steemit-re-ravonn-swinging-the-code-axe-20170817t140206334z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-17 14:02:24
last_update2017-08-17 14:02:24
depth3
children0
last_payout2017-08-24 14:02:24
cashout_time1969-12-31 23:59:59
total_payout_value0.018 HBD
curator_payout_value0.005 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length140
author_reputation28,448,644,499,713
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,087,618
net_rshares7,033,454,328
author_curate_reward""
vote details (1)
@thorondor ·
Really great work you are doing there! :)
One big reason why I always remove unused/old code is that others might find it and build up on it or (maybe even worse) use the underlying patterns. The old code might be written in an old pattern that you are currently trying to move away from. But if people see it all over the place they might adapt to it. I have seen that a lot, so I am totally with you when it comes to removing legacy code :)
πŸ‘  
properties (23)
authorthorondor
permlinkre-ravonn-swinging-the-code-axe-20170819t164854924z
categorygridcoin
json_metadata{"tags":["gridcoin"],"app":"steemit/0.1"}
created2017-08-19 16:48:54
last_update2017-08-19 16:48:54
depth1
children0
last_payout2017-08-26 16:48:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length442
author_reputation750,222,434,745
root_title"Swinging the Code Axe"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,277,337
net_rshares0
author_curate_reward""
vote details (1)