Never stop learning
Source: Dev.to
Introduction
It’s a wonderful time to be a developer with rich tools, documentation, and artificial intelligence. Still, at least for now and the foreseeable future, developers must learn to write code, as AI tools are not perfect and may produce code that is difficult to integrate into an existing code base.
- For developers just starting out – learn the basics, then OOP and database work.
- For experienced developers – hone your skills to get and keep a full‑time job. For instance, C# .NET Core has a new feature; take time to learn it, even if there is no immediate use for it. Another path is to browse developer forums, analyze every aspect of a question, and decide what can be learned or avoided.
The following guidance applies to developers using Microsoft Visual Studio, C#, and .NET 8 or higher.
- Create a Visual Studio solution for learning and use solution folders to categorize topics.
- When code appears useful across multiple projects, place it in a class library (see the folder for class projects in the screenshot below).
Request for a login for a console project
First, check out the thread in its entirety – that is what an AI might use to form a response.
Now let’s explore a better way using the Spectre.Console NuGet package.
Spectre.ConsoleTextPromptprompts users to enter text input with validation, default values, and secret‑input masking.- It will be used to ensure a non‑empty string is returned.
- The password text is masked.
- Both username and password use the same colors.
- The sample includes sufficient validation for testing purposes (hard‑coded).
using Spectre.Console;
using SpectreLoginSample.Classes.Core;
namespace SpectreLoginSample.Classes;
internal class Prompts
{
public static string PromptStyleColor { get; set; } = "cyan";
public static string PromptColor { get; set; } = "bold";
public static bool TryLogin(int maxAttempts = 3)
{
for (int attempt = 1; attempt
username == "admin" && password == "password";
public static string GetUserName(bool allowEmpty) =>
allowEmpty
? AnsiConsole.Prompt(
new TextPrompt($"[{PromptColor}]User name[/]")
.PromptStyle(PromptStyleColor)
.AllowEmpty())
: AnsiConsole.Prompt(
new TextPrompt($"[{PromptColor}]User name[/]:")
.PromptStyle(PromptStyleColor));
public static string GetPassword() =>
AnsiConsole.Prompt(
new TextPrompt($"[{PromptColor}]Password[/]:")
.PromptStyle("grey50")
.Secret()
.DefaultValueStyle(new Style(Color.Aqua)));
}
Why this is a good learning experience
Once the login code is finished, there is plenty more to explore in the Spectre.Console library. It shines for:
- .NET tools
- Console‑project utilities
File Globbing to the rescue
File globbing is a topic every developer should know. A glob defines patterns for matching file and directory names using wildcards. Globbing is the act of defining one or more glob patterns and yielding files from inclusive or exclusive matches.
Scenario – A developer uses OneDrive for backups. After a backup completes, all local files are removed. When the backup is restored, many duplicate files appear (5,000+ copies). Manually deleting them is impractical. With file‑globbing knowledge, the developer can write a simple console app to remove the duplicates automatically.
Code to create a list of duplicate files
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.FileSystemGlobbing;
using Spectre.Console;
public static class Globbing
{
///
/// Returns a list of files that match typical “Copy” naming patterns.
///
public static async Task> GetDuplicatesTask(string parentFolder)
{
var list = new List();
var matcher = new Matcher();
// Include typical copy‑file patterns
matcher.AddIncludePatterns(new[]
{
"**/* - Copy .*",
"**/* - Copy (*.*"
});
// Exclude folders that may need special permissions
matcher.AddExcludePatterns(new[]
{
"**/My Music/**",
"**/My Pictures/**",
"**/My Videos/**"
});
await Task.Run(() =>
{
foreach (var file in matcher.GetResultsInFullPath(parentFolder))
{
list.Add(new FileMatchItem(file));
}
});
// Persist the list for later inspection
await File.WriteAllLinesAsync(
Path.Combine(parentFolder, "Duplicates.txt"),
list.Select(item => item.ToString()));
return list;
}
}
Code to remove the duplicate files
using System;
using System.Threading.Tasks;
using Spectre.Console;
public static class DuplicateProcessor
{
public static async Task ProcessOneDriveDuplicates()
{
var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var list = await Globbing.GetDuplicatesTask(folder);
if (list.Count > 0)
{
AnsiConsole.MarkupLine($"[bold green]Found {list.Count} duplicate files.[/]");
foreach (var item in list)
{
try
{
System.IO.File.Delete(item.FullPath);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine(
$"[red]Failed to delete {item.FullPath}: {ex.Message}[/]");
}
}
AnsiConsole.MarkupLine("[bold green]Deletion complete.[/]");
}
else
{
AnsiConsole.MarkupLine("[green]No duplicate files were found.[/]");
}
SpectreConsoleHelpers.ContinuePrompt();
}
}
💡 Tip –
AddExcludePatternsis useful for skipping directories that require elevated permissions or that you simply don’t want to touch.
Summary
- Use Spectre.Console for polished, interactive console prompts (login, menus, etc.).
- Leverage file‑globbing (
Microsoft.Extensions.FileSystemGlobbing) to locate and manipulate groups of files based on patterns. - Organize reusable code in class‑library projects within a Visual Studio solution to keep things tidy and shareable across multiple console apps.
Happy coding!
Source code
files.[/]");
} else
{
AnsiConsole.MarkupLine($"[bold green]No duplicate files found in {folder}.[/]");
return;
}
foreach (var (index, item) in list.Index())
{
try
{
if (File.Exists(item.FullName))
{
File.Delete(item.FullName);
}
else
{
AnsiConsole.MarkupLine($"[yellow bold]{item.FullName}[/]");
}
}
catch (Exception e)
{
AnsiConsole.MarkupLine($"[red bold]Failed to delete " +
$"{index} {item.FullName}[/]");
}
}
Summary
No matter if a developer vibes codes, uses artificial intelligence for what they get stuck on, or doesn’t use AI, try and learn something new at least once a week. Karen tries to learn something new several times a week.