Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
D docker-containers
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Public
  • docker-containers
  • Wiki
  • code refactoring

Last edited by Yogesh Hegde Nov 04, 2020
Page history
This is an old version of this page. You can view the most recent version or browse the history.

code refactoring

Refactoring Code

In the software companies, there will be times when old software code (also legacy code) needs to re-written with newer optimizations and syntax. This does not add a new feature but improves the working of the existing code. This process is called as refactoring code.

Advantages of refactoring

  1. Improved code readability
  2. Reduced code complexity
  3. Improved performance
  4. Coding style compliance

At then end the goal is to achieve simpler, cleaner, faster and code compliant code without changing user functionality.

Refactoring practical

Goal of the module is to fix problems with the existing code and refactor the code.

The module provides 2 sample example code in 2 coding languages (CPP & Python)

  1. Get the workspace for refactoring

    • Download the ready to use workspace for refactoring - https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-workspace/-/archive/master/refactoring-workspace-master.zip

    • Unzip the refactoring-workspace-master.zip

    • Open VScode.

    • Press Ctrl + Shift + p in VScode. A bar will open up at the top.

    • Search for Remote-Containers remote-containers

    • Click on "Remote-Containers: Open Folder in Containers".

    • In the pop up Window, Navigate to Downloads --> refactoring-workspace-master

    • Click on Open.

    • Vscode will take some time to start up the container, once done

    • Open up terminal by Pressing Ctrl + j. remote-containers

    • That is it done you have successfully opened up the workspace. Now you can get to refactoring.

  2. Fork the refactoring repository.

    • Go to link - https://gitlab.iotiot.in/newbies/pre-office-office/refactoring-trial

    • Click on Fork.

      fork

    • Select your username in the next window.

    • The repo will fork and you should be directed to your own copy of the original repository.

  3. Clone the repository.

    • Copy Repository URL from the

      clone

    • Go to your VScode which has the refactoring workspace opened. remote-containers

    • Type git clone {your-repository-URL-here} in the terminal. (for ex: git clone https://gitlab.iotiot.in/yh42/refactoring-trial)

      clone2

    • Type cd refactoring-trial and open up the repository.

  4. Choose a coding language Python or CPP to refactor code. (choose the language that you are most comfortable with)

    • Type cd codestyle/{language} (for ex: cd codestyle/cpp)
  5. Choose any one sample code to refactor. There are 2 sample codes

    1. yhatzee-game - Click here to read code doc
    2. tennis - Click here to read code doc
  6. Check coding style of the codes

    • For python

      Click to see your steps!
      • Make sure that you are in the folder codestyle/python, Check by running command pwd
      • Type cd {your-chosen-example} in VScode terminal. (for ex: cd tennis)
      • Run command
        • For Tennis pycodestyle tennis.py
        • For yhatzee-game pycodestyle yahtzee.py
      • After running the command you will get a big list of errors in the coding style.
    • For CPP

      Click to see your steps!
      • Make sure that you are in the folder codestyle/cpp, Check by running command pwd
      • Type cd {your-chosen-example} in VScode terminal. (for ex: cd tennis)
      • Run commands
        mkdir build 
        cd build 
        cmake ../
        make codestyle
      • After running the command you will get a big list of errors in the coding style.
  7. Make changes to the code

    • For Python Example

      Click to see your steps!
      • Run command pytest
      • You will see your refactored code get tested. If anything fails the test will report the failure.
    • For CPP Example

      Click to see your steps!
      • For Tennis example, run commands
        make
        ./tennis1_tests
      • For yhatzee-game, run commands
        make
        ./yahtzee_tests
      • You will see your refactored code get tested. If anything fails the test will report the failure.
  8. Test if your refactored code passes all the tests.

    • For Python

      Click to see your steps!
      • Run command pytest
      • You will see your refactored code get tested. If anything fails the test will report the failure.
    • For CPP

      Click to see your steps!
      • For Tennis example, run commands
        make
        ./tennis1_tests
      • For yhatzee-game, run commands
        make
        ./yahtzee_tests
      • You will see your refactored code get tested. If anything fails the test will report the failure.
  9. Repeat the steps 6, 7, 8 till all the code style errors are solved.

  10. Submit the changes.

    • Run commands

      cd /home/shunya/refactoring-trial
      git config --global user.name "{Your-name}" 
      #(for ex: `git config --global user.name "Yogesh Hegde"`)
      git config --global user.email "{your-email-id}" 
      #(for ex: `git config --global user.email "yogesh@iotiot.in"`)
      git add .
      git commit -m "refactored code"
      git push

      submit-cmd

  11. See your code Build, Test and Deploy via CI/CD.

    • Go to your repository (the one that you have forked), CI/CD --> Pipelines.

      pipleines

    • You can see Build, Test and Deploy devOps stages passing.

      stages

    • Click on the passed to see all the individual stage summary. stages-1

  12. Thats is it done, you have successfully Refactored your code and see it Built, Tested and Deployed via CI/CD.

Clone repository
  • Installing tools
  • Readme doc format
  • code refactoring
  • code style container
  • day0
  • devops practical
  • docusaurus
  • Home
  • install on mac
  • install tools ubuntu 16.04
  • install tools windows