teleren/devto huggingface dataset:
Debugging C# Source Generators
Tags: dotnet, csharp
Published: 2021-09-11 21:54:06

## Introduction

With C# 9 we got introduced to [Source Generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview) which are really awesome and have potential for many things. In this post I will describe how I ended up debuging them as I was creating my [ViewBindingsGenerator](https://www.nuget.org/packages/P41.ViewBindingsGenerator) project for Android apps.

## The Problem
Visual Studio 2019 & Visual Studio 2022 are really great for development but source generators is one place where they fall short.

There are many great articles out there but none help with the actual problem of debuging your generator as a novice without tests or the knowledge to write some. Also not knowing what you are looking for adds to the burden and in the end you just want to play with your code just like in the [SourceGeneratorPlayground](https://wengier.com/SourceGeneratorPlayground/) but more involved.

After fighting the tooling and trying to debug my code, where at that point I was still exploring plus I didn't know a lot of things so it became a problem.

## The Solution
As I was about to give up It hit me, I just in the end want to at least see some text somewhere like in the console (the Javascript way xD). So using VS Code, it's built in console and this code

```csharp
#if DEBUG
internal static class Log
{
    public static List<string> Logs { get; } = new();

    public static void Print(string msg) => Logs.Add("//\t" + msg);

// More print methods ...

    public static void FlushLogs(GeneratorExecutionContext context)
    {
        context.AddSource($"logs.g.cs", SourceText.From(string.Join("\n", Logs), Encoding.UTF8));
    }
}
#endif
```

I started debuging my code with no problems!

The code is really simple, you have several methods that will append strings in a list, each entry is a new commented line that will be printed to a `C#` file.

Using the last method `FlushLogs` which I call at the end of my generator `context.FlushLogs()` I "printed" the messages.

The VS Code Setup:

![VS Code Setup Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fi1iy4l09o9yhua5ev5c.png)

At the bottom of the screen I am either running `dotnet build` or `dotnet clean && dotnet build` to get a clean generation (bonus with VS Code I never lose my open `logs.g.cs` file).

To the right I have the logs.g.cs file which is located in `obj/Debug/{platform}/generated` depending on your project.

To the left I have the code I am testing on which I call the `Log` class and it's print methods.

The most important part for me was to keep the Log class only in the `#If DEBUG` so that I could remove it later for release!

## The End

And that's it, even if it is dirty, it gets the job done especially for a novice and allowes you to code a lot faster for now until the tooling gets better!

If anyone has better ways please do provide links in the comments 😁
Second Week in the Task Force
Published: 2021-09-11 21:35:32

Hey everyone!

Here are my take away and challenges that I have encountered during the second week of the task force and how I tried to overcome them.

During the second week of the task force,  the first two days were calm. We did many interactive activities that were mainly group centered. Their aim was to teach us that in order to work well in a group, we have to collaborate. The crazy thing is that this time it was easier to communicate through non-verbal than verbal because there was less distractions and more focus on what we were supposed to achieve, Crazy huh! #Non-verbal#communication#is#it :) 
Also another thing I learnt from that was that we can not all be leaders in a group , thus we have to choose a leader and coordinate accordingly to get the work done. 

Unfortunately I could not attend the 10 CTs & Virtual Meetings Etiquette session because I had to go to school for my final exams. Hopefully I wont miss any other session onwards.
We also got to learn about Code of Africa's core values and our values personally which was very educative because I got to know the core values anyone should have in order to excel mostly at your work place as well as in your everyday life. 

The rest of the week was pretty much hectic, where we were supposed to come up with well designed mockups based on functionalities we were given. This tested my creative side and now I feel like I am improving in every aspect of my design skills, which is a very rewarding feeling :) 
 
And lastly on Friday, We about stereotypes of Germans and East Africans in general, that was very educative because I got to know more about Germans and East Africans and also how these stereotypes can be a barrier to communication.

In a nutshell, week two was very challenging but fun, looking forward to what week three has in store for us.
See you :)
Top Programming Languages
Tags: cpp, javascript, php, python
Published: 2021-09-11 21:25:22

##C++

If you are interested in learning C++, remember that it's a very complex language to learn in beginning. If you are aiming at taking on big projects where you wish to have a lot of control of how the things work, C++ is a good choice. If you know C then C++ is bit simple for you but not C isn't mandatory. Once you master C++, learning other programming language is much easier. 

`C/C++ is also good for placements.`


##Java

If you aren't sure that what you do with coding then java is good choice because of its versatility. Java is a great asset to have when you start applying for your first job as a developer. Java is most the useful/preferred programming language for android mobile development. Java is quite difficult for beginners but this will be simple with time.

`Java is also a good choice for placements.`


##JavaScript

If you want to become a front-end developer, you have to learn javascript at some point. A full-scalable website can't build without JavaScript. JS is the "hottest" & best language for web development at this moment. No trouble to finding a job once you master in JavaScript. Use JS with HTML - CSS & you got a complete portfolio of skills to get your first front-end developer job!

`JS is less preferred for placements.`


##Python

If you want to see results quickly and build meaningful from the beginning, python is a great choice. Python lets you create so many different projects from data mining to game development that you can start learning it & see what you like the most as you progress. Python is a slow language & can't be use competitive programming. 

`Python is also less preferred for placements.`


##Objective-C

If you want to create the apps for the App Store, objective-C is a necessary skill you need to learn. When you start learning Objective-C, be prepared to learn Swift too. The combination of these two languages will give you great skill set for iOS development for a long time! 

`Objective-C has not good scope for placements.`


##PHP

Since PHP is easy to get started with, it's a great choice for a beginner programmer. Additionally PHP is the most useful programming language for Wordpress Development. If you're planning to become a freelance web-developer; PHP is safe choice : Wordpress & other Content Management Systems (CMS) often use PHP. 

`PHP also has not good scope for placements.`


> This is a distinct point of view; most firms follow this, but it may be different in your instance.


Also Check : 
* [Developer Resources](https://github.com/theritiktiwari/dev-resources)
* [Coding Walls](https://instagram.com/codingwalls)
10 Android Apps to Evolve Your Programming Skills
Tags: codenewbie, beginners, 100daysofcode
Published: 2021-09-11 21:11:00

## 10 android apps to evolve your programming skills.

+ [DataCamp: Learn Python, SQL & R coding](https://play.google.com/store/apps/details?id=com.datacamp&hl=en&gl=US)
+ [Mimo: Learn coding in HTML, JavaScript, Python](https://play.google.com/store/apps/details?id=com.getmimo&hl=en&gl=US)
+ [Programming Hero: Coding Just Got Fun (beta)](https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp&hl=en&gl=US)
+ [Grasshopper: Learn to Code](https://play.google.com/store/apps/details?id=com.area120.grasshopper&hl=en&gl=US)
+ [Programming Hub: Learn to code](https://play.google.com/store/apps/details?id=com.freeit.java&hl=en&gl=US)
+ [Sololearn: Learn to Code for Free](https://play.google.com/store/apps/details?id=com.sololearn&hl=en&gl=US)
+ [900+ Programming Books - Free Coding Books at Once](https://play.google.com/store/apps/details?id=com.codinghomies.programming.books.learn.to.code&hl=en&gl=US)
+ [Learn DS & Algo, Programming Interview Preparation](https://play.google.com/store/apps/details?id=free.programming.programming&hl=en&gl=US)
+ [Master Coding - Learn Coding from Zero to Hero](https://play.google.com/store/apps/details?id=net.androidsquad.androidmaster&hl=en&gl=US)

Have a good day!
Week 2 as a taskforce
Tags: awesomitylab, codeofafrica, taskforce
Published: 2021-09-11 20:51:52

Hello there! 

Here we are again, wrapping up the second week in style😎.
This week was more challenging from very awesome team games in soft skills sessions to tough individual technical assignments. 

Monday started off with Yannick’s session, I was introduced to the developer’s world a bit through the session on git workflows, the whole process was new to me but it was interesting to learn some technicalities and how they affect the whole process in the end. 

Tuesday was a more relaxed day, morning session was about values, it was interesting because we often don’t realize what we know about ourselves until we pause and reflect on it, that session was more a reflection and it was also nice getting to know more about the team and CoA’s values.

![Values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxw0078u1xsdlujbgjaz.jpeg)

That was basically it for the soft and easy part of the week😂, what followed was more of a rollercoaster, as part of our weekly technical challenges we had to create mockups that match a project we had to come up with based on functionalities we were given, hilarious huh?🤣 Normally it’s the project first but this time nahh. 

![Challenge](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlps6lbtzdgj1olyaka3.jpg)

This was a challenge because it’s not the usual way we did it before, we didn’t even know were to start but we found ways, this has allowed me to think of a certain functionalities as a main part of the project’s success not just as an add ons.

Briefly this week was more intense, more challenging but again more fruitful. On a personal level I feel like I’m improving and I can’t wait to see what I still have in stores😅


And as always, see you next week. :)
Introduction to Servlets
Tags: java, webdev, todayilearned
Published: 2021-09-11 19:02:33

While surfing any website on the internet, for any page in it there are two things that happens, request and response between the client and server. Client sends a request to retrieve any page and response comes from the server. 

There are basically two types of pages - static and dynamic. Dynamic pages are those pages which are created during run time. 

## Web containers
So now to understand where servlets fits in this picture, we need to understand something called web containers which are nothing but helper applications which are used to generate these dynamic pages. These helper functions contains servlets for the same purpose. Apache Tomcat is one of the examples for web containers. 

## Servlets
Now what exactly this servlet does and what it is exactly? It's nothing but a java file which can take the request from the client on the internet and it can process that request and it can provide you a response in the form of an HTML page. It's a normal class that extends HttpServlets

## Deployment Descriptor
Now how does this web container will know which servlet is suitable for handling any incoming request. Well, for that we have web.xml files which are also know as deployment descriptor. Here you mention for which request which servlet should be called.
@jy95/i18n-tools - CLI to make common operations around i18n files simpler
Tags: typescript, opensource, javascript, tooling
Published: 2021-09-11 18:59:31

![Summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmsj9lfsbt8j1wbufet6.PNG)

To keep Angular applications translations up to date, I had to constantly exchange and compare files (i18n, xlsx) between business & devs.

With a growing number of labels, this increasingly time-consuming task involves two challenges :
- How to quickly see if some values have changed (and which ones) ?
- How to convert the different file types to i18n files (and vice versa) for the available locale(s) ?

So I decided to create a CLI with the following features :

- 👩‍💻 Export i18n files into something else (xlsx, csv, ...)
- ✨ Turn a file (xlsx, csv, ...) to i18n file(s)
- 📜 Compare at least two i18n files and generate a report
- ... (🚧 More in the future)

Demo :

![Examples](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/srw55ox1jd8mo68v3rr5.PNG)

Read more on [https://jy95.github.io/i18n-tools/](https://jy95.github.io/i18n-tools/)
Source code : [https://github.com/jy95/i18n-tools](https://github.com/jy95/i18n-tools)

Remember to leave a ⭐ if you like it!
Typescript : Type guards simply explained.
Tags: typescript, typeguards, javascript
Published: 2021-09-11 18:46:45

Today we're exploring a functionality in Typescript called **type guards**, if the name sounds strange to you,know however this is a technique that you probably have used in plain Javascript if you've been coding in that language for a while.

Type guards is a technique used in Typescript to get information about the type of a variable (to know what the type is) and this often happens within a conditional block like if/else. To achieve this, typescript makes use of some built-in javascript operators like `typeof`, `instance of`, the `in` operator which is used to determine if an object contains a property.

So this is enough theory already, let's go through some examples.
Oh just before, type guards mostly come to use when we're dealing with a function whose parameter has a **union type** as type annotation.
If you're not familiar with Union Types, you can take it literally as a union of types, e.g:
`Type UnionOfTypes = string | number`

Let's go through a failing code example to see where Type guards come in.

```javascript
type StringOrNumber = string | number //our union type

function processAmount(amount: StringOrNumber){
    return amount + 10 //error
}
```
In the snippet above, our function `processAmount()` takes an argument `amount` which can be either a string or a number.
In the function body, we just assume that `amount` is a number and try to add 10 to it. The compiler gets confused, it cannot add 10 (number) to 
amount (string | number) and thus signals us that there's an error:
`Operator '+' cannot be applied to types 'StringOrNumber' and 'number'`

Ok, so what are we doing wrong? Well, we are not narrowing the type of the argument `amount`. We need a way to tell the compiler that it should treat 
our variable as a number and let us perform our operation. **That's where type guards come in.**

```javascript
type StringOrNumber = string | number

function processAmount(amount: StringOrNumber){
    if(typeof amount === "number"){
        return amount + 10
    }
    return amount
}
```
This time, by using the `typeof` operator within a conditional block, we tell the typescript compiler to treat `amount` as a number within the scope and now our code can compile without errors.

That is Type guards in a nutshell, remember that there are other operators used to perform Type guards and narrowing in Typescript like `instanceof` and `in`. I'll cover these in a future blog post.
⌨️ An ACTUAL typewriter (that auto types and is interactive too!) 🤯
Tags: showdev, html, javascript, webdev
Published: 2021-09-11 18:43:47

A bit late to the party but here is my silly entry for the typewriter wars!

And unlike everyone else...I built a typewriter!

**warning:** This will not be very accessible for screen reader users I am afraid.

{% jsfiddle https://jsfiddle.net/t4naug2y/7/ result %}

It is a little rough around the edges and way better on a PC, but it works and it will do for a quick idea (I say quick, it took ages!).

## It is interactive
Once the initial animation has played you can use it just like a typewriter! You may have to click on the typewriter to focus the fiddle.

**on mobile:** there is an input you can focus to bring the keyboard up.

## What no tutorial this time?
Nope, there is not a single piece of code here that I would want you to use in the real world!

However I have taken the time to make sure that the key movements actually correspond to the keys on your keyboard, so I hope that you can forgive the shoddy code in exchange for the **eternity** that it took me to label up all the parts of the SVG!

Anyway, just have fun with it and at least I joined the fight, even if it was late!
How the bootcamp is going so far
Published: 2021-09-11 18:27:05

Hi! First of all I'd like to thank you for taking a time to read this, and I hope you gonna read it to the end right!?

Last week I shared how I now pay attention to user stories when building web applications, and how important user stories are. Here is the [link](https://dev.to/patricktunez123/my-first-week-a-k-a-my-thirteenth-week-at-awesomity-lab-code-of-africa-s-bootcamp-58pf) to it in case you have not checked it out yet. Well, today I just wanted to share with you how the bootcamp is going so far, especially during this week.

Ok, the week has been fun as always. We worked on some Katas (On [Codewars](https://www.codewars.com/), kata are code challenges focused on improving skill and technique). Some of katas were simple; well, at least for me of course! and others were a little bit challenging but fun though!. We also learned what Git workflow is , the purpose of Software documentation, the purpose of having a DevOps process and the reasons why to  containerizing projects. 

Ok, I know how these terms may sound not familiar to you and more technical if you're not a developer, but I just wanted to give you a quick view of what we've been at this week. 

I hope I did not bore you with those technical words and stuff! and oh! I just almost forgot to tell you how fun it was doing the research about German Stereotypes!, one of many researches I did is that Germans love cars! Agree? let me know in the comments.

Let me stop by here. I have a lot of things to say but I need to make this post short, before I put the last dot on it, I just want to say that I'm gaining a lot from this bootcamp. Thanks to Awesomity Lab and Code of Africa who organized it.

 Thanks for reading!
What is overfitting in machine learning?
Tags: machinelearning
Published: 2021-09-11 18:25:19

*Overfitting* is a common challenge to overcome while training machine learning models.

To understand this concept, let’s consider a plane with an X and Y-axis. The X-axis represents the complexity of your model, and the Y-axis represents the loss function.

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


## Explanation
In the diagram above, the blue line represents the training set and the orange line represents the validation set.

### The training set
Let’s consider the blue line.

As the complexity of the model increases, the loss decreases, and vice versa.

### The validation set
Now, let’s consider the orange line.

As we keep moving from left to right, the loss falls until a certain point. If you keep moving right from that point, the loss increases.

The point from which the loss increases is the minimal loss for the validation set.


## Balanced model
Before this point, a model is considered under-fitted, and after this point, the model is deemed to be over-fitted. This level of complexity represents the balanced model.

To better understand the balanced model, let’s consider some data points to represent these three fittings.


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

## Explanation
In the diagrams above, the red data points are the ones we use to train the model. This means they were already available.

The green data point is newly introduced, and we test it against our model.

If the green data point is introduced in the balanced machine learning model, it will be close to the plotted line, indicating greater accuracy.

### Underfit model
In Fig. A, our ML model has plotted a straight line against the data points. The line crosses through a few data points, and other data points are further from the plotted line.

When a new data point is introduced, it is far from the line. This indicates that the model is not accurate.


### Overfit model
The model is fitted exceptionally well, as seen in Fig. B because the plotted line passes through all the training data points.

This model is entirely accurate for the training data. However, introducing a new data point shows that the model may not work well for new data, as it is far away from the plotted line.

### Balanced model
In Fig. C, which is our balanced model, the plotted curve passes through some of the data points. If we calculate the loss, this model would have the most minor loss out of all the models.

The introduction of a new point is near the plotted curve. Hence, when the model is used with actual/production data, our predictions will be reasonably accurate.

That's all for this post guys,
If you enjoyed it, don't forget to leave a like.
Happy Learning.