5. Code#

In the previous chapter, we discussed how version control using Git can be a superhero sidekick for managing your documents, allowing you to keep track of changes and maintain a clear history of your work. But did you know that version control has its origins in the world of code development?

Evolution of Version Control for Code Before Git, developers faced similar challenges to those encountered with multiple manuscript versions. They would create multiple files like “table1_jhu_v1.ado,” “table1_jhu_v2.ado,” or even “table1_jhu_final.ado” as they iteratively improved their code to generate Table 1, a crucial component in medical and epidemiological research (see below for an in-house example).

The Power of Version Control in Code Just like in our manuscript example, code development also required a better way to manage versions and collaborate efficiently. And that’s where version control systems came to the rescue.

The Hero of Code Version Control Version control in the context of code serves the same fundamental purpose as it does for documents. However, instead of managing manuscripts’ evolution, it tracks the evolution of code files like “table1_jhu.ado.” Just like snapshots in time, it records every change made to the codebase, allowing developers to review the history and understand how the code has progressed. An example in Stata of how things are currently done is shown in the code version 3.01 below.

The Rise of Git Git, which we’ve been discussing in the manuscript context, is one such version control system designed primarily for code. Although we previously talked about manuscripts, the principles of version control apply equally to code files like “table1_jhu.ado.”

Collaboration and Code Management with Git Git was initially created by Linus Torvalds in 2005 to manage the development of the Linux kernel, but its adoption quickly spread among developers due to its efficiency, flexibility, and powerful features. It revolutionized how code projects were managed, enabling seamless collaboration between individuals and teams across the globe.

Branching and Beyond Instead of passing files back and forth or creating countless copies, developers could now work together on the same codebase, creating branches to experiment with new ideas while preserving the main code’s integrity, such as “table1_jhu_development” or “table1_jhu_feature_branch.”

Version Control Platforms As version control became an integral part of the software development process, it also led to the rise of platforms like GitHub, Bitbucket, and GitLab. These platforms provide a centralized and accessible location to host Git repositories, making it easier for developers to share their code and collaborate with others on projects like “table1_jhu.ado.”

The Versatility of Git Today, Git has become the industry standard for version control, transforming how developers approach code development and fostering a vibrant and collaborative open-source community. Its adoption extends far beyond software development, as it has proven to be an invaluable tool for managing any project involving files and collaboration, including projects like “table1_jhu.ado” in medical and epidemiological research.

Streamlining Workflows So, whether you’re working on a manuscript or developing code like “table1_jhu.ado,” version control systems like Git have become indispensable tools for modern collaborative workflows. By embracing version control principles, you can streamline your work, avoid confusion, and focus on what truly matters – delivering high-quality research and impactful contributions to your field. Happy version controlling! 🚀👩‍💻

Sample Table 1 Code: Before the Dawn of Git’s Era

The snippet below provides a fascinating window into the world before the widespread adoption of version control. These lines, with their inline annotations and versioning notes, encapsulate the diligent efforts developers made to manually track the evolution of their code.

*! inspired by PH.340.600
*! by Vincent Jin & Abi Muzaale
*! July 5, 2022 
*! version 3.01
*! fixed rounding issue for non-by table
*! space added between median & IQR for cont vars

capture program drop table1_jhu_v3_01
program define table1_v3_01
     syntax [if],  title(string) ///  
	              [cont(varlist)] ///  
			      [binary(varlist)]  /// 
			      [multi(varlist)] /// 
				  [foot(string)] ///  
				  [by(varname)] ///
				  [excel(string)]
				  
	quietly {
		
		// screen if 'if' syntax is invoked
		if "`if'" != "" {
			local if_helper = substr("`if'", 3, .)
			local if_helper : di "& " "`if_helper'"
		}

Imagine, for a moment, navigating such changes across multiple files, each with its own set of annotations and edits. Now, let’s contrast this with the convenience of Git. With Git, instead of scattered annotations, each change gets a commit – a snapshot, if you will, that clearly records alterations, complete with meaningful descriptions. Over time, these commits accumulate to form a Git history, a comprehensive log of all changes made to the codebase.

For those who are visual learners, We’ve prepared a demonstration on how Git seamlessly manages these changes, allowing for a streamlined coding experience. Dive into this video We’ve uploaded on YouTube to see Git in action:

In the video, you’ll witness the power of Git commits and history firsthand, illustrating just how transformative this tool has been for developers, especially when contrasted with the manual methods of yesteryears.