Skip to content

Commit

Permalink
Refactoring 020 - Transform Static Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxi committed Dec 14, 2024
1 parent 526463a commit 08aaad9
Show file tree
Hide file tree
Showing 328 changed files with 1,065 additions and 856 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ I will keep gist for control version, but not for embedding.

Try reading this:

[Gist Url]: # (https://gist.github.com/mcsee/49382a7cff708d0b4a8c2e602295484f)
<!-- [Gist Url](https://gist.github.com/mcsee/49382a7cff708d0b4a8c2e602295484f) -->

```javascript
movie.rate.warnIfNotAllowed(this.age);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![3.2 Identifying the Essence of Your Objects](3.2%20Identifying%20the%20Essence%20of%20Your%20Objects.png)

> TL;DR:
> TL;DR:
https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99

Expand Down
4 changes: 2 additions & 2 deletions Articles/Code Smells/Code Smell 01 - Anemic Models/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If we ask a domain expert to describe an entity he/she would hardly tell it is *

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/73f84d80f7c3e89a216dd9e40ab71bcc)
<!-- [Gist Url](https://gist.github.com/mcsee/73f84d80f7c3e89a216dd9e40ab71bcc) -->

```java
public class Song {
Expand All @@ -52,7 +52,7 @@ public class Song {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/78f2dd78120db843c960ed41839f29cb)
<!-- [Gist Url](https://gist.github.com/mcsee/78f2dd78120db843c960ed41839f29cb) -->

```java
public class Song {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/dec9856bf69a06c367d2e683b179577a)
<!-- [Gist Url](https://gist.github.com/mcsee/dec9856bf69a06c367d2e683b179577a) -->

```php
<?
Expand All @@ -42,7 +42,7 @@ function energy($mass) {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/2e4c88a516078500ce833dbfbd3d9b0e)
<!-- [Gist Url](https://gist.github.com/mcsee/2e4c88a516078500ce833dbfbd3d9b0e) -->

```ruby
# Storing magnitudes without units is another smell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/1f12fb2d0cb9f8eea202526597cf4b83)
<!-- [Gist Url](https://gist.github.com/mcsee/1f12fb2d0cb9f8eea202526597cf4b83) -->

```php
<?
Expand All @@ -52,7 +52,7 @@ function setUpChessBoard() {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/0f66ce8c2bba8990e44a36495fa4c3e1)
<!-- [Gist Url](https://gist.github.com/mcsee/0f66ce8c2bba8990e44a36495fa4c3e1) -->

```php
<?
Expand Down
4 changes: 2 additions & 2 deletions Articles/Code Smells/Code Smell 04 - String Abusers/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/19b5965879d11e6c185d4591add24042)
<!-- [Gist Url](https://gist.github.com/mcsee/19b5965879d11e6c185d4591add24042) -->

```php
<?
Expand All @@ -48,7 +48,7 @@ $school = preg_split('/[\s,]+/', $schoolDescription, 3)[0]; //'College'

## Right

[Gist Url]: # (https://gist.github.com/mcsee/9aea4a3d401b7e3c2e80101ff348dfa6)
<!-- [Gist Url](https://gist.github.com/mcsee/9aea4a3d401b7e3c2e80101ff348dfa6) -->

```php
<?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Comments are coupled to implementation and hardly maintained.*

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/4fb1f04c950ece88450fec59ed6a827b)
<!-- [Gist Url](https://gist.github.com/mcsee/4fb1f04c950ece88450fec59ed6a827b) -->

```php
<?
Expand All @@ -66,7 +66,7 @@ final class ChatBotConnectionHelper {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/698102c04428aec69356cad26d4c50cd)
<!-- [Gist Url](https://gist.github.com/mcsee/698102c04428aec69356cad26d4c50cd) -->

```php
<?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/df27505a28b5f65faaa273b0bfe1f322)
<!-- [Gist Url](https://gist.github.com/mcsee/df27505a28b5f65faaa273b0bfe1f322) -->

```javascript
function primeFactors(n) {
Expand All @@ -55,7 +55,7 @@ function primeFactors(n) {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/4749cfe51de1c02848df1aa802fa5705)
<!-- [Gist Url](https://gist.github.com/mcsee/4749cfe51de1c02848df1aa802fa5705) -->

```javascript
function primeFactors(numberToFactor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This also follows [Open/Closed Principle](https://en.wikipedia.org/wiki/Open%E2%

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/5a3e8e05def917a29b84be7264493a67)
<!-- [Gist Url](https://gist.github.com/mcsee/5a3e8e05def917a29b84be7264493a67) -->

```php
<?
Expand All @@ -41,7 +41,7 @@ function processBatch(

## Right

[Gist Url]: # (https://gist.github.com/mcsee/66956e6ccfe8126d0819fa193d793dd5)
<!-- [Gist Url](https://gist.github.com/mcsee/66956e6ccfe8126d0819fa193d793dd5) -->

```php
<?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Any chain change breaks the code.*

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/de702945b0bb7cd80f696f8cbe19c91c)
<!-- [Gist Url](https://gist.github.com/mcsee/de702945b0bb7cd80f696f8cbe19c91c) -->

```javascript
class Dog {
Expand Down Expand Up @@ -51,7 +51,7 @@ for (var foot of dog.getFeet()) {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/b3b7d73ffb6554df2c06fce3b93a134f)
<!-- [Gist Url](https://gist.github.com/mcsee/b3b7d73ffb6554df2c06fce3b93a134f) -->

```javascript
class Dog {
Expand Down
4 changes: 2 additions & 2 deletions Articles/Code Smells/Code Smell 09 - Dead Code/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/9e793df7489a96dc27d29d0f4e963bdf)
<!-- [Gist Url](https://gist.github.com/mcsee/9e793df7489a96dc27d29d0f4e963bdf) -->

```javascript
class Robot {
Expand All @@ -41,7 +41,7 @@ class Robot {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/e1075cc971b5f7af28e37d29b492735d)
<!-- [Gist Url](https://gist.github.com/mcsee/e1075cc971b5f7af28e37d29b492735d) -->

```javascript
class Robot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/ea7d32472830d5ea877be1438807fe89)
<!-- [Gist Url](https://gist.github.com/mcsee/ea7d32472830d5ea877be1438807fe89) -->

```java
public class Printer {
Expand All @@ -50,7 +50,7 @@ public class Printer {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/200a18dd99a76a95155df4cb032b1d10)
<!-- [Gist Url](https://gist.github.com/mcsee/200a18dd99a76a95155df4cb032b1d10) -->

```java
final public class PaperSize { }
Expand Down
4 changes: 2 additions & 2 deletions Articles/Code Smells/Code Smell 100 - GoTo/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ I had to learn structured programming from scratch in Rehab mode.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/5d76fda8dfbe6f351e709baa00e0e61c)
<!-- [Gist Url](https://gist.github.com/mcsee/5d76fda8dfbe6f351e709baa00e0e61c) -->

```csharp
int i = 0;
Expand All @@ -46,7 +46,7 @@ if (i < 10)

## Right

[Gist Url]: # (https://gist.github.com/mcsee/da74b8e901f234b6bc400c9a6e0b7725)
<!-- [Gist Url](https://gist.github.com/mcsee/da74b8e901f234b6bc400c9a6e0b7725) -->

```csharp
for (int i = 0; i < 10; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Many languages cast values to boolean crossing domains.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/118ff2e5ebd9779675f664ed46bae95d)
<!-- [Gist Url](https://gist.github.com/mcsee/118ff2e5ebd9779675f664ed46bae95d) -->

```bash
#!/bin/bash
Expand All @@ -53,7 +53,7 @@ fi

## Right

[Gist Url]: # (https://gist.github.com/mcsee/405d45ed06a94a81d1f1a3b06381c0f9)
<!-- [Gist Url](https://gist.github.com/mcsee/405d45ed06a94a81d1f1a3b06381c0f9) -->

```bash
#!/bin/bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Cost/benefit is not worth it.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/6f91efd52401b93f91322f20ab6d3aab)
<!-- [Gist Url](https://gist.github.com/mcsee/6f91efd52401b93f91322f20ab6d3aab) -->

```solidity
contract MessageContract {
Expand All @@ -61,7 +61,7 @@ contract MessageContract {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/91d0aa627815f79d471fa79150c5dc9b)
<!-- [Gist Url](https://gist.github.com/mcsee/91d0aa627815f79d471fa79150c5dc9b) -->

```solidity
contract MessageContract {
Expand Down
4 changes: 2 additions & 2 deletions Articles/Code Smells/Code Smell 104 - Assert True/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Error tracking gets more difficult.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/c54f0b1ee42d6a1aff640507e0bdf625)
<!-- [Gist Url](https://gist.github.com/mcsee/c54f0b1ee42d6a1aff640507e0bdf625) -->

```php
<?
Expand Down Expand Up @@ -56,7 +56,7 @@ final class RangeUnitTest extends TestCase {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/edf0b1c3339451662bb000055ef5d782)
<!-- [Gist Url](https://gist.github.com/mcsee/edf0b1c3339451662bb000055ef5d782) -->

```php
<?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Sometimes we get bored and try to be funny.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/fe5ba2b148a1b9b5f11cd7022b059fe6)
<!-- [Gist Url](https://gist.github.com/mcsee/fe5ba2b148a1b9b5f11cd7022b059fe6) -->

```javascript
function erradicateAndMurderAllCustomers();
Expand All @@ -35,7 +35,7 @@ function erradicateAndMurderAllCustomers();

## Right

[Gist Url]: # (https://gist.github.com/mcsee/19ae535002ea19708c13334a1171af37)
<!-- [Gist Url](https://gist.github.com/mcsee/19ae535002ea19708c13334a1171af37) -->

```javascript
function deleteAllCustomers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In this case, we need to configure the environment with the strength strategy an

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/2b00edcf1fded330263a4773b227cd06)
<!-- [Gist Url](https://gist.github.com/mcsee/2b00edcf1fded330263a4773b227cd06) -->

```python
def send_welcome_email(email_address, environment):
Expand All @@ -48,7 +48,7 @@ send_welcome_email("[email protected]", "production")

## Right

[Gist Url]: # (https://gist.github.com/mcsee/4a598f416f01357597a072d75ba30a6f)
<!-- [Gist Url](https://gist.github.com/mcsee/4a598f416f01357597a072d75ba30a6f) -->

```python
class ProductionEnvironment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We should narrow the scope as much as possible.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/88615884493c78d45a57be565964ae5b)
<!-- [Gist Url](https://gist.github.com/mcsee/88615884493c78d45a57be565964ae5b) -->

```java
// print line total
Expand All @@ -46,7 +46,7 @@ System.out.println( "Amount due: " + total);

## Right

[Gist Url]: # (https://gist.github.com/mcsee/9657946be3bcd5a81aebc12d4ef82d0b)
<!-- [Gist Url](https://gist.github.com/mcsee/9657946be3bcd5a81aebc12d4ef82d0b) -->

```java
function printLineTotal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We recommend avoiding floats at all and trying to use infinite precision numbers

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/2fc79af85305eaada328fd324cb38c0d)
<!-- [Gist Url](https://gist.github.com/mcsee/2fc79af85305eaada328fd324cb38c0d) -->

```java
Assert.assertEquals(0.0012f, 0.0012f); // Deprecated
Expand All @@ -43,7 +43,7 @@ Assert.assertTrue(0.0012f == 0.0012f); // Not JUnit - Smell

## Right

[Gist Url]: # (https://gist.github.com/mcsee/570958fcfb8e52379b7ddde2389ad6f8)
<!-- [Gist Url](https://gist.github.com/mcsee/570958fcfb8e52379b7ddde2389ad6f8) -->

```java
Assert.assertEquals(0.0012f, 0.0014f, 0.0002); // true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Some languages provide explicit support to build anemic models and DTOs.

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/2353f11cfb336aaeda194c4a11a21324)
<!-- [Gist Url](https://gist.github.com/mcsee/2353f11cfb336aaeda194c4a11a21324) -->

```csharp
class Person
Expand All @@ -44,7 +44,7 @@ class Person

## Right

[Gist Url]: # (https://gist.github.com/mcsee/198d8a232bd1abf52cda0884fb96bc5f)
<!-- [Gist Url](https://gist.github.com/mcsee/198d8a232bd1abf52cda0884fb96bc5f) -->

```csharp
class Person
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/4f53d085c8b566936c04483064e25ed9)
<!-- [Gist Url](https://gist.github.com/mcsee/4f53d085c8b566936c04483064e25ed9) -->

```java
public class Rectangle {
Expand Down Expand Up @@ -56,7 +56,7 @@ public class Box extends Rectangle{

## Right

[Gist Url]: # (https://gist.github.com/mcsee/9f0082db40c2ab590b2b6ea9702bbb22)
<!-- [Gist Url](https://gist.github.com/mcsee/9f0082db40c2ab590b2b6ea9702bbb22) -->

```java
abstract public class Shape{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Since [case and switches](https://github.com/mcsee/Software-Design-Articles/tree

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/ddad35dc0be43c82d4aff94ad2b79d09)
<!-- [Gist Url](https://gist.github.com/mcsee/ddad35dc0be43c82d4aff94ad2b79d09) -->

```javascript
switch (value) {
Expand All @@ -55,7 +55,7 @@ switch (value) {

## Right

[Gist Url]: # (https://gist.github.com/mcsee/78ca0363b28677b5ff24973b2fc4806f)
<!-- [Gist Url](https://gist.github.com/mcsee/78ca0363b28677b5ff24973b2fc4806f) -->

```javascript
switch (value) {
Expand Down
Loading

0 comments on commit 08aaad9

Please sign in to comment.