Saturday, November 14, 2015

The SSI Story, wrapped in the X Factor anecdote !

This is an old one now ! I've probably got late to put it here, or maybe I would have never put it. The motivation suddenly pricks me from within while I prepare for my final presentation and viva for the MS project that I undertook on LTE-Advanced: Carrier Aggregation ! I am reminded of another presentation that I once made, of a product that I used to solely support and take care of, that I never cherished but could never hate :) There was a codeathon event last winters, and I had prepared a presentation on this product called 'System Services Interface', that did lie close to my heart to an extent, even though I used to dream of playing other games. I made this while I was home for a winter break, and the team presented it on the finale ! We did not stand 1st, but this one did evoke smiles on a lot of faces. And the team did roll on the floor laughing - for the X factor points !








                                          





Details later ! I have a viva tomorrow morning, and my presentation ain't ready yet. Blahhh !

Sunday, May 3, 2015

Globals were always a no-no-no !


While reviewing your code, your architect wouldn't perhaps allow you to use a global. Did you know the many reasons why ? Read on ! 

  • Non-locality -- Source code is easiest to understand when the scope of its individual elements are limited. Global variables can be read or modified by any part of the program, making it difficult to remember or reason about every possible use.
  • No Access Control or Constraint Checking -- A global variable can be get or set by any part of the program, and any rules regarding its use can be easily broken or forgotten. (In other words, get/set accessors are generally preferable over direct data access, and this is even more so for global data.) By extension, the lack of access control greatly hinders achieving security in situations where you may wish to run untrusted code (such as working with 3rd party plugins).
  • Implicit coupling -- A program with many global variables often has tight couplings between some of those variables, and couplings between variables and functions. Grouping coupled items into cohesive units usually leads to better programs.
  • Concurrency issues -- if globals can be accessed by multiple threads of execution, synchronization is necessary (and too-often neglected). When dynamically linking modules with globals, the composed system might not be thread-safe even if the two independent modules tested in dozens of different contexts were safe.
  • Namespace pollution -- Global names are available everywhere. You may unknowingly end up using a global when you think you are using a local (by misspelling or forgetting to declare the local) or vice versa. Also, if you ever have to link together modules that have the same global variable names, if you are lucky, you will get linking errors. If you are unlucky, the linker will simply treat all uses of the same name as the same object.
  • Memory allocation issues -- Some environments have memory allocation schemes that make allocation of globals tricky. This is especially true in languages where "constructors" have side-effects other than allocation (because, in that case, you can express unsafe situations where two globals mutually depend on one another). Also, when dynamically linking modules, it can be unclear whether different libraries have their own instances of globals or whether the globals are shared.
  • Testing and Confinement - source that utilizes globals is somewhat more difficult to test because one cannot readily set up a 'clean' environment between runs. More generally, source that utilizes global services of any sort (e.g. reading and writing files or databases) that aren't explicitly provided to that source is difficult to test for the same reason. For communicating systems, the ability to test system invariants may require running more than one 'copy' of a system simultaneously, which is greatly hindered by any use of shared services - including global memory - that are not provided for sharing as part of the test.