teleren/devto huggingface dataset:
Comparing switch-like operators in 14 different programming languages
Tags: programminglanguages
Published: 2021-09-11 10:00:22

---
title: Comparing switch-like operators in 14 different programming languages
published: true
description: 
tags: programmingLanguages
//cover_image: https://direct_url_to_image.jpg
---

We are going to look at Javascript, Typescript, Java, C#, Swift, Objective-C, Python, PHP, Ruby, Kotlin, ReasonML, Dart, Go and Elixir.

At Avo (avo.app) we work with 12 languages, and I decided to do a series of quick comparisons of those languages, plus 3 languages we are going to support soon.

First feature we are going to look at is the switch-like constructs. We are interested in 3 features related to switches - ability to use switch as an expression (so it returns a value), whether the switch construct is exhaustive (you need to handle all cases to compile the code) and if the fall-through logic disabled (so you don't need to break out of each case explicitly).

Language | has switch expression | is exhaustive | no need to break | reference
--- | --- | --- | --- | ---
javascript | limited, only if wrapped in a function https://stackoverflow.com/a/55944296 | - | - | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
typescript | limited, only if wrapped in a function | limited http://ideasintosoftware.com/exhaustive-switch-in-typescript/ | - | same as JS |
java | starting java 12 | expression is, statement is not                 | additional syntax starting java 12 | https://openjdk.java.net/jeps/354 |
c# | starting C# 8.0 | - (expression will give a compile warning) | need to break in the statement | https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression |
swift | - | + | + | https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html |   
objc | - | + | - | 🤷‍♂️ | 
python | no switch in python :) | | | |
php | called match, introduced in php 8 | match is, switch is not | match , switch is not | https://www.php.net/manual/en/control-structures.match.php | 
ruby, called `case` | + | - | + | https://ruby-doc.org/core-3.0.1/doc/syntax/control_expressions_rdoc.html#label-case+Expression |
kotlin, called when | + | expression is, statement is not | + | https://kotlinlang.org/docs/control-flow.html#when-expression |
reasonml/rescript | + | + | + | https://rescript-lang.org/docs/manual/latest/pattern-matching-destructuring#switch-based-on-shape-of-data |
dart            |            -     |             +    |             - |  https://dart.dev/guides/language/language-tour#switch-and-case |
go        |                  -       |            -    |               + | https://tour.golang.org/flowcontrol/9 |
elixir          (called case)  |         -   |              - (runtime error CaseClauseError) |               +    | https://elixir-lang.org/getting-started/case-cond-and-if.html#case |
My attempt at creating a unique portfolio website!
Published: 2021-09-11 09:54:28

---
title: My attempt at creating a unique portfolio website!
published: true
date: 2021-09-11 09:48:37 UTC
tags: 
canonical_url: https://livecode247.com/my-attempt-at-creating-a-unique-portfolio-website
---

I created my portfolio website a few months ago and tried to make it as unique as possible and came up with the idea of a terminal based website. You can find it [here](https://kavin.me). It takes in a command (you can list all commands you can use by typing `help` and then typing the command) and displays an output much like a proper terminal. I used HTML, CSS, and Vanilla Javascript which I regret sometimes because of how hard it is to maintain now. I might add Parcel later to make it easier to bundle the code. But for now it's how it is and you can find the code in the Github Repo below!

> Update (26/10/2021): The website is now made using NextJS

[https://github.com/kavinvalli/kavinvalli.github.io](https://github.com/kavinvalli/kavinvalli.github.io)

Oh, there is also a normal mode on the website if you don't want to use the terminal mode. I'll love some feedback on the website and drop your portfolio links below too!

I also later created a normal design website which can be found [here](https://n.kavin.me) and the code for that is in this repo:

[https://github.com/kavinvalli/normal-website](https://github.com/kavinvalli/normal-website)
Abstraction in Python
Tags: python, abstraction
Published: 2021-09-11 09:14:03


## Abstraction
In software Engineering,  abstraction means the act of hiding irrelevant classes from users to reduce complexity. This means that users can create some functions without worrying about how they work. They know what the function does but they don't need to know the logic behind it. Let's look at our smartphones for instance we can use the camera to take pictures, but we know don't the operations that are happening in the background while taking the picture.

In Python, we can achieve abstraction by using abstract classes and interfaces. You may be wondering, what is an abstract class?  It is any class that contains at least one abstract method and cannot be instantiated, but can be subclassed. An abstract class is useful when designing large functions and it also provides large interfaces for the implementation of components. Let's create an abstraction in python using the abc module. 

## Code
```
from abc import ABC, abstractmethod

class Shape(ABC):
    # abstract method
    @abstractmethod
    def sides(self):
        print('This is the main class')

    def normal(self):
        print('This is a normal class')


class Triangle(Shape):
    def sides(self):
        print(' Triangle has 3 sides')


class Square(Shape):
    def sides(self):
        print(' Square has 4 sides')

t = Triangle()
t.sides()
t.normal()

s = Square()
s.sides()
s.normal()
```

## Output
```
Triangle has 3 sides
This is a normal class
Square has 4 sides
This is a normal class

```
## Explaination
We created the abstract base class Shape using the ABC module that was import from Python, and also created an abstract method sides(). The Triangle() and Square() classes inherited the base class  and have their own side() methods. The  were created and the sides() methods was invoked, The sides() methods, hidden definitions were activated when the user creates the Triangle() and Square() objects and invoked the sides() method. The sides() method defined in the Shape() class in never invoked, while the normal() method is invoked because it is not an abstract method.

## Conclusion
Abstraction is important whenever we want to hide core functionalities from users.  An abstract class can contain both a normal method and an abstract method. We noticed that abstract method in the abstract class are never activated while the normal method was activated.
Yet another portfolio - 12th attempt
Tags: portfolio, javascript, webdev, gatsby
Published: 2021-09-11 09:10:36

Hello everyone, 

I love working on my portfolio, I know it sounds narcissistic, but the truth is that it is the subject I know the best, and it is always a bit of introspection and self-knowledge when I do this exercise,  kind of like a therapy. 

Redoing my portfolio has always been a way to put one foot into a new web technology. My first portfolio was 10 years ago, using only HTML and CSS. Needless to say it looked pretty basic. 
Then I remember doing a second version with JQuery, and anoter one with a custom design, one using PHP, etc... Every iteration was a learning. 

Last year, I worked on a new version of my portfolio after few weeks of designing it through Figma, I started coding while having in mind that this would be a long-term one. I wanted to get familiar with the concept of animation and minimalism. I wanted that website to be unique and soft, while telling my story.

To anyone who wants to learn something new in web development or design in general, I highly recommend to do a portfolio.

Hope you will enjoy my twentieth take on it: https://thomasmorice.com
Cheers
Do you consider yourself a rockstar developer?
Tags: career, productivity, discuss
Published: 2021-09-11 08:53:01

Rockstar, unicorn, ninja, 10x developer... Do you think you made the cut to the developer elite yet and how do you know?

Or maybe you consider these labels a dumb way to call a person who works more for less pay?

What's your ultimate career goal if you have any? 

What do you do to get better or is just doing your job enough for you?

What's your definition of the perfect developer you would want to be?

I believe in evolution of skills and character and would really want to know your ways of getting a little bit better everyday.
Optimizing GoLang Package
Tags: go
Published: 2021-09-11 08:50:42

---
title: Optimizing GoLang Package
published: true
description: Memory and CPU Optimization
tags: golang
//cover_image: https://direct_url_to_image.jpg
---
I made a GoLang package which serializes Json from Structs. The package is [here](https://github.com/j0nimost/jstra). I have an open issue, where I am trying to optimize the library. Find the issue [here](https://github.com/j0nimost/jstra)
Ruby Single Table Inherency (STI)
Tags: ruby, rails, database, activerecord
Published: 2021-09-11 08:49:50

From a personal experience, In a recent interview for a rails developer position, i was asked to implement something simple but tricky. eg:

"We need an application to create a post, comments, and replies with only two tables, how will you approach it." 
- All i could think of was creating a boolean column in comments table to trigger replies. After the session, the interviewer gave me a straight tip on what he expected and that's single table inheritance(STI).
- We've **'Posts table'** and **'Comments table'**, after generating our models and migrating, we can create another class  'Replies' to inherit from 'Comments'. eg 

**Post model**
```
Rails generate model post title:string
```

above we generate a model `Post` with a title column.

**Comments model**
```
Rails generate  model comment title:string type:string
```
above is a comments model with title and type, you might be wondering why type? well, we need a column to hold replies type. creating a reply will be saved as a type. 

let's generate a replies model.
```
Rails generate model reply --parent=Comment
``` 
Yes, about the flag used `--parent` a normal model inherits from active record by default but here we want our model to inherit from `Comment` model, adding the flag generate something like this 
```
class Reply < Comment
end
```

we can comments and replies 
```
# comment
comment = Comment.create(title: "hello comment")

reply
# reply = Reply.create(title: "hello title")
```

Reply SQL looks like 
```
INSERT INTO "comments" ("type", "title") VALUES ('Reply', 'hello title')
```
You should always try to avoid Single Table Inherency(STI), it makes models associations complicated
When to use static and when not to in C#
Tags: csharp, dotnet
Published: 2021-09-11 07:36:42

In the last post I talked about static keyword. Today I will write about the usage of static. I recommend first read that [article](https://dev.to/shariaretanvir/all-about-static-in-c-4me5) where you can get a brief idea about static before read this article.

**When to use static in C#**

1.	Static provide an easy way to call methods and fields.
2.	Method which doesn’t work differently for different objects can be used as static.
3.	App configuration class can be a good example for static class/methods. Because it stays same throughout the application.
4.	Database Connection string is another good use case of static method.
5.	Static members make code cleaner.
6.	Mainly utility kind operations should be mark as static.


**When not to use static in C#**

1.	Static hinders unit testing.
2.	Static missing OOP concepts including abstractions.
3.	Do not use static when the class or field is going to change according to caller class.
4.	Async or multithreading sometimes conflicts with static, mostly if someone mark data access layer as static(which is not recommended)
My first freelance job part 3
Tags: html, css, javascript, webdev
Published: 2021-09-11 07:19:46

As I have been telling in previous posts I had a bad experience in my first job as a freelancer and this was because the deal with the client was led by a third party (a girl who contacted me on facebook).
To put it in context:
The story starts when this girl contacts me to help her with a school project, I non-profit helped her in her project.
A month later she contacts me offering me to do a real project for the company on which she had based her school project, because they liked the design.
So I started with the project but I never got any economic remuneration ... a month after the delivery (about three days ago) I decided to send mail to the company to tell them why his page had never been published and the delay of the same emphasizing the lack of economic remuneration.
The next morning I received a call from the company where they informed me that they had already covered 80% of the project for a month ago (what I had charged from the beginning), because this girl had charged even more (so the company still owed her money), that's right ! the girl had already charged and had not paid me !!!.
I reported the situation to the person at the company and they decided to sue the girl for breach of contract, I received a call from her claiming that I had communicated with the company and she offered to pay me the amount that I had charged (even knowing that she charged more, she never told me).
But well I no longer wanted to have any contact with her so I told her that I was aware of the fraud she had done and that I wished her good luck in her legal process, stressing that there was no rancor on my part because they were difficult days for me (eating only once a day for lack of money because I lost my job and my apartment as a result of being able to finish this project in a timely manner).
-----THE GOOD NEWS.-------
After talking with the representative of the company they offered me to pay the page and today I received MY FIRST PAYMENT FOR A WEBSITE made by me !!! and they also offered me a possible second project (this is waiting for authorization).
Now I have direct contact with the company and I am happy to work in what I like in a "formal" way, for the first time !!! !!!
For the hiring of my services I have relied on a contract and I hope that everything goes well.
PS; This is undoubtedly a clear example that your quality of personal values can lead you to a good job or to a legal problem from which you will not get out well.
I hope you like this experience that I am glad to share with all of you !
greetings and blessings to all of you !!!!
How to Create React Multi Language Website Using i18Next
Tags: react, i18next
Published: 2021-09-11 07:15:45

Today, we will show you how to implement multi-languages in React. Sometimes you may need to add multi-language support to a website or a react web application like English, Chinese, etc.

In this article, we’ll use the react-i18next internationalization framework for React App which is based on i18next.

https://www.codecheef.org/article/how-to-create-react-multi-language-website-using-i18next
VS Code Shortcuts every developer should know (Windows)
Tags: vscode, microsoft, shortcuts, programming
Published: 2021-09-11 06:54:58

Who doesn't want to speed up their work? Especially developers. They love shortcuts. And here we are back with some very useful shortcuts for developers when using VS Code in Windows.

P.S. Since this article is to make dev life easier, I have decided to keep it crisp.

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

## Add a Comment
ctrl + /
## Moving a line up or down
alt + up arrow/down arrow
## Cut an entire line
ctrl + x
## Copy an entire line
ctrl + c
## Quickly open a file
ctrl + p
## Move to a desired line number
ctrl + g
## Move to any file within the project
ctrl + e
## Hide/Show Side bar
ctrl + b
## Select the current line and move cursor to next line
ctrl + l
## Show/Hide the terminal
ctrl + j
## Select and Edit multiple lines
alt + cursor
drag middle mouse key
## Search any word
ctrl + f
## Search & Replace any word
ctrl + h
## See previous selections/cursor movements
ctrl + u
## Quickly close a file
ctrl + w
## Switch between sidebar services
ctrl + q
## Open current folder in browser
alt + l + o
Search Layouts, List Views, & Field Dependencies
Tags: database, cloud, codenewbie, computerscience
Published: 2021-09-11 06:31:59

In the previous articles of my Salesforce Admin Series, I've talked about Objects, Database tables, Relationships, & Data Modelling. If you've read the previous parts, I bet you now know what Salesforce does and how to edit, view records in Salesforce.

If you don't, sit relaxed and keep reading the articles. I'll post a video stating all the basics and go through of Salesforce!

There are certain types of layouts and viewing options available in Salesforce.

#Search Layouts
Salesforce gives you the functionality to customize the display of fields in search results. This feature is called Search Layout. It allows you to customize the search results, lookup dialogs, and recent lists on any tab.

Search Layouts are ordered field groups that are displayed when you try to present a record in a particular context. It consists of the following - 

###Search Results
It originates when you search for a record using the search panel on the left sidebar. It also considers the advance search feature.

###Lookup Dialogs
The results that pop up on clicking next to the lookup field are called the Lookup Dialogs.

###Object Tab
When you click on a tab, you see some records that have been used recently. You can switch between 'All' & 'Recent' as you like.

#List Views
Also called the object list view. This layout does not pick fields specifically. Instead, it is used to specify the buttons that you wish to appear on the list view.

Not many people use this tool. But it gives you the power to see exactly the segments you want to see. Say you want to sort your records based on just one field. What'd you do? Generate reports!

There is a short way! List views. Specify the field, and you'll have records according to your need at the tab home. List view is one of the most underrated yet cool tools of Salesforce.

#Field Dependencies
The term field dependency in Salesforce means controlling a field value in accordance with another field. For example - say a standard object has fields - City & State. 
You choose a state, and the city column shows the cities of that state only. This is where field dependency works.

###Some Pointers - 
1. The value selected in the controlling field affects the values available in the dependent field.
2. A dependent field works in conjunction with a controlling field to filter its values.
3. We can define custom picklist fields as controlling or dependent fields.
4. Standard picklist filed must be controlling fields. We cannot define standard picklist fields as dependent fields.
5. We can define default values for the controlling field. But we cannot define default fields for dependent fields.
6. We cannot define multi-select picklist as controlling.
7. We can define a checkbox as a controlling field only.

Sources - 
https://www.salesforcetutorial.com/field-dependency-in-salesforce/
https://shreysharma.com/search-layouts/
Merging Two or More Arrays in JavaScript
Tags: javascript
Published: 2021-09-11 06:28:06

There often comes a time in JavaScript when you need to combine two or more arrays.

I'll begin with a basic example, demonstrating how you can easily combine just two arrays into one:

```js
const arrayOne = [1, 2, 3];

const arrayTwo = [4, 5, 6];

const mergedArray = arrayOne.concat(arrayTwo);
```

In this example, `mergedArray` will return `[1, 2, 3, 4, 5, 6]`.

## Merging multiple arrays

We can also use the `concat()` array method to merge more than two arrays together:

```js
const arrayOne = [1, 2, 3];

const arrayTwo = [4, 5, 6];

const arrayThree = [7, 8 , 9];

const mergedArray = arrayOne.concat(arrayTwo, arrayThreee);
```

And in this example, `mergedArray` will return `[1, 2, 3, 4, 5, 6, 7, 8, 9]`.

What's nice about `concat()` is that it uses a [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax), so you can pass in as many parameters as you want, and they'll all get sequentially merged.

## Removing duplicate values

Sometimes when merging arrays, you'll want to dispose of duplicate values.

Here's a quick snippet that'll do just that:

```js
const arrayOne = [1, 2, 3, 4, 5];

const arrayTwo = [4, 5, 6, 1, 2];

let mergedArray = arrayOne.concat(arrayTwo);

mergedArray = mergedArray.filter((item, i) => mergedArray.indexOf(item) === i);
```

In this example, `mergedArray` will return `[1, 2, 3, 4, 5, 6]`, the aggregate of `arrayOne` and `arrayTwo` in order and without any duplicates, as expected.

## Conclusion

There's other ways to go about merging your arrays, but I've always found `concat()` to be the most practical.

I hope you enjoyed this quick little tutorial! Thanks for reading.
Hide a file / folder using Golang
Tags: go, linux, windows, webdev
Published: 2021-09-11 06:21:46

Recently, one of my clients is requesting me to develop a web system that runs on Windows (instead of Linux). What they thought is that they don't need to hire an IT guy to do the daily maintenance and they can fix / update the system even without much technical knowledge in the field. 

As I am a "nice" developer, I say "sure", but the next things I am thinking is: How do I hide all the files that should not be touched securely? After some Googling, I decided to hide all the system generated files using Windows API. I also want to keep the Linux compatibility of the system (just in case they hire an actual IT guy later and decided to migrate to Linux), so I made this simple Go Module to get the job done.

{% github tobychui/goHidden %}

Here is a basic example usage of the module.
```
//Hide a folder
err := hidden.HideFile("./test")
if err != nil {
	panic(err)
}

//Check if a folder is hidden
isHidden, err := hidden.IsHidden("./test", false)
if err != nil {
	panic(err)
}
```

It is licensed under MIT, for anyone who needs it, feel free to use it in your projects :)
Create a Netflix clone from Scratch: JavaScript PHP + MySQL Day 47
Tags: php, javascript, webdev, tutorial
Published: 2021-09-11 05:51:40

Netflix provides streaming movies and TV shows to over 75 million subscribers across
the globe. Customers can watch as many shows/ movies as they want as long as they are
connected to the internet for a monthly subscription fee of about ten dollars. Netflix produces
original content and also pays for the rights to stream feature films and shows.

In this video,we will be  Creating mute and unmute functionalities
{% youtube 01wvSu7HDUg %}

In this video,we will be  Changing the icon on mute and unmute button
{% youtube jA5m9gJarYk %}



If you like my work, please consider
[![Buy me a coffee](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jm11knj7d8zwcvo150q2.png)](https://www.buymeacoffee.com/cglikpo)
so that I can bring more projects, more articles for you

If you want to learn more about Web Development, feel free to [follow me on Youtube!](https://www.youtube.com/c/ChristopherGlikpo)