Developer experience & limitations
See how generators affect developer experience: naming, file discovery, diagnostics, build performance, and safe fallbacks — with C# 6 emulation.
Developer experience & limitations is a free C# Academy lesson on CoddyKit — lesson 2 of 2. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 2 lessons in the course, and your progress syncs across the web and the CoddyKit app.
DX & limits overview
Aim: Make generated code easy to use.
- Predictable names & file locations
- Helpful diagnostics
- Small, focused outputs
- Know limits: build-time only, no runtime reflection
Predictable names
Use stable names (e.g., *.g.cs, DebugId) so users can find generated members quickly.
using System;
// Emulate "predictable" generated naming: suffixes and folders are consistent.
public partial class Order
{
public int Id;
}
// Simulated generated piece: same partial name, with a clear suffix convention.
public partial class Order // would live in Order.g.cs typically
{
public string DebugId()
{
// predictable member name makes discovery easy
return "Order#" + Id;
}
}
public class Program
{
public static void Main(string[] args)
{
Order o = new Order();
o.Id = 42;
Console.WriteLine(o.DebugId());
}
}
Avoiding collisions
A separate namespace (e.g., Generated.*) and clear prefixes help avoid collisions with user code.
using System;
namespace Generated
{
// Emulate a generator using a dedicated namespace to reduce collisions
public static class OrderExtensions
{
public static string ToLabel(this Order o) { return "Order: " + o.Id; }
}
}
public partial class Order { public int Id; }
public class Program
{
public static void Main(string[] args)
{
Order o = new Order();
o.Id = 7;
// Extension lives under Generated.* to stay out of the way
Console.WriteLine(Generated.OrderExtensions.ToLabel(o));
}
}
Helpful diagnostics
Good generators emit clear diagnostics when input is invalid; users fix code quickly.
using System;
// Emulate generator diagnostics: validate inputs and print clear messages.
public static class GenCheck
{
public static string EmitGetter(string fieldName)
{
if (string.IsNullOrEmpty(fieldName))
return "DIAGNOSTIC: Field name is empty. Skipping emission.";
if (!char.IsLetter(fieldName[0]))
return "DIAGNOSTIC: Field must start with a letter: " + fieldName;
// pretend emission was fine
return "OK: Generated getter for " + fieldName;
}
}
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(GenCheck.EmitGetter("1bad")); // diagnostic
Console.WriteLine(GenCheck.EmitGetter("name")); // ok
}
}
Small focused outputs
Prefer small generated files with one responsibility; easier to read and debug.
using System;
// Emulate small, single-purpose emissions instead of huge files.
public partial class Report
{
public int Count;
}
public partial class Report // Report.Stats.g.cs idea
{
public double Average(int total)
{
if (Count == 0) return 0.0;
return (double)total / Count;
}
}
public partial class Report // Report.Format.g.cs idea
{
public string Summary(int total)
{
return "Total=" + total + ", Count=" + Count + ", Avg=" + Average(total);
}
}
public class Program
{
public static void Main(string[] args)
{
Report r = new Report();
r.Count = 4;
Console.WriteLine(r.Summary(20));
}
}
Limits & fallbacks
Limits:
- Runs at build-time, not runtime.
- Avoid heavy I/O or network calls.
- Do not rely on runtime reflection inside the generator path.
- Keep outputs deterministic.
Fallbacks: if input is invalid, emit diagnostics or minimal stubs instead of failing the whole build.
DX best practice
Recap
Recap: Favor predictable names, clear diagnostics, and small outputs. Respect build-time limits and provide safe fallbacks when input is invalid.
Frequently asked questions
Is the “Developer experience & limitations” lesson free?
Yes — the full text of “Developer experience & limitations” is free to read here on the web, and the C# Academy course includes 2 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “Developer experience & limitations”?
See how generators affect developer experience: naming, file discovery, diagnostics, build performance, and safe fallbacks — with C# 6 emulation. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 2, so you can start here or from the beginning and move at your own pace.
How long does the “Developer experience & limitations” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Concept & use-cases; incremental generators (overview)
- Developer experience & limitations