Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Spring 2021 -- CSC 2700 Section 01 (100 Tureaud Hall, 6:30 PM - 8:20 PM)

Programming Style

Each person has their own style. And your style evolves over time. More importantly, without constant diligence your style varies constantly.

Before we proceed, it never hurts to give Wikipedia a glance. Here is a neat article on style.

Your style (and the consistency of style) is very important. Consistent style use eases the process of coding (fewer decisions to make hence less opportunity for indecision). More importantly, consistent style is critical for ease of reading code.

Think about it: reading code is not easy. The more variable the coding style the harder it is to read the code (and understand it). The more the style varies from your current style, the more difficult it is to comprehend the code.

Many factors impact code readability:

For the sake of this discussion, lets assume all other factors are static and continue explore the impact of style.

In fact, lets take a step back. As time passes, your knowledge and experiences change (probably advancing). Like everything else, evolves. And just like many other things, that evolution can occur autonomously, managed or somewhere in between. Beginners are almost always unconscious of the style evolution. They eventually notice that the longer ago they wrote something, the harder it is to read. While style is not the only reason for this, it is often a big part of it.

If style evolution goes unmanaged, the impact can be significant. Quite often your style changes to avoid a particular issue. If that issue remains a non-issue for a while, your style may very well regress -- kind of like 1 step forward and 2 steps back. Management of style evolution is necessary to avoid regression (loss of good changes).

How does one go about ensuring that desirable style changes persist? In fact, how do you go about detecting style changes (evolution)?

The general answer to this kind of question is something like this:

Style has a tendency to float (be inconsistent). By definitely defining your style periodically, you reduce the unintended drift. Since your style choices and their variance/consistency dramatically impact readability , development time, and maintainability of code, it is important to develop a consistent style that you are comfortable with.

Periodic re-evaluation of your style allows you several opportunities:

Having a definitive style definition also makes it much easier for a team to agree on a common style (even if the members work in their own and then use formatters to transition to and from the agreed upon style).

All of these statements should help you understand the importance of knowing your style and being able to track its evolution. That evolution happens as you mature and become a more experienced developer. Clearly you want your style to facilitate your improvement instead of hindering you.

Style Elements

Style can have many components. Here are a few to get you thinking:

In fact, many style choices tend to correlate to preference of language.

You should study your style, the style of others (class mates and published code) and the elements of style sufficiently that you feel like your style is the compromise possible for you at this point of your development.

Reformatting

I typically use highlight to reformat code for html display. I am experimenting with astlye for reformatting code (and keeping it still code).

Here are some interesting links: