Giter Site home page Giter Site logo

cypher's Introduction

Refactoring

In our persuit to becoming a grade "A" beginner we need to make our code clean, easy to read and smooth to run. We do this first by sitting down with a fresh pair of eyes.

Refactoring is not about solving the problem with different logic, it's solving the problem with more polish. A good solution is not just one that works well enough but one that is clear and we do this by...

  • Descriptive and appropriate naming for methods and variables. Here are some tips on naming Click here for good naming article
  • Make code more readable by reducing "code smell". There's a good article here. Remember: that short code is not the smallest number of lines, but each line and each method has as little responsibilty as possible.

Example of what not to do:

word.downcase.split(//).join.match(/\w/).gsub

This is very hard to read when all of your methods are chained together.

Last major refactoring trick is writing D.R.Y. code aka "Don't Repeat Yourself" and Y.a.g.n.i. meaning you ain't gonna need it. Click here for make DRY code.

Yagni tips

  • ruby returns implicitly
  • methods return the last line of code as their result.

Google other tips for refactoring ruby, there is alway room to get better.

Cipher Challenge

Summary

Cryptography is all about the art of creating and decoding secret messages, called ciphers. Modern computers were born from advancements in cryptography.

In this challenge, you'll refactor some existing cryptography code to make it more readable and follow Ruby best practices. This is a long method. Use your newly-developed skills with classes and driver test code to break this code into a class structure and call the methods within it.

Release 0: Run the code

Run the code in my_solution.rb and see what the expected output is.

Release 1: Comment the code

Write comments next to or above each line in the my_solution.rb file with an explanation. Really focus on breaking each step down. You want to fully understand and explain every line.

Release 2: Write additional tests

Create some input messages of your own and see what comes out. What will always be the same using this cipher? What changes? Write driver test code in the my_solution.rb file based on what you discover.

Release 3: Refactor the initial solution

Rewrite the method in the my_solution.rb file. Be sure to do the following:

  • Clean up the variable names.
  • The original code used a hard-coded hash to do the encryption. Can you create a simple algorithm instead? The original shift was by 4 characters. What would happen if it was changed to 10? Would your class be able to handle that change easily? Enjoy Enjoy again

cypher's People

Contributors

jackmarx avatar

Watchers

James Cloos avatar  avatar

Forkers

raindogg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.