teleren/devto huggingface dataset:
Code Smell 70 - Anemic Model Generators
Tags: codenewbie, tutorial, beginners, programming
Published: 2021-05-18 03:04:10

## TL;DR: Do not create anemic objects. Much less with automatic tools.

# Problems

- Anemic Objects

- Coupling to Implementation

- Harder to Debug

# Solutions

1. Create your objects manually.

2. Focus on essential behavior instead of accidental data storage.

# Sample Code

## Wrong

[//]: # (https://gist.github.com/mcsee/f930ccb9f2a14798aea9c6b96977b391)

```php
<?

AnemicClassCreator::create(
    'Employee',
    [
        new AutoGeneratedField('id', '$validators->getIntegerValidator()'),
        new AutoGeneratedField('name', '$validators->getStringValidator()'),
        new AutoGeneratedField('currentlyWorking', '$validators->getBooleanValidator()')
    ]);

class Employee extends AutoGeneratedObjectEmployee {
}

//We have magic setters and getters
//getId() , setId(), getName()
//Validation is not implicit
//Class are loaded via an autoloader

$john = new Employee;
$john->setId(1);
$john->setName('John');
$john->setCurrentlyWorking(true);

$john->getName(); //returns 'John'
```


## Right

[//]: # (https://gist.github.com/mcsee/366d7d78b0952ac088125f75c2bc4035)

```php
<?

final class Employee {
    private $name;
    private $workingStatus;

    public function __construct(string $name, WorkingStatus $workingStatus) {
        //..
    }

    public function name(): string {
        return $this->name;
        //This is not a getter. It is Employee's responsibility to tell us her/his name
    }
}

//We have no magic setters or getters
//all methods are real and can be debugged
//Validations are implicit

$john = new Employee('John', new HiredWorkingStatus());

$john->name(); //returns 'John'
```


# Detection

Often, anemic models are generated with [meta-programming](https://dev.to/mcsee/laziness-i-meta-programming-32a9). 

We need to track these magic [code generators](https://dev.to/mcsee/laziness-ii-code-wizards-56p0).

# Tags

- Anemic

# Conclusion

Code Wizards, Meta-programming, and anemic models are all code smells.

We need to avoid these dark techniques.

Having to write *explicitly* the code makes us reflect on every piece of data we encapsulate.

# Relations

{% post https://dev.to/mcsee/code-smell-01-anemic-models-4dg2 %}

# More info

{% post https://dev.to/mcsee/laziness-i-meta-programming-32a9 %}

{% post https://dev.to/mcsee/laziness-ii-code-wizards-56p0 %}

# Credits

Photo by <a href="https://unsplash.com/@lennykuhne">Lenny Kuhne</a> on <a href="https://unsplash.com/s/photos/factory">Unsplash</a>
  
* * *

> The best smells are something that's easy to spot and most of time lead you to really interesting problems. Data classes (classes with all data and no behavior) are good examples of this. You look at them and ask yourself what behavior should be in this class.

_Martin Fowler_
 
* * *
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}
How to handle out of memory errors when running composer
Published: 2021-05-18 02:23:26

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45nsxk33cflddzqzgupk.jpg)

Just set the `memory_limit` specifying the full route of your `composer.phar` file and update if you got the out of memory error when running composer require.

```
php -d memory_limit=-1 [composer_phar_file_path] update
```

I hope it can help you :)
Storing Data in a Flutter App
Tags: flutter, dart, mobile
Published: 2021-05-18 02:13:37

This series of posts covers mobile app development with Google's [Flutter](https://flutter.dev/). Flutter apps are written in Dart and can be compiled into Android, iOS, and web apps all using a single codebase. 

The last post covers storing data in a Flutter app. I discuss storing data on the device and off of it. I show how to use some of Firebase's services (Cloud Firestore and Auth).

You will be asked to follow along with the programs below. Just click on the links and a code playback will load (you might want to open each one in a new tab). Then click on the comments on the left hand side of the screen or hit the play button to drive the development of the code. You can download the code at any point or copy/paste it. There are some controls in the top right hand side of the screen to make the text bigger or to switch to blog mode (which is good for small screens).

####Storing data on the device
These playbacks show how to store data on the device using shared preferences, files, and SQLite databases.
* [Storing App Data in a File
](https://markm208.github.io/flutterbook/chapter3/01/index.html)
* [Storing App Data in a SQLite Database](https://markm208.github.io/flutterbook/chapter3/02/index.html)

####Storing data off of the device
These playbacks show how to store data off of the device by using the http package and Google's Firebase products.
* [Storing App Data in a Server](https://markm208.github.io/flutterbook/chapter3/03/index.html)
* [Storing App Data in the Firebase Cloud Firestore](https://markm208.github.io/flutterbook/chapter3/04/index.html)
* [Firebase Authentication](https://markm208.github.io/flutterbook/chapter3/05/index.html)

####Comments and Feedback
You can find all of these code playbacks in my free 'book', [Mobile App Development with Dart and Flutter](https://markm208.github.io/flutterbook/). I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter [@markm208](https://twitter.com/markm208).
An Introduction to Flutter
Tags: flutter, dart, mobile
Published: 2021-05-18 02:13:29

This series of posts covers mobile app development with Google's [Flutter](https://flutter.dev/). Flutter apps are written in Dart and can be compiled into Android, iOS, and web apps all using a single codebase. 

In this post I cover the basics of Flutter apps- widgets, state management, navigation, and packages. There are pre-built Flutter widgets for just about everything you can think of and you can compose them together to make your own. There are also a lot of free, open-source 'packages' or libraries on [pub.dev](https://pub.dev/) that allow your app to use the device's sensors, fetch data, and more. 

You will be asked to follow along with the programs below. Just click on the links and a code playback will load (you might want to open each one in a new tab). Then click on the comments on the left hand side of the screen or hit the play button to drive the development of the code. You can download the code at any point or copy/paste it. There are some controls in the top right hand side of the screen to make the text bigger or to switch to blog mode (which is good for small screens).

####Intro
These two playbacks show how to create and run Flutter apps and how to use the tools.
* [Flutter Hello World](https://markm208.github.io/flutterbook/chapter2/01/index.html)
* [flutter create demo_app](https://markm208.github.io/flutterbook/chapter2/02/index.html)

####Widgets
These playbacks cover some of the basic UI widgets in Flutter and how to lay them out on the screen.
* [ListViews](https://markm208.github.io/flutterbook/chapter2/03/index.html)
* [Laying Out Widgets](https://markm208.github.io/flutterbook/chapter2/04/index.html)
* [Navigation in Flutter](https://markm208.github.io/flutterbook/chapter2/05/index.html)
* [Forms](https://markm208.github.io/flutterbook/chapter2/06/index.html)

####Packages
There is a thriving community of developers contributing open source packages on [pub.dev](https://pub.dev/). Packages help you access features of the device like sensors, storage, and more.
* [Using Packages in Flutter](https://markm208.github.io/flutterbook/chapter2/07/index.html)

####Comments and Feedback
You can find all of these code playbacks in my free 'book', [Mobile App Development with Dart and Flutter](https://markm208.github.io/flutterbook/). I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter [@markm208](https://twitter.com/markm208).
An Introduction to Dart
Tags: flutter, dart, mobile
Published: 2021-05-18 02:13:17

This series of posts covers mobile app development with Google's UI toolkit, [Flutter](https://flutter.dev/). Flutter apps are written in Dart and can be compiled into Android, iOS, and web apps all using a single codebase. 

I begin by covering the Dart programming language. Dart is a statically typed, OO language that will feel comfortable to anyone with a background in Javascript, Java, or C#. If you are feeling adventurous you may be able to skip the first post and move on to the next one in the series to dive right into Flutter.

You will be asked to follow along with the programs below. Just click on the links and a code playback will load (you might want to open each one in a new tab). Then click on the comments on the left hand side of the screen or hit the play button to drive the development of the code. You can download the code at any point or copy/paste it. There are some controls in the top right hand side of the screen to make the text bigger or to switch to blog mode (which is good for small screens).

####Installing 
This playback covers installing the tools needed to run Dart programs and to build Flutter apps.
* [Hello World!!! and Flutter/Dart Install Instructions](https://markm208.github.io/flutterbook/chapter1/01/index.html)

####Types
These playbacks cover basic data types in Dart including some data structures.
* [Simple Types in Dart](https://markm208.github.io/flutterbook/chapter1/02/index.html)
* [Lists (Array Based Containers)](https://markm208.github.io/flutterbook/chapter1/03/index.html)
* [Maps and Sets](https://markm208.github.io/flutterbook/chapter1/04/index.html)

####Flow of control
These playbacks covers ifs, loops, and functions.
* [Altering the Flow of Control](https://markm208.github.io/flutterbook/chapter1/05/index.html)
* [Closures](https://markm208.github.io/flutterbook/chapter1/06/index.html)

####Asynchronous programming in Dart
Asynchronous programming is critical in UI focused programs like Flutter apps. This playback begins to cover Futures and await/async.
* [Asynchronous Code in Dart](https://markm208.github.io/flutterbook/chapter1/07/index.html)

####Classes in Dart
This playback covers classes in Dart. There are some interesting features of Dart classes like named constructors and initializers.
* [Classes in Dart](https://markm208.github.io/flutterbook/chapter1/08/index.html)

####Comments and Feedback
You can find all of these code playbacks in my free 'book', [Mobile App Development with Dart and Flutter](https://markm208.github.io/flutterbook/). I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter [@markm208](https://twitter.com/markm208).
Quick notes to use the serverless framework to deploy a Node project on AWS
Tags: aws, serverless, lambda, node
Published: 2021-05-18 02:07:11

## Intro


[serverless](https://www.serverless.com/) framework consists of an open source CLI and a hosted dashboard to provide you with full serverless application lifecycle management. 

The purpose of the article is to provide you a quick configuration to get started with it.

#### Install *serverless* cli

`npm i -g serverless`

#### Configure *serverless* to use AWS

`serverless config credentials --provider aws --key <access-key-id> --secret <secret-access-key> --profile <profileName>`

If you do not wish to provide secrets in the shell, use `~/.aws/credentials` file to save credentials in the following format:

```
[<Enter profile name here>]
aws_access_key_id=*********
aws_secret_access_key=***************
[<Enter another profile name here>]
aws_access_key_id=*******************
aws_secret_access_key=**********************
```

#### Create a new project (*nodejs*)


`serverless create --template aws-nodejs --path myServerlessProject`

The following files are created:
*handler.js*
*.npmignore*
*serverless.yml*

In `serverless.yml`, add `profile` and `region`
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiec5t15luy6qdvaasgj.png)
 

#### Deploy to AWS

In a shell, run
`sls deploy`

After every change in `serverless.yml`, you must run this command to deploy the changes.

#### Add a S3 bucket

In `serverless.yml` add:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnho74dplem1k7y61yfk.png)
 

#### Add a plugin 

In a shell, run

`npm i --save serverless-s3-sync`

In `serverless.yml` add:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3bb14yycmc753m3tlzx.png)
 

#### Configure the plugin

Example configuration for `s3sync` plugin

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76pu6hdp45nj9losbcfv.png)

#### Add lambda functions

In `serverless.yml` add:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wste4bhotq1s4hso7e7g.png)
 
#### Enable debug when deploying

In a shell, run
`SLS_DEBUG=* sls deploy`


#### Example config of `serverless.yml`

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbte90g06ipxw3scmgim.png)
Create Custom Helper Class in Laravel 7
Published: 2021-05-18 02:04:11

In this article, let’s learn how to create a custom helper class in Laravel 7.

First step, create a `app\Utilities` folder.

Next, create a `app\Utilities\SiteHelper.php` file.

Then add following code into that file

```php
namespace App\Utilities;

class SiteHelper
{
    public static function slug(string $str): string
    {
        $str = self::stripVnUnicode($str);
        $str = preg_replace('/[^A-Za-z0-9-]/', ' ', $str);
        $str = preg_replace('/ +/', ' ', $str);
        $str = trim($str);
        $str = str_replace(' ', '-', $str);
        $str = preg_replace('/-+/', '-', $str);
        $str=  preg_replace("/-$/", '', $str);
        return strtolower($str);
    }

    public static function stripVnUnicode(string $str): string
    {
        if (!$str) {
            return false;
        }
        $str = strip_tags($str);
        $unicode = [
            'a' => 'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
            'd' => 'đ',
            'e' => 'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
            'i' => 'í|ì|ỉ|ĩ|ị',
            'o' => 'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
            'u' => 'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
            'y' => 'ý|ỳ|ỷ|ỹ|ỵ',
            'A' => 'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
            'D' => 'Đ',
            'E' => 'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
            'I' => 'Í|Ì|Ỉ|Ĩ|Ị',
            'O' => 'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
            'U' => 'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
            'Y' => 'Ý|Ỳ|Ỷ|Ỹ|Ỵ',
        ];
        foreach($unicode as $key  => $value) {
            $str = preg_replace("/($value)/i", $key, $str);
        }
        return $str;
    }
}
```

In `config\app.php`, add key and value in array of Aliases.

```php
return [
    //...
    'aliases' => [
        //...
        'SiteHelper' => App\Utilities\SiteHelper::class,
    ],
];
```

And then in your `composer.json` file add the following “files” array to the autoload section. It should look something like this:

```
"autoload": {
    // ...
    "files": [
        "app/Utilities/SiteHelper.php"
    ]
},
```

Run follow command in Terminal:

```
composer dump-autoload
```

How to use:

In controller code

```php
use SiteHelper;
public function test()
{
    dd(SiteHelper::slug('dolor sit qui amet qui'));
}
```

In blade template

```
{{ SiteHelper::slug('dolor sit qui amet qui') }}
```

I hope it can help you.
Javascript Chapter 4 - Arithmetic Operators in JavaScript
Tags: javascript, tutorial, beginners
Published: 2021-05-18 02:00:36

Arithmetic operators in JavaScript are very necessary when we create applications that require logic that requires us to make calculations, whether it is a small number of calculations or a very large number of computations. Therefore I will discuss about "Arithmetic Operators in JavaScript".

Arithmetic / math operators are used to assign values, compare values, perform arithmetic operations, and much more. Arithmetic operators are indispensable when we create applications that require calculation logic. Whether it's a small number or a large number of calculations. And in this tutorial, I will discuss what Arithmetic operators are
Before learning further about javascript arithmetic operators, we will discuss what operators are available in javascript that we can use to create calculation applications using javascript.

Here are the operators that we can use to create arithmetic operators

| Operator | Description |
| ----------- | ----------- |
**+**|**Addition**
:-----:|:-----:
-|Subtraction
*|Multiplication
**|Exponentiation (ES2016)
/|Division
%|Modulus (Remainder)
++|Increment
--|Decrement

## HOW TO MAKE ARITHMATIC CALCULATIONS WITH JAVASCRIP
 
The following is an example of writing to create a javascript arithmetic operator

![index.html](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4p3epplezbvz0u73k4li.png)

In the example above, we made an example of making addition arithmetic operators. By creating two variables and filling in the values of each of these variables, namely variables numbers1 and numbers, where variable1 I fill in the value 5 and variable numbers I fill in the value 8. Then to add them we just need to add the number operator as follows:

```javascript
document.getElementById('penjumlahan').innerHTML = penjumlahan;
```

At this point, the summation variable already contains the value of number1 + number2, namely 5 + 8. Then we display the results on the element with the id of addition. And when we try to run it in a web browser, the results are as follows

![index.html result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xniabk5l770bckzrst8f.png)

## CONCLUSION
Javascript has several arithmetic operators including addition (+), subtraction (-), multiplication (*), division (/), modulus (%), increment (++), decrement (-) which we can use to make an operation mathematics and one of the examples we can apply is by making a calculator with javascript
Working With Cache
Tags: cache, webdev, musing
Published: 2021-05-18 01:25:52

Whether you are new to programming or you have been at it for a couple of years, you will run into cache. Maybe you have deployed updated code to a project that you have been working on and noticed that _the changes are not there._ You refresh the page and still nothing! You check deployment and everything looks good. Why are the changes not showing up? The answer probably is that the cache has not cleared. 
 
So, what is cache? How do you work with it? 
 
Cache is something that the browser will access quickly so it does not have to make a request to the server to see the contents of the page you are trying to access. 
 
Picture this: you want to bake cookies. Instead of going to the store to retrieve flour, sugar, chocolate chips, etc. you go right to your kitchen and grab the ingredients you need. Instead of making the request to the server (i.e. going to the store to retrieve items), you accessed cache (i.e kitchen) to get your items in a much faster time. 
 
Cache enhances user experience so you do not have to sit and wait for a page to load. In other words, you do not have to go the store every single time you want to bake cookies. 
 
Back to the beginning of the article: Always. Remember. To. Clear. Cache! 😄
BigO for technical interviews
Published: 2021-05-18 01:14:57

When preparing for upcoming technical interviews (especially for software engineering roles at [FAANG companies](https://blog.interviewing.io/how-do-i-know-if-im-ready-to-interview-at-faang/)), you might practice by solving coding challenges online and preparing by solving [common interview questions](https://www.pathrise.com/guides/93-software-engineer-interview-questions-to-nail-your-onsite/).

One of our previous articles lists some [common platforms](https://dev.to/coderbyte/the-best-code-interview-prep-platforms-in-2020-3emj) where you can practice coding, like:
- [Coderbyte](https://coderbyte.com/)
- [Interview Cake](https://www.interviewcake.com/)
- [AlgoExpert](https://www.algoexpert.io/product)
- [Leetcode](https://leetcode.com/)

[Big-O](https://en.wikipedia.org/wiki/Big_O_notation) is an important concept you'll come across when learning about algorithms and data structures. 

>Big-O notation is used to classify algorithms according to how their run time or space requirements grow as the input size grows.

[Coderbyte](https://coderbyte.com/big-o-runtime-guide) is the only platform where the runtime analysis for your solutions is generated and expressed in Big-O notation automatically in your profile. Below is a screenshot of how it'll look on your profile after solving a coding challenge.

```javascript
function FindIntersection(strArr) { 
  let arr1= strArr[0].split(', ');
  let arr2 = strArr[1].split(', ');
  let intersArr= [];
  for (i = 0; i < arr1.length; i++) {
    if (arr2.includes(arr1[i])) {
      intersArr.push(arr1[i])
    }
  }
  return intersArr.toString();
}
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7e47t3bfukxplcre6zk.png)

When you submit a solution for a challenge and it passes all the test cases, your solution is then sent to our runtime-analysis server where we run a series of progressively larger test cases, and then statistically determine what runtime trajectory it matches. We currently will return one of the following [common Big-O results](https://en.wikipedia.org/wiki/Big_O_notation#Orders_of_common_functions).

We [open-sourced our code](https://github.com/coderbyte-org/big-o) for this as well (written in TypeScript) so you can learn how it works!

{% youtube HfIH3czXc-8 %}
TIL to Set Unity Quick Search Priority
Tags: todayilearned, gamedev, unity3d, search
Published: 2021-05-18 01:01:09

2021-05-17

My user interface err usage(?) style tends to be mouse-averse. As an example I prefer using Quick Launcher UIs to clicking around menus and submenus. 
![GIF animations of Power Toys Quick Launcher in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqyxym858r25q3onjbbi.gif)
So once I discovered it, I used Unity Quick Search a bit. But I noticed that most of my frequently needed commands were at the bottom of the list. This is because the default order of providers favors assets first. For me, this meant editor icons and other cruft were given priority first. Fortunately this is easy to reorder under Preferences > Quick Search.
![Screenshot of provider order](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwo9ztn5b5wcpkdu0b8n.png)
Just click the up and down buttons as needed. Favorites, I suppose, can also be used for similar effect but this seems to work for me...for now.
I'm launching a DevOps podcast
Tags: podcast, devops, qna, youtube
Published: 2021-05-18 19:25:51

---
title: I'm launching a DevOps podcast
published: true
date: 2021-05-18 00:00:00 UTC
tags: podcast,devops,qna,youtube
canonical_url: https://jhall.io/archive/2021/05/18/im-launching-a-podcast/
---

Next week I’ll be launching a new weekly video podcast: [Tiny DevOps](https://podcast.jhall.io/).

In each episode I will interview a DevOps practitioner on a different topic relevant to small companies and small teams, or answer listener questions.

So before the launch, I wanted to reach out and ask for your questions. What questions do you have about productivity, developer practices, or any other DevOps topic that you’d like to hear answered in an upcoming Q&A episode? Hit your reply button, and let me know what’s on your mind. Priority will be given to video or audio recordings of you asking your question!

Until then, you can listen to (or watch) the trailer episode I’ve prepared:

Listen: [https://share.transistor.fm/s/66f442a0](https://share.transistor.fm/s/66f442a0)Watch: [https://youtu.be/pozCkfO0hQE](https://youtu.be/pozCkfO0hQE)

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._