Copy Paste Code, Implementations, Clock Skew, Time Zones, Network Intelligence
Post date: Apr 29, 2016 5:59:37 PM
- Some developers seem to like copy paste code, but I just can't stop hating it. Like writing tons of code like if something != something_else: something = something_else and modified = True and then if modified then save object. And copy paste that for 100's of lines with different variables. I converted that horrible copy paste bloat to simple code like like update([(list, of), (variables, to), (be, updated), (with, data), (in, tuples)]. Got got much cleaner, it's more reliable and lot faster than the most simple implementation. Btw. There are three standard levels how similar method exists in the code. Some of code parts just updates variables and always saves. But that's horrible, it's really slow and consumes lot of resources slowing system performance. Do programmers get that? Nope? Copy paste code is huge improvement over that in terms of performance. But it's really error prone when coding. You'll just quickly snag some snippets, add more code, maybe if statement is wrong, maybe update is wrong. Maybe you didn't update modified flag and then everything is wrong. If you save without checking modify flag, then it's just slow. Simple is beautiful, but it often provides really bad performance. Best next thing is to make code which takes care of the complexity making rest of development work easy. Of course it's easy to say that you made 2000 rows of code in a day, instead of 6. If you just copy paste and edit some rows, generating bugs meanwhile. - This is actually one of the low hanging fruits of optimization. Program can run a lot, several orders of magnitude faster if useless transactions and writes are dropped. Cost of that is of course checking if update is required and keeping state. But that can be written in library so it happens completely transparently. Yet when layers start to overlap it can make code really hard to understand. This applies to many existing tightly mixed libraries which are really hard to understand unless you just start reading the whole code and experimenting with individual functions. Yes, it might be easy to use the library, but when you want to modify how it's internals work or to extend it or add external calls doing something which the original writer never thought the library would used for... That can be quite hard and also easily triggers unexpected side-effects by breaking internal relations, references and or state. Yet, not modifying library might lead to tons of bad code, bugs and poor performance.
- More fun with complex implementations and data which got absolutely stunning amount of different mathematical cross references. It's funny when one part bugs, and causes invalid data, nobody notices that for cases A, B and C. Why? Because those implementations use different parts of the data to get the data which they need. Everything seems to be working well, until there's implementation D which does exactly the same as A, B and C, but using different criterion and then boom, we have a problem. As example one program check that 100 - 20% = 80 One program uses the numbers to define percentage, but then another program use the first pair or last pair or what ever, and then rounds it and... Yeah, you'll get the picture. Business as usual. Cross checking data could be really fun in some larger organizations and could reveal really interesting data quality problems. Take three independent or lightly integrated totally different data sources and then start cross checking. If you get same result, that's absolutely amazing. I'm pretty sure you won't. Probably you'll find that the data quality is so bad, that it's amazing that anyone hasn't noticed it earlier.
- Clock Skew Exists? - Yeah it does. I just today spent quite a while fixing few servers having serious clock issues. Yet most common big fails are due to invalid time zone configuration on some level. VM BIOS clock / RTC settings in Windows registry, etc. In case of Finland it usually leads to 2-3 hours (EET, EEST) difference due to UTC being mixed up with local time.
- Watched a documentary about Finnish Network and Communications Intelligence gathering. Only thing they said in that documentary which I haven't heard earlier, was that Sweden has been spying for Finland. Based on on earlier documents, that could have been easily assumed. It's also known way of working around national laws, is letting 'others' outside the law do the dirty work and then co-operate with them.