How does coding improve with time?

0

Answer by Phillip Oldham from Quora:

  • You write code that’s easier to read. Better variable/function/class names, inline comments, better layout, more logical flow.
  • You learn that documentation is a GoodThing™ and, while boring to produce, is something you start to add without being prompted.
  • You find naming things (arguably the hardest part of programming) gets easier.
  • You learn how to structure your code better. Grouping functionality into classes, modules, packages becomes second nature.
  • You stop copy-pasting code around your codebase to duplicate functionality, and start following “Don’t Repeat Yourself” practices.
  • You learn to log properly, and how useful that is for debugging.
  • You stop to think more. When you start out you tend to just keep writing code until something works. As you progress, you start to think more about the problem and stop piling on the code to attempt to fix things.
  • You write less code overall; experience teaches you better approaches to the basics you start with.
  • You learn what Technical Debt is. And you learn to hate it.
  • You learn to refactor. You’d be surprised how often you fix a problem by refactoring and simplifying your code.
  • You learn that premature optimisation is a “sin”, but you also learn to use optimal constructs by default.
  • You learn to manage your code properly. Version control. Code reviews. Versioning. Releases.
  • You stop relying on things. Networks, APIs, protocols, libraries, databases, data, people, even your own code… what can go wrong will go wrong, so you learn to be defensive about everything. While this sounds pessimistic, you realise it’s simply practical.

How does coding improve with time?

MaximumSubArray – Dynamic programming

0

//aim of the program is to find the maximum subarray (contiguous sequence of number) in an array containing both positive and negative numbers

#include<iostream>
using namespace std;
int main(){
    int n;
    cout<<“enter the number of elements”;
    cin>>n;
    int arr[n],max[n],maxsum=0;
    cout<<“enter the elements”;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(arr[0]>0)
      max[0]=arr[0];
      else
      max[0]=0;
      for(int i=1;i<n;i++){
          if((max[i-1]+arr[i])>0){
              max[i]=max[i-1]+arr[i];
          }
              else
              max[i]=0;
          
      }
      for(int i=1;i<n;i++){
          if(max[i]>maxsum){
              maxsum=max[i];
          }
      }
      cout<<“\n maximun sum is “<<maxsum;
  }