teleren/devto huggingface dataset:
Why you should write constants on the LHS for comparisons?
Tags: programming, codenewbie, beginners
Published: 2021-07-13 13:00:49

I picked up this practice some 20+ years ago in my first job. It was part of the commandments for us newbie programmers back then - we mostly coded in C/C++ those days. We have come a long way since, but I'd argue that this practice could help you save from a blunder some day.

Let me just quote the commandment here -     

> **Thou shall _always_ put the literals/constants on the LHS and variable on the RHS in the `if` condition for equality!**

Code samples:

```java
if(true == deleteAll){
   // delete all records
}

if(0 == quantity){
   // report not available
}
```

The rationale here is simple – occasionally we programmers, lost in our efforts to solve the complex problems of universe, end up using a single assignment operator `=` instead of the comparison operator `==` unknowingly. In case of the languages where `if` condition does not only accept a boolean (like C, C++), this could result in unintentional assignment instead of comparison. Moreover, your compiler won’t be able to catch it for these languages (most IDEs these days warn about this though), or it will go unnoticed in scripts like JavaScript. However, when you use literal/constant on the LHS, even an accidental, unintentional assignment is not possible. i.e. you simply cannot have this, compiler will flag an error –

```java
if(0 = quantity){
   // report not available
}
```

But the compiler, or your IDE _might_ not flag an error for this - 

```java
if(quantity = 0){
   // report not available
}
```
..and that’s _exactly_ the point. We let the compiler do the work of finding such bugs instead of realizing it at the runtime, and then eventually spending hours debugging and tracking down one small unintentional assignment, which should have been an equality comparison in the first place.

This approach _still_ makes sense in 2021 including languages like Java, Kotlin (only boolean in `if` condition) etc. for the following reasons - 

1. Consider boolean comparison itself in Java, what would happen here (ignoring compiler warning for assignment, among tons of other deprecation warnings) if the following code is unintentionally added?

```java
if(deleteAll = true){
    //delete everything?
}
```

On the other hand, when you write code like this, the compiler would be able to help you, right? 😥

```java
if(true = deleteAll){
    //delete everything?
}
```

2. More importantly, you seldom code in a single language as you grow as a software developer. There are times when you need to come up with a small snippet of JavaScript code (well, JS is ubiquitous - ain't disappearing for another two decades or more). All these things would be still valid there. 

It is not about any one particular language/technology, it is more about developing better coding practices. These practices help us in the long run, and make us better programmers. :smiley:
AI Solutions Software Development Company
Published: 2021-07-13 12:59:25

As an Quytech AI Development Company, we enable your business to offer a best customer experience and become smarter by implementing AI into your products and growing business operations. Our best Artificial Development Services include building BI solutions, NLP-based applications, computer vision apps, SaaS App, voice assistants and chatbots. Having more then 10+ years experience in development and 1000+ happy clients. https://www.quytech.com/artificial-intelligence-solutions.php
Python UNIT Testing
Tags: python, testing, tutorial
Published: 2021-07-13 12:53:56

# UNIT Testing 
It is the processing of testing whether a particular unit is working properly or not is called unit testing


# Test Scenario vs Test Case vs Test Suite
* Test Scenario consists of multiple test case for single scenario
* So there will be different scenarios consists of test cases for a given application example of one scenario is testing login functionality.
* Test Suite is something like grouping of test cases and executing them at a time

# Implementing Python Unit testing 
* We will use Python in-built module **unittest**
* We will  use **TestCase** class to implement
* We also use 3 instance methods **setUp(), test(), tearDown()**
* Here is the simple test class
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/obnzxr2vrxyila0t4b63.png)

* Output of above code is 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dowo3gufp6a3isitzvmj.png)

* Here we need to be careful that setUp and tearDown method names are fixed but we can change the test method name as we like bit it need to be prefix with "test" example test_sample(), test1().
* We can include as many test methods we want into the class
## Note
* For every test method setUp(),tearDown() methods will be executed.

* To avoid this repeated call of setUp and tearDown methods we can use **setUpClass(), tearDownClass()** methods, now only one time setup and teardown methods are called regardless of how many number of testcases.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4ea5me8gwpc7jkml8mv.png)

O/P

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3e60n9pg3v9e6bb454a.png)

You can also use assert functions in test method 


Hope you learned something!!!
Happy coding!!!
7 Github repos based on JavaScript
Tags: webdev, codenewbie, beginners, programming
Published: 2021-07-13 12:50:44

_If you found value in this thread you will most likely enjoy my tweets too so make sure you follow me on [Twitter](https://twitter.com/VladPasca5)  for more information about web development and how to improve as a developer. This article was first published on my [Blog](https://vladpasca.hashnode.dev/)_

### 1. JavaScript30

A list of 30 projects built with HTML, CSS and JavaScript

🔗https://github.com/wesbos/JavaScript30

### 2. 30 seconds of code

Short JavaScript code snippets for all your development needs

🔗https://github.com/30-seconds/30-seconds-of-code

### 3. Clean code JavaScript

Clean Code concepts adapted for JavaScript

🔗https://github.com/ryanmcdermott/clean-code-javascript

### 4. 33 JavaScript Concepts

33 JavaScript concepts every developer should know

🔗https://github.com/leonardomso/33-js-concepts

### 5. JavaScript questions

A long list of (advanced) JavaScript questions, and their explanations

🔗https://github.com/lydiahallie/javascript-questions

### 6. JavaScript

JavaScript Style Guide

🔗https://github.com/airbnb/javascript

### 7. JavaScript

A repository for All algorithms implemented in Javascript (for educational purposes only)

🔗https://github.com/TheAlgorithms/Javascript

### The end

_I hope found this useful and if you did please let me know. If you have any question feel free to DM me on  [Twitter](https://twitter.com/VladPasca5) ._
UI Dev Newsletter #65
Tags: html, css, javascript, a11y
Published: 2021-07-13 12:40:16

- [Using HSL Colors In CSS](https://bit.ly/3AVIweL)
Ahmad Shadeed explains what HSL is, how to use it and shares some valuable use-cases and examples that you can use right away in your current projects.


- [The Large, Small, and Dynamic Viewports](https://bit.ly/3r2oafr)
Bramus Van Damme shows which changes are being proposed regarding viewport units and how they should work.


- [The Dilemma of Naming Font Size Variables](https://bit.ly/3hx3Xes)
Martin Lexelius explores how to define font sizes in your project.


- [Demystifying the material design expand and cross-fade effect](https://bit.ly/3wzLYs7)
Mikael Ainalem explains how to recreate the effect from the Material Design where the component zooms in and reveals more details.


- [Pairing fonts – 3 ways to find great typeface combinations](https://bit.ly/36uicun)
Oliver Schöndorfer shares different approaches to combining typefaces that teach you some principles, show you a couple of quick wins and go into the nerdy detail.


- [the-new-css-reset](https://bit.ly/2UI4p0p)
Elad Shechter shares the new simple, and lighter CSS reset.


- [RTL:WTF](https://bit.ly/3ARYOW7)
Moriel Schottlender creates a site where you could read the web like Right-to-Left readers do, learn about the challenges, and how to help solve them.


- [20+ Web Projects With Vanilla JavaScript](https://bit.ly/3hWCCSc)
Brad Traversy collects mini projects built with HTML5, CSS & JavaScript. No frameworks or libraries.



Happy coding!

[Subscribe to the newsletter here!](https://bit.ly/34155z3)
Daily Developer Jokes - Tuesday, Jul 13, 2021
Tags: jokes, dailydeveloperjokes
Published: 2021-07-13 12:00:25

---
title: "Daily Developer Jokes - Tuesday, Jul 13, 2021"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Tuesday%2C%20Jul%2013%2C%202021"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e125880f2f70.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ How do you get the code for the bank vault?

___A:___ You checkout their branch.
 -->
How to architecture state variables in React
Tags: javascript, react, webdev, beginners
Published: 2021-07-13 11:57:49

Hello Devs, in this article, we will see how to architecture the state variables in your react app.


* If a state is used by a single component it should be inside that component.

* If a state is used by multiple components in a tree and they are all direct children of the same parent component, it should be in their parent component.

* If a state is used by multiple components in a tree but they are not direct children of the same parent component, it should be in context/redux.

* If a state is used by multiple components in different trees, it should be in context/redux.


I hope this article helped you. Want to connect with me? my DM is open on dev.to, you can connect with me on [twitter](https://twitter.com/SaranChakravar3)

Happy coding!
5 Projects to Get You to Your First Dev Job in 2021
Tags: webdev, react, javascript
Published: 2021-07-13 11:13:53

#Projects Link :

1. **LinkedIn clone**    : https://linkedin-clone-ten.vercel.app/
2. **Amazon clone**      : https://amazon-clone-self.vercel.app/
3. **Instagram clone**   : https://learning-f80ea.firebaseapp.com/
4. **Ecommerce Website** : https://gym-equipment-b8ac7.web.app/
5. **WhatsApp clone**    : https://whatsapp-clone-ochre.vercel.app/

{% github Aman2221/ECOMMERCE-MERN %}
How to manage your package JSON file with npm
Tags: node, npm, javascript
Published: 2021-07-13 11:01:33

<!-- wp:paragraph -->
<p>We are using every day <strong>npm package</strong> and sometimes we forgot to check the latest updates from the package JSON file so how we update this file with <strong>npm</strong>?</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The best approach for a front-end project is always to have the latest packages updated. Why? You are up to date with the latest technologies and also you can prevent problems related to security.</p>
<!-- /wp:paragraph -->

## Use npm outdated

If we run npm outdated command in the root of the project, for a project with a package JSON file, we can see how many npm packages require updates.

## Run npm update

<!-- wp:paragraph -->
<p>Running <strong>npm update</strong> will auto-update packages without the need to update them manually. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Before running <strong>npm update</strong> if you have some packages that don't need updates or maybe it's a package with some deprecations, no longer maintained by the author, you can change the version of the package to be fixed like this: "next": "^10.2.3" → "next": "10.2.3".</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Removing the "^" from the package version, we set a fixed version and when we run <strong>npm update</strong> that package will not be updated to the next version.</p>
<!-- /wp:paragraph -->

##Scan your project for vulnerabilities with npm audit

Yes, we can audit our packages running npm audit, this will tell you if you have any vulnerabilities and what to do to fix them.

<!-- wp:paragraph -->
<p>Read carefully all the pieces of information from the report, some suggestions may not be a fit for your project.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The last command you should run after report review is <strong>npm audit fix</strong>, this will automatically update all the broken packages. Other options for <strong>npm audit</strong> can be found on the <a href="https://docs.npmjs.com/cli/v7/commands/npm-audit" target="_blank" rel="noreferrer noopener">official docs</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>From my point of view, this would be a good behavior to have as a Developer, check your packages because when you code new features it's easy just to add packages without checking for vulnerabilities.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
If you like what I suggested here you can follow me on&nbsp;<a href="https://twitter.com/StefanCraciun5" target="_blank" rel="noreferrer noopener">Twitter</a>&nbsp;or subscribe to my&nbsp;<a href="https://tinyletter.com/stefaniq1" target="_blank" rel="noreferrer noopener">newsletter</a>.
<!-- /wp:paragraph -->

The original article can be found on my [personal blog](https://stefaniq.com/how-to-manage-your-package-json-file-with-npm/).
Wunder sharing knowledge on Decoupled Days 2021
Tags: decoupleddays2021
Published: 2021-07-13 11:00:46

When else would you have an opportunity to attend a worldwide conference while having a sunbath and enjoying cold refreshments? In the summer, of course!

Decoupled Days 2021 is about to air this Wednesday (July 14), and our @dcorbacho will be there with two #wunderful sessions.
So, find a shady spot, make yourself comfortable and get ready for loads of valuable knowledge. 

Read more: https://bit.ly/36CiX4o
42 - How to choose the 'Right' Datastores for your scenario
Tags: data, azure, cloud, architecture
Published: 2021-07-13 10:19:26

**This post was originally published on Fri, Jul 9, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/choosing-the-right-datastore/).**

There are so many types of data stores out there these days. You have relational, non-relational, documents, blob, tables, files and more. There's also a growing awareness of 'Polyglot Persistence' where you use different data stores depending on the task. But how do you know which is the 'right' one? Chris is joined once again by Steph Martin as we talk through some of these types of datastores, and the factors that may help you in your decision!

{% youtube clX44yqWKLo %}
CGN6 - Cloud Gaming Notes Episode 6 - Gaming as Entertainment - Esports and Streaming
Tags: gaming, cloud, azure, gamedev
Published: 2021-07-13 10:17:38

**This post was originally published on Wed, Jul 7, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/game-streaming-and-entertainment/)**.

Playing games has always been a social experience. Whether it's board games, sports or video games - a multiplayer component is common. We see these experiences becoming forms of entertainment (e.g. watching our favourite sports teams compete). This trend continues into the Gaming Industry, as we see the growth of Esports in Gaming, as well as streamers regularly broadcasting over on YouTube and Twitch. Chris is joined by Lee Williams, as they talk through these trends and how Cloud has enabled this transition.

{% youtube kbtvX8JUwYQ %}
How to Boost Your Team’s Happiness through Transparency

Tags: productivity
Published: 2021-07-13 10:17:03

Positive work culture is essential for higher productivity and motivated employees. Here, business transparency plays a vital role in developing positive work culture. It can enhance teamwork in the workplace. In other words, a lack of transparency can affect the performance of employees and the bottom line of your company. 

In this blog, we are going to give four essential steps to boost transparency, thereby increasing happiness in the workplace. 

<h2>Top Tips to Enhance Transparency of Team Work in The Workplace</h2>
<h3>1. Sharing Time and Schedules</h3>
A teamwork in the workplace team management software can keep all the employees on the same page for every project and all the tasks. A few years back, calendars were used for storing and managing tasks. Today, evolving technology has brought a robust team task management tool that has many user-friendly features. Such a tool facilitates your employees to share their time management for nurturing transparency. It is fair to mention that viewing the co-worker’s schedules can help your employees manage their time more effectively and stay motivated. 

Sharing schedulers can also contribute to taking away stress related to tasks completion and increase the happiness of the company. Sharing time management can improve collaboration. All you need to do is use team task management software to enable all the team members to check the tasks of one another. 

<h3>2. Using Task Management Software</h3>
A project management tool or task management software can make the task visible visually. Unlike traditional to-do lists, such visual management tools can make communication more effective by using a centralized platform. Such real-time communication can make tasks easier and enhance collaboration. Effective planning and delegation of tasks for every team member can enable your teamwork in the workplace to achieve key objectives. 

Many team task management tools keep on updating in real-time during meetings. They have built-in communication tools that leave no room for miscommunication when it comes to meeting deadlines while addressing challenges. Be it task monitoring or managing, the project tracker tool always remains handy. It can make all monotonous to-dos or complex tasks more manageable and achievable. It not only enhances transparency but also increases happiness and satisfaction levels at the workplace. 

<b>Original Source : <a href="https://www.taskopad.com/blog/teamwork-in-the-workplace/">How Transparency Enhances Your Team’s Happiness at Workplace</a> </b>
Why a Diverse Team is Crucial to Startup Success
Tags: diversity, inclusion, people, technology
Published: 2021-07-13 10:15:31

**This post was originally published on Tue, Jul 6, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/diverse-team-crucial-to-startup-success/).**

Team diversity refers to differences between members of startup team. Those differences can include demographic differences (like age, race, sex, ethnicity), personality (extrovert, introvert, and differing Myers-Briggs types) and functional (as in skill sets, like engineering, design, copywriting, and marketing).

How does team diversity impact your customers' experience from the moment they learn about you through their journey with you? You will attract and relate to customers how look like you. They will understand your messaging and you will understand their needs. If you don't represent the right dimensions of diversity, you are leaving an amazing experience behind.

{% youtube LnMZsNidlCM %}
41 - DevOps on Azure
Tags: traefik, devops, containers, azure
Published: 2021-07-13 10:11:17

**This post was originally published on Fri, Jul 2, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/devops-on-azure/).**

In this episode, Chris is joined by Mert Yeter, a software engineer with 16 years of experience in .NET and Microsoft technologies. We'll be talking all things DevOps on Azure, including Azure Container Registry, Azure Container Instances and Azure Kubernetes Service. We'll also get a chance to talk about Traefik and how it's pluggable middleware can help you with your Kubernetes ingresses! Tune in to find out more!

{% youtube 1xyBUj72Uh4 %}
Top new CNCF projects to look out for
Tags: cloudnative, kubernetes, cloud, opensource
Published: 2021-07-13 10:09:21

**This post was originally published on Wed, Jun 30, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/top-new-cncf-projects/).**

The Cloud Native Computing Foundation (CNCF) brought you such fan favourites like Kubernetes & Prometheus. In this talk Annie Talvasto will introduce you the most interesting and coolest upcoming CNCF tools and projects.

This compact and demo-filled talk will give you ideas and inspiration that you can 1) discover new technologies and tools to use in your future projects as well as 2) be the coolest kid in the block, by being up to date with the latest and greatest.

{% youtube V2z1NhNWdVc %}
ansible create empty file if it does not exist
Tags: ansible
Published: 2021-07-13 10:08:24

```
- name: Touch again the same file, but do not change times this makes the task idempotent
  ansible.builtin.file:
    path: /etc/foo.conf
    state: touch
    mode: u+rw,g-wx,o-rwx
    modification_time: preserve
    access_time: preserve
```
Auto-reset environment variables when testing in Go
Tags: go, testing, programming
Published: 2021-07-13 10:02:42

During the testing, one of the hardest parts is to make tests isolated from others. And when setting environment variables in tests, they must be reset to original values. But developers must do it on their own.

> 🇨🇿 V češtině si lze článek přečíst na [kutac.cz](https://www.kutac.cz/pocitace-a-internety/testy-v-go-a-environment-variables) 

--- 

Sometimes there is a need to set environment variable directly in the test. And tests should do **clean-up** after themselves, to not affect others. So also env vars should be reset to the original value, or deleted.

## Helper and `t.Cleanup()`/`defer`

In Go, it can be done with a simple **helper**, which will return a callback. Which is called with t.Cleanup() in Go 1.14+ or with `defer` in older Go versions.

```go
func envSetter(envs map[string]string) (closer func()) {
	originalEnvs := map[string]string{}

	for name, value := range envs {
		if originalValue, ok := os.LookupEnv(name); ok {
			originalEnvs[name] = originalValue
		}
		_ = os.Setenv(name, value)
	}

    return func() {
		for name := range envs {
			origValue, has := originalEnvs[name]
			if has {
				_ = os.Setenv(name, origValue)
			} else {
				_ = os.Unsetenv(name)
			}
		}
	}
}
```

### Usage

```go
func TestFunctionWithEnvVars(t *testing.T) {
	closer := envSetter(map[string]string{
		"MY_ENV_VARS":         "with some value",
		"MY_ANOTHER_ENV_VARS": "again with some value",
	})
	t.Cleanup(closer) // In Go 1.14+
	// defer closer() // Prior Go 1.14
	// ...
}
```