Edison  Stark

Edison Stark

1603177500

Refactoring Code | Rock Paper Scissors | Web Dev | Javascript

In this video we refactor our Rock, Paper, Scissors code two times. We take our first version and refactor it with a loop and an array. Then, we continue refactoring code by updating the entire application to a functional approach.

✅ Quick Concepts outline:
Refactoring Code: Rock, Paper, Scissors
• Comparing version 1 and version 2
• Adding a loop
• Adding an array
• Eliminating the reload
• Testing our code
• Comparing version 2 and version 3
• A functional approach

📺 Here’s the refactored code for each version:

Gist for Rock, Paper, Scissors version 1:
https://gist.github.com/gitdagray/38322a7141f4236e050086e7053febb7

Gist for Rock, Paper, Scissors version 2 (add loop and array):
https://gist.github.com/gitdagray/a709dba6c46fcd2b239a8a5679af4e0e

Gist for Rock, Paper, Scissors version 3 (with functions):
https://gist.github.com/gitdagray/c33ef93ba4c18aa3d123c26be23d539a

#javascript #web-development #programming #developer

What is GEEK

Buddha Community

Refactoring Code | Rock Paper Scissors | Web Dev | Javascript

5 Best VS Code Extensions for Refactoring that Every Dev Should Know

If you’re looking at ways to clean up our code, reduce complexity and improve functionality - these refactoring extensions will help you move faster:

#refactoring #vscode #javascript #programming #legacy-code #coding #code

Houston  Sipes

Houston Sipes

1604088000

How to Find the Stinky Parts of Your Code (Part II)

There are more code smells. Let’s keep changing the aromas. We see several symptoms and situations that make us doubt the quality of our development. Let’s look at some possible solutions.

Most of these smells are just hints of something that might be wrong. They are not rigid rules.

This is part II. Part I can be found here.

Code Smell 06 - Too Clever Programmer

The code is difficult to read, there are tricky with names without semantics. Sometimes using language’s accidental complexity.

_Image Source: NeONBRAND on _Unsplash

Problems

  • Readability
  • Maintainability
  • Code Quality
  • Premature Optimization

Solutions

  1. Refactor the code
  2. Use better names

Examples

  • Optimized loops

Exceptions

  • Optimized code for low-level operations.

Sample Code

Wrong

function primeFactors(n){
	  var f = [],  i = 0, d = 2;  

	  for (i = 0; n >= 2; ) {
	     if(n % d == 0){
	       f[i++]=(d); 
	       n /= d;
	    }
	    else{
	      d++;
	    }     
	  }
	  return f;
	}

Right

function primeFactors(numberToFactor){
	  var factors = [], 
	      divisor = 2,
	      remainder = numberToFactor;

	  while(remainder>=2){
	    if(remainder % divisor === 0){
	       factors.push(divisor); 
	       remainder = remainder/ divisor;
	    }
	    else{
	      divisor++;
	    }     
	  }
	  return factors;
	}

Detection

Automatic detection is possible in some languages. Watch some warnings related to complexity, bad names, post increment variables, etc.

#pixel-face #code-smells #clean-code #stinky-code-parts #refactor-legacy-code #refactoring #stinky-code #common-code-smells

Ajay Kapoor

1626321063

JS Development Company India | JavaScript Development Services

PixelCrayons: Our JavaScript web development service offers you a feature-packed & dynamic web application that effectively caters to your business challenges and provide you the best RoI. Our JavaScript web development company works on all major frameworks & libraries like Angular, React, Nodejs, Vue.js, to name a few.

With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.

Looking for professional JavaScript web app development services? We provide custom JavaScript development services applying latest version frameworks and libraries to propel businesses to the next level. Our well-defined and manageable JS development processes are balanced between cost, time and quality along with clear communication.

Our JavaScript development companies offers you strict NDA, 100% money back guarantee and agile/DevOps approach.

#javascript development company #javascript development services #javascript web development #javascript development #javascript web development services #javascript web development company

Edison  Stark

Edison Stark

1603177500

Refactoring Code | Rock Paper Scissors | Web Dev | Javascript

In this video we refactor our Rock, Paper, Scissors code two times. We take our first version and refactor it with a loop and an array. Then, we continue refactoring code by updating the entire application to a functional approach.

✅ Quick Concepts outline:
Refactoring Code: Rock, Paper, Scissors
• Comparing version 1 and version 2
• Adding a loop
• Adding an array
• Eliminating the reload
• Testing our code
• Comparing version 2 and version 3
• A functional approach

📺 Here’s the refactored code for each version:

Gist for Rock, Paper, Scissors version 1:
https://gist.github.com/gitdagray/38322a7141f4236e050086e7053febb7

Gist for Rock, Paper, Scissors version 2 (add loop and array):
https://gist.github.com/gitdagray/a709dba6c46fcd2b239a8a5679af4e0e

Gist for Rock, Paper, Scissors version 3 (with functions):
https://gist.github.com/gitdagray/c33ef93ba4c18aa3d123c26be23d539a

#javascript #web-development #programming #developer

Wiley  Mayer

Wiley Mayer

1603890000

How to Find the Stinky Parts of Your Code (Part I)

of something that might be wrong. They are not rigid rules.

Code Smell 01 — Anemic Models

Your objects are a bunch of public attributes without behavior.

Photo by Stacey Vandergriff on Unsplash

Protocol is empty (with setters/getters).

If we ask a domain expert to describe an entity he/she would hardly tell it is ‘a bunch of attributes’.

Problems

  • No Encapsulation.
  • No mapping to real world entities.
  • Duplicate Code
  • Coupling

Solutions

    1. Find Responsibilities.
    1. Protect your attributes.
    1. Hide implementations.
    1. Delegate

Examples

  • DTOs

Sample Code

	<?

	Class Window{
	  public height;
	  public width;

	  function getHeight(){
	    return $this->height;
	  }

	  function setHeight($height){
	    $this->height = $height;
	  }

	  function getWidth(){
	    return $this->width;
	  }

	  function setWidth($width){
	    $this->width = $width;
	  }

	}

Wrong

<?

	final Class Window{ 

	  function area(){
	    //...
	  }

	  function open(){
	    //..
	  }

	  function isOpen(){
	    //..
	  }

	}

Right

#code-smells #clean-code #refactoring #refactor-legacy-code #stinky-code #stinky-code-parts #pixel-face #hackernoon-top-story