teleren/devto huggingface dataset:
Understanding scope in Golang
Tags: go
Published: 2022-10-17 19:47:20

---
title:Understanding scope in Golang
published: true
description: A deep dive into how scope works in Golang
tags: go, golang
cover_image: https://res.cloudinary.com/morelmiles/image/upload/v1666025831/pexels-pnw-production-8997867_xzywfl.jpg
---
> This article first appeared on my personal website [https://luigimorel.co](https://luigimorel.co/blog)

### What is scope?

Scope can be defined as the current context of execution in which values and expressions are "visible" or can be accessed within a program.
If a variable or expression is not in the current scope,it will not be available for use by other parts of the program.

There exists two types of scope in Go:

### Local scope

Local scope is achieved when a variable is declared inside a function body. Such variables are said to have local scope _thus_ (within the function).
They can not be accessed outside of the function.

These types of variables are called local variables. For example,

```go
package main
import "fmt"

func printNumber() {

 b := 2

}

func main() {

printNumber()

// b is inaccessible
fmt.Println("Value of b is", b)

}
```

### Global scope

When a variable is declared outside of a function body, it possesses a global scope. Such variables are know as _global variables_.
They can be accessed from any part of a program.
For example,

```go

package main
import "fmt"

var x string

func printString () {

x = "This is a string"

}


func main() {

  printString()

  fmt.Println("Value of x is", x)

}
```

### Why is scope important in a program?

- Scope helps to prevent mutation of assigned values during the lifetime of a program which helps avoid unneccessary bugs in a program.

### What happens if a variable has the same name in both the global and local scope?

If we have local and global variables with the same variable names, the compiler gives priority to the local variable.
For example,

```go
// Program to illustrate the priorities of variables

package main
import "fmt"

// define global variable
x  := 10

func main() {

 // define local variable with same name
  x := 30

  fmt.Println(random)
}

```

### Output

```go
30
```

### Resources

- [https://golangr.com/scope/](https://golangr.com/scope/)
- [https://developer.mozilla.org/en-US/docs/Glossary/Scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope)
- [https://go.dev/doc/](https://go.dev/doc/)
MindsDB Hacktoberfest2022: Win a Cash Prize
Tags: mindsdb, hacktoberfest, opensource, machinelearning
Published: 2022-10-17 19:24:13

### Looking for an Opensource Github Repository to contribute to?

[MindsDB Hacktoberfest](https://mindsdb.com/hacktoberfest) provides opportunities for everyone to contribute and stand a chance to win a cash prize.

For this year's MindsDB Hacktoberfest there are 3 categories to participate in, one is submitting an idea for MindsDB Integrations. This is a great and easy way for you to participate in Hacktoberfest!

**How to enter and win a cash prize:**

- Share a well-described idea of a new MindsDB integration on [MindsDB's Github Repository](https://github.com/mindsdb/mindsdb/issues?q=is%3Aissue+is%3Aopen+label%3Ahacktoberfest).

- Invite people you know to upvote your idea.

- The top 3 authors, whose ideas will get the highest number of upvotes, are the winners. If multiple ideas have the same number of votes, the first one posted wins.

- You can submit as many ideas as you like. However, we will not sum up upvotes from multiple issues from a single author. We’ll take just one that has the highest number of votes.

**The top 3 authors will receive a cash prize:**
- The first place gets $500 cash prize, plus MindsDB t-shirt, plus audio gadget.
- The second place gets $300 cash prize, plus MindsDB t-shirt, plus audio gadget.
- The third place gets $200 cash prize, plus MindsDB t-shirt, plus audio gadget.

[See Rules](url)

Rewards will be paid as one-time [GitHub sponsorship](https://docs.github.com/en/sponsors/receiving-sponsorships-through-github-sponsors). Each winner can choose one of the gadgets ([JBL Earbuds or Rugged Outdoor Speaker](https://res.cloudinary.com/practicaldev/image/fetch/s--6Frk-K9i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uo5zdu3wkvfc2mw8hww3.png))

We will announce the winners on our Community Slack during the first week of November.
Moving Student Sprites
Published: 2022-10-17 19:18:46

Some slow progress while I find time to work on this game in between being a dad and sleeping! 

Sprites for the students/"lemmings" are now moving:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7kyyst206dvhuuagcwi.gif)

Since all of the students are on the same layer, they look funny when they pass through each other. I am going to resolve this by making the left moving students on a slightly different Z axis than the right moving students. This is how I also plan to handle staircases - two 3d sloped surfaces in a single room stacked on top of each other with a landing separating them.

The next area that I'll be working on will be for handling doors and openings in the floor. I initially thought that I would be able to "subtract" a cube object from the room walls to make an opening, but I haven't found anything that would indicate that this is possible with the objects that I am importing from Blender. HOWEVER I learned a little about layer masking while making the students able to bounce off the walls but not collide with other students. I think that I will be able to temporarily turn off layer masking for the layer that a wall or floor is on when the student touches an invisible object to temporarily allow a student to pass through as if there is an opening there. This will let me make students that have an ability (like hammer?) to create holes in the floor or wall and let other students through. That seems like it would work for the physics/collisions. To make it _look_ like a hole maybe I'll be able to do something with image masking on the material in code to put a transparent spot in right location.
¿Cómo podemos mantener directorios vacíos en git/github?
Tags: git, github
Published: 2022-10-17 18:52:50

**Tenemos la siguiente situación:** Estamos armando la estructura de nuestro proyecto en git, carpetas y sub carpetas, muchas de estas vacías, pero que a futuro serán llenadas con los archivos del proyecto. 
Cuando queremos subir el repositorio a github nos encontramos con la sorpresa de que ¡toda carpeta vacía desapareció!
Lo que sucede es que **git solo añade archivos al stage y cualquier carpeta vacía será descartada.**
Si no queremos agregar en ese momento los archivos que estarán en esas carpetas, **podemos crear un archivo vacío llamado** `.keepgit`, **de esta manera conservaremos la estructura de nuestro proyecto sin mucho problema.**
Algunas veces este archivo tendrá el nombre de `.keep`, por lo que es bueno saberlo si estamos explorando repositorios ajenos. 
Algunos sugieren que es mejor usar `.gitignore`, lo "malo" de esta solución es que podemos llegar a confundir a las personas que tengan que trabajar con el proyecto, ya que .gitignore tiene otra función.
3 React tips you should know to become a better engineer
Tags: react, tip, beginners, javascript
Published: 2022-10-17 19:05:14

When learning React its normal to focus on the more pressing topics like components and rendering those components so its not unusual that when pushing something for production you might set aside somethings that at the time you felt that were not so important for your application. That being said in this article I’m gonna talk about three React “Hidden” tips and when you should use them.

1. Key prop

I’m sure that at some point in time when you we’re building an app and opened your console you received the warning below

`Warning: Each child in a list should have a unique key prop.`

And thought to yourself “Damn I forgot to pass the map index as a key” and I’m here to tell you why you shouldn’t be doing this.

Well for starters this is what React already does by default, so when you pass the index as a key you’re really not doing anything you’re just shutting off the warning but the problem remains.

And the problem is that React has a hard time keeping track of elements between updates so that’s why you should pass a unique key when rendering from an array of items like an id that comes from your backend.

To illustrate this problem you can click on the fruits at this [**demonstration**](https://react-fundamentals.netlify.app/isolated/final/07.extra-1.js) by the amazing Kent C. Dodds.

2. Lazy initializing

When using React built-in Hook useState is quite common that we pass an initial value to it but in some cases this initial value can be computationally expensive like getting a value from localStorage for example

And we might just need this value one time so to keep doing this computationally expensive operation every re-render is a big nono.

So in this case we turn the localStorage access into a function and pass its declaration as the initial value of useState and then this function will only be called on the first render of the component.

This will be called at every re-render.

`const [value, setValue] = useState(localStorage.getItem("key"))`

This will only be called at the first render.

`const keyGetter = () => localStorage.getItem("key") 
const [value, setValue] = useState(keyGetter)`

3. React Dev tools

The third tip its not in react per se but if you use correctly it will drastically improve your coding experience.

React Dev tools is a great chrome extension that makes way easier to analyze your React application you can get details like props,hooks,state,components and see the reason behind a component render so it makes debugging more efficient.

After you install it it will appear at your browser’s developer console.

That’s all for today folks, Thank you so much for reading it, and I just want to make it clear that in spite of the title there is no tip in the world that you make you into a better engineer overnight, this might seem obvious but if you don’t understand something that you’re doing stop and study it because knowledge also has a compound effect to it and it’s dividends are huge.
Emojis for your Project
Tags: discuss, beginners, programming, tutorial
Published: 2022-10-17 19:04:04

**How to type emojis in your projects?**

> On Mac:

Command + Control + Space

This is the default shortcut to bring up the emoji keyboard. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d2ur3k0z29bnmtkmmd3s.png)

> Access Emoji in Windows 10 Using Keyboard Shortcut

Put the cursor in any text field you’d like to insert an emoji. This could be Microsoft Word, Chrome, or Notepad app.

Press the WIN + . (full stop) keyboard shortcut, or else the WIN + ; (semicolon). Either will open an emoji picker over the text field.

Also use - [Unicode Emoji Table](https://unicode-table.com/en/emoji/)

What are the other ways that you use for adding an emoji?
Ensure a beaut code with Laravel Pint
Tags: laravel, php, programming, webdev
Published: 2022-10-17 18:44:19

Hello,

This is my first full English post! So, I'd starting with "sorry" for my wrongs, I'm learning :)

If you, like me, has Laravel inside your world and like beautiful things, I think you need to meet the Laravel Pint.

Laravel Pint help us to keep a good code style.

Working in one team without some code styler or some texteditor settings, usually we need to check a lot of spaces changes, breaklines, positions in the Pull Request review. It's so bad and sad to review one big PR with a lot of 'non-necessary-changes'.

To solve this, we can setup the default code style for everyone of the time, this make more easy to check codes from other person and improve the PR Review moments.

With `Laravel Pint` is so easy setup a one default way to this, without extra settings like with pure PHP-CS.

Let's install de Pint with the normal command:

```
composer require laravel/pint --dev
```

After installation, you can just run:
```
./vendor/bin/pint 
```

At the first time, you can see a lot of files changes, like in this my personal hobby project:

![Changes after run command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzakuzy0goznqxufrqh9.png)


Of course, in this simple way, you will need run the command before commits to ensure a correct code style. We can improve this we can to use some `pre-commit` hook, like a `grumphp` https://github.com/phpro/grumphp.

In other post, I can write more about `grumphp`, but if you want, you can check the oficial docs to learn more.

For today it's only, thanks for read! :)
When AI plays Tic Tac Toe
Tags: algorithms, minimax, ai, python
Published: 2022-10-17 18:33:41

I remember the first time that I was playing Tic Tac Toe with a non-human, I really had no idea how it works or how it knows what moves to make to prevent me from winning the game.

My answers to this question were hilarious at the time; but then, after some time, I found that this is just a simple algorithm which never led me beat it. 

The algorithm is called _**MiniMax**_.

## MiniMax
**MiniMax** isn't just for Tic Tac Toe game, in fact it's a very cool algorithm which we can use in any match where there is an opponent in front of you and is acting _against you_.

The theory behind the MiniMax algorithm is to predict the opponent moves or thoughts, which are obviously beneficial for her/him and then choosing the best move based on your prediction.

_The best move should be both to your advantage and to your rival's disadvantage._

## Tic Tac Toe

![iceXO tic tac toe game minimax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zu7h2bu9l6hm4v5kohgs.gif)

The first step of the process is to predict all possible actions after a player makes any moves.

![tic tac toe predicting actions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9zu0c0clagqij2qnp8r.png)

We continue this process till the game overs. You'll see it makes a _recursive function_.


![tic tac toe predicting actions minimax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kkshrjs3tuwdfomt4yoz.png)

_To understand this picture better, at first we should specify a score for each position of the game board._

-1: O wins
0: No one wins
+1: X wins

And then, please consider player O and player X as min player and max player.

1. Min player: Chooses the minimum score 
2. Max player: Chooses the maximum score

For instance if we have 3 possible options on the board which the scores are [0,-1,-1] X player will choose **0** and O player will choose one of the **-1** options.

Now, that we know the final score of each action on the board (by continue filling it out) we can easily choose between the scores based on which player is acting as AI player.

---

If you're interested in this algorithm and Tic Tac Toe game, you can take a look at [This GitHub Repo](https://github.com/Atena-d/iceXO) which I covered MiniMax algorithm in an interesting Tic Tac Toe game, in both JavaScript and Python languages.
How to get better tabs in Firefox UI (on Mac)
Tags: browsers, firefox, css
Published: 2022-10-17 18:31:52

Yes, the tabs in Firefox suck, they look like pills (or buttons) and look horrible, right?

This is how I styled them to look a little more visually pleasing:

![Gif of how the tabs look with the below styles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfhg0wnlr8zaarngbtw2.gif)

![Screenshot of a few tabs.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wi1d99cdus02v0qptbc8.png)


Edit `/Users/<username>/Library/Application Support/Firefox/Profiles/<your profile>/chrome/userChrome.css` and add the following:

_Note, you should know where this file is. If you don't, Google it and come back here._

```css
.tab-background {
	border-radius: 0 0 3px 3px !important;
	border-top-right-radius: 0 !important;
	border-top-left-radius: 0 !important;
	margin-right: 0 !important;
	margin-left: 0 !important;
	margin-bottom: 0 !important;
	margin-top: 0 !important;
}

.tabbrowser-tab:not( [selected=true] ):not( [multiselected=true] ) .tab-background {
	background-color: color-mix( in srgb, currentColor 10%, transparent);
}
```

I am using [this theme](https://addons.mozilla.org/en-US/firefox/addon/macos-monterey-safari-dark/), curious how this looks in other themes.

Also, please let me know how this works on Windowz!
Host and deploy your website to AWS Amplify within one minute
Tags: aws, cloud, devops, webdev
Published: 2022-10-17 18:27:34


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pj09uy4iiue8ljih5hm.png)
"Easily deploy your web app or website to the fast, secure, and reliable AWS content delivery network (CDN), with hundreds of points of presence globally."

👉🏻Let's Start

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e0ljri79kbpc2hwiogi.png)

1.Choose **Get started** under **Deliver**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwmx9mvzw63nypejiq4m.png)
2.If you are starting from the All apps page, choose New app, then Host web app in the upper right corner.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgfp89e4e8p8ehkz7wnc.png)

**Step 1: Connect a repository**
Connect your **GitHub**, Bitbucket, GitLab, or AWS CodeCommit repository. **You also have the option of manually uploading your build artifacts without connecting a Git repository.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9w5ht17u69fcfmjxc9ok.png)

**Step 2: After you connect the repository service provider**
Choose a repository, and then choose a corresponding branch to build and deploy.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9ff5p690brhus3zd5p7.png)

**Step 3: Confirm build settings for the front end**
For the selected branch, Amplify inspects your repository to automatically detect the sequence of build commands to run.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/han2bidadg0q59d5ohc4.png)

**Step 4: Confirm build settings for the backend**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqiirk0dvyfj250kpf7p.png)

**Step 5: Save and deploy**
Review all of your settings to ensure everything is set up correctly. Choose Save and deploy to deploy your web app to the AWS global content delivery network (CDN). Your front end build typically takes 1 to 2 minutes but can vary based on the size of the app.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvpquf2rtz638v98cvb2.png)
1.**Provision** - Your build environment is set up using a Docker image on a host with 4 vCPU, 7GB memory. Each build gets its own host instance, ensuring that all resources are securely isolated. The contents of the Docker file are displayed to ensure that the default image supports your requirements.

2.**Build** - The build phase consists of three stages: setup (clones repository into container), deploy backend (runs the Amplify CLI to deploy backend resources), and build front end (builds your front-end artifacts).

3.**Deploy** - When the build is complete, all artifacts are deployed to a hosting environment managed by Amplify Hosting. Every deployment is atomic - atomic deployments eliminate maintenance windows by ensuring that the web app is only updated after the entire deployment has completed.
Ng-News: Episode 22/41
Tags: javascript, angular, webdev, programming
Published: 2022-10-17 18:09:25

{% embed https://youtu.be/AgdRy52T_xM %}

## Nx 15

Nx, an alternative to the Angular CLI, was released in the new major 15.

We can expect a detailed overview at the Nx Conf, which starts today.

{% embed https://www.youtube.com/watch?v=-g3NABhePJg %}

Nx provides features for large applications or monorepositories in the areas of building, generators, tooling, etc.

Lately, we have seen that nx splits up the angular.json into multiple per-project procect.json files. Under the hood, the generators and schematics still work as long as they stick to the official API, which is not always the case.

This new development is a significant improvement; hopefully, the rest of the Angular ecosystem will quickly adapt.

## Native Federation 1.0

There is a trend that tools, once written in JavaScript, are rewritten in a programming language that compiles down to native code. Like Go or Rust. For some time now, Angular has been working on the integration of esbuild which could be a full replacement of webpack. An experimental version exists in Angular 14.

But in the Angular ecosystem, other tools depend on webpack, and they also have to find a solution. 

Module Federation, a technique for Micro Frontends, is one of them.

Last week, we saw the release of Native Federation version 1. It emancipates itself from webpack and can run with esbuild, vite, or any other build tool with an available adapter.

{% embed https://www.angulararchitects.io/en/aktuelles/announcing-native-federation-1-0/ %}

## esbuild in Angular

If you are interested in esbuild, AngularNation has a video for you. Alex Rickabaugh talked about using esbuild for the Angular compiler itself. 

esbuild compiles on a file to file basis which is not very optimal for an application with NgModules. esbuild just sees the file of a component, but needs to know the location of the NgModule. Unfortunately, the component has no import statement that links to its NgModule.

{% embed https://youtu.be/NLU6lmWPdLg %}

## Minor Releases

Other than that, we had two minor releases of popular testing frameworks. Cypress went up to 10.10 and Jest to 29.2.

[Cypress 10.10 Release Notes](https://docs.cypress.io/guides/references/changelog#10-10-0)

[Jest 29.2 Release Notes](https://github.com/facebook/jest/releases/tag/v29.2.0)
Starting out learning to code with flatiron online coding boot-camp.
Tags: beginners, javascript, webdev
Published: 2022-10-17 17:59:48

On October 10th, 2022 I started the flex-software-engineer program at flatiron school. Wow! I just want to say how amazing the present can be. One day I woke up and asked myself if what I was doing was worth it? Was I making a difference and enjoying my craft? As fast as I could make the decision to switch career paths I was on my way to learning to code. 

After researching several online coding boot-camps that could work around my current career I finally chose flatiron school. This was the best choice I have made, and although I am only a week into the program, I can say that this school sets you up for success. You immediately have access to a pre-work program that sets you up with a solid foundation. 

During the pre-work I learned the basis of HTML, JavaScript, and CSS. You are also given a step by step process to make sure the device you are using is ready for the program by installing Visual Studios to helping you first discover how to use GitHub. I am well on my way and will be posting about my experience as often as I can.
Best Tableau Training
Tags: education
Published: 2022-10-17 17:45:31

The objective of IgmGuru's [Tableau online training](https://www.igmguru.com/data-science-bi/tableau-training/) program is to assist users in their dynamic learning about Tableau's application for data visualization while also being compliant with the most recent Tableau Certification Exam. The Tableau Course covers the fundamentals of data types, data extraction, data blending, filtering, highlighting, geocoding, map and image visualization, and many other technical aspects of Tableau.
Marketmovil Agencia de Marketing Digital y Diseño Web en Sevilla
Tags: webdev, news, wordpress
Published: 2022-10-17 17:44:43

Les invito a conocer mi web donde ofrezco servicios de [Diseño Web](https://marketmovil.es/diseno-web-sevilla/) y [Marketing Digital en Sevilla](https://marketmovil.es/).