Programming Tips πŸ’‘
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
What is Unit Testing & Why You Need to Lean It ⁉️

Unit testing is the practice of writing code to test your code and then run those tests in an automated fashion. βœ…

πŸ”ΉπŸ”ΈπŸ”ΉπŸ”Έ

Here is an example. πŸ‘¨πŸ»β€πŸ’»

Imagine you have this function somewhere in your code.
It’s a basic calculate function that takes an input and depending on some conditions, it returns different values.

public float CalculateTax(int input) 
{
if (x) return ...;
if (y) return ...;
return ...;
}


If you want to test this function manually :

1️⃣ You have to run your application
2️⃣ Perhaps you have to login
3️⃣ Maybe do a few clicks here
4️⃣ There to get to a page where this function is used.
5️⃣ You have to fill out a form
6️⃣ Submit it
7️⃣ Verify if this function returned the right result.

And then you have to repeat all these steps, each time using different values in your form. πŸ€¦πŸ»β€β™‚οΈ

πŸ”ΈπŸ”ΉπŸ”ΈπŸ”Ή

Manual testing is expensive πŸ’Έ

As you can see, this is very time-consuming. βŒ›οΈ

This workflow to test this function may take several minutes every time❗️

Now to make matters worse, this is not the only function in your application. 🌍

In a real application, you have tens or hundreds of functions like this ❗️

As your application grows in size and complexity, the time required to manually test all the different bits and pieces increases exponentially. ⏱

So, that’s why we use Automated Testing. ♻️

πŸ”ΊπŸ”ΉπŸ”ΊπŸ”Ή

https://t.me/pgimg/24

[ Full Article ] : http://bit.do/utdd

γ€°γ€°γ€°γ€°γ€°γ€°
#CleanCode #UnitTest #TDD
@ProgrammingTip
The Art of Comments 🎨

[ Article ] : https://css-tricks.com/the-art-of-comments/

γ€°γ€°γ€°γ€°γ€°γ€°
#CleanCode #Comments
@ProgrammingTip
The Pragmatic Programmer.pdf
2.6 MB
The Pragmatic Programmer πŸ“™

Authors : Andy Hunt, Dave Thomas πŸ–Š

Level : Advanced πŸ”

γ€°γ€°γ€°γ€°γ€°γ€°
#Book #CleanCode #Refactoring
@ProgrammingTip
Quick Tip: How to pass visual alerts with an HTMLHelper⚠️

It will display a Bootstrap alert if there is a message passed through the ViewModel. πŸ’₯

This message can be a success, error, warning, or informational message. 🌈

The nice thing about the ViewMessage HtmlHelper is that if we don't pass it into our views, it won't display anything. πŸŽ›

https://t.me/pgimg/87

[ Article ] : http://bit.do/alhl

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #CleanCode
@ProgrammingTip
Automatic ModelState Validation in ASP.NET MVC πŸ”₯

How many times have you seen or written code like this ♻️ :

[HttpPost]
public ActionResult Index(SomeModel model)
{
if (ModelState.IsValid)
{
return View();
}

// do something
return RedirectToAction("index");
}


Stop repeating ModelState checks in your ASP.NET MVC controller actions. ❌

Wouldn’t it be nice if all we had to do was like this ? ⚑️

[HttpPost]
[ValidateModelState]
public ActionResult Index(SomeModel model)
{
// if we get here, ModelState is valid
// save to db etc.
return RedirectToAction("index");
}


https://t.me/pgimg/89

[ Article ] : http://bit.do/msta

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #CleanCode
@ProgrammingTip
How we do MVC – View models πŸ‘€

The ViewModel is a central aspect of our MVC architecture. 🌞

One of the first dilemmas facing MVC developers is to decide what the β€œM” in MVC means in ASP.NET MVC. πŸ€”

In Rails, this is fairly clear, the M is ActiveRecord (by default). 🌍

But in ASP.NET MVC, the β€œM” is silent❗️

Its out-of-the-box architecture offers no guidelines nor advice on what the M should be. βš™οΈ

Should it be an entity❓
Data access object❔
DTO❓
Something else❔

https://t.me/pgimg/91

[ Website ] : http://bit.do/mvvm

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
ASP.NET MVC Best Practices and Guidelines βœ…

While most developers were used to WebForms and Microsoft's stock controls, when developers moved to ASP.NET MVC, a number of developers were shocked because there wasn't enough meat for this to be a full-featured release. πŸ€“

Some of the guidelines list below are based on my own experiences over the years since 2008. πŸ“†

https://t.me/pgimg/93

[ Website ] : http://bit.do/aspbst

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
Architecting Services with Design Patterns πŸ’Ž

As the number of your services expands you're going to need to start thinking about how to organize them. πŸ—‚

Applying these two design patterns can help, provided you understand all their variations. βœ…

With the current set of tools that come with the Microsoft .NET Framework, it's easy to create a service. βš™οΈ

But it's also easy to create what both Nayaki Nayyar and Benjamin Moreland described as a "junk drawer of services." πŸ‘Ύ

If you're going to avoid that as the number of services in your organization increases, then you need to think about your architecture. πŸ€”

https://t.me/pgimg/95

[ Article ] : http://bit.do/asdp

γ€°γ€°γ€°γ€°γ€°γ€°
#CleanCode #DesignPatterns
@ProgrammingTip
Use T4MVC to Remove Magic Strings in ASP.NET MVC Apps 🎩

ASP.NET MVC has a fascination with magic strings. ❌

Basically any time you need to specify an action, a view, or controller, you use a magic string ✨ :

return RedirectToAction("Index", "Home", new { id = 4 });

return View("Details");

@Html.ActionLink("Back to details", "Detals", "User", new {id = 12}, new {@class = "backlink"});

@using (Html.BeginForm("Details", "User", FormMethod.Post))


The problem with magic strings is the same problem that ViewBag has ⚠️ :

1️⃣ There's no type checking.

2️⃣ The developer won't catch these errors until runtime, and sometimes not at all.

πŸ”ΉπŸ”ΈπŸ”ΉπŸ”Έ

T4MVC aims to remove magic strings from MVC and replace them with strongly-typed ActionResults. βœ…

It adds a bunch more overloads to methods such as ActionLink(), BeginForm(), and RedirectToAction() so that they can now accept ActionResults as parameters. πŸ—ƒ

Thereby making them strongly-typed and removing their dependency on magic strings. πŸ’Ž

Most importantly, it means we can take the above code samples and refactor them to look like this πŸ€™πŸ» :

return RedirectToAction(MVC.Home.Index(4));

return View(MVC.User.Views.ViewNames.Details);

@Html.ActionLink("Back to details", MVC.User.Details(12), new {@class = "backlink"});

@using (Html.BeginForm(MVC.User.Details(), FormMethod.Post))



https://t.me/pgimg/98

[ Article ] : http://bit.do/t4mvc

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #CleanCode #T4MVC
@ProgrammingTip
The Clean Coder.pdf
2.8 MB
The Clean Coder : A Code of Conduct for Professional ProgrammersπŸ“•

Author : Robert C. Martin πŸ–Š

Level : Advanced πŸ’Ž

γ€°γ€°γ€°γ€°γ€°γ€°
#Book #CleanCode
@ProgrammingTip
Insidious Dependencies πŸ€·πŸ»β€β™‚οΈ

In the last year or so I’ve really seen the light on how to really write loosely-coupled code. πŸ’Ž

I thought I knew something about this concept before – I mean, I knew loose coupling was good, generally speaking, and I knew data abstraction was one of the key ways to limit dependencies between classes. βœ…

However, I didn’t realize that I was unintentionally adding all kinds of coupling into my applications despite my best efforts to the contrary. ⛔️

Let’s talk about some dependencies, including some obvious ones, as well as some insidious dependencies that lurk in most applications I’ve seen. πŸ—‚

Insidious dependencies ❌ :
β€’ File System
β€’ Email
β€’ Web Service & Requests
β€’ DateTime.Now
β€’ Configuration
β€’ New ...


https://t.me/pgimg/139

[ Article ] : bit.do/indP

γ€°γ€°γ€°γ€°γ€°γ€°
#CleanCode #Dependency
@ProgrammingTip
How to Stop Using Callbacks and Start Living βš›οΈ

Javascript has two major ways of dealing with asynchronous tasks - callbacks and Promises. 🀝

In general Promises are considered easier to use and to maintain than callbacks. βœ…

But in reality even Promises alone won’t make you happy. 🀬

Asynchronous code may still be quite difficult to read and to understand. 🀯

Therefore third-party libraries, e.g. co, provided means to write a synchronous-like asynchronous code. πŸ—ƒ

I personally prefer everything in the world to be as clear and beautiful as redux-saga. ✨

But not everybody is lucky to work with React and Redux to be able to use sagas. ⛔️

This article will show that in modern Javascript it is not difficult to write a well structured and easy to understand asynchronous code without using any third-party libraries.πŸ’Ž


https://t.me/pgimg/146

[ Article ] : kutt.it/call

γ€°γ€°γ€°γ€°γ€°γ€°
#JavaScript #CleanCode
@ProgrammingTip
Clean Architecture with ASP.NET Core 2.1 πŸ¦‹

The explosive growth of web frameworks and the demands of users have changed the approach to building web applications. 🌐

Many challenges exist, and getting started can be a daunting prospect. Let's change that now. βœ…

This talk provides practical guidance and recommendations. πŸ’Ž

This video will cover architecture, technologies, tools, and frameworks. We will examine strategies for organizing your projects, folders and files. ⚑️

We will design a system that is simple to build and maintain - all the way from development to production. You leave this talk inspired and prepared to take your enterprise application development to the next level. πŸ”₯


https://t.me/pgimg/180

[ Video ] : kutt.it/cav
[ Source Code ] : kutt.it/cag

γ€°γ€°γ€°γ€°γ€°γ€°
#AspNet #Core #CleanCode
@ProgrammingTip