- STACK.md - Technologies and dependencies (.NET 4.7.2, NuGet, Costura.Fody) - ARCHITECTURE.md - Layered CLI with ICncMachine factory pattern - STRUCTURE.md - Directory layout and where to add new code - CONVENTIONS.md - C# style, naming, result wrapper pattern - TESTING.md - NUnit 3 + Moq, stubs, ignored FOCAS tests - INTEGRATIONS.md - FOCAS, LSV2, FTP, RSA licensing - CONCERNS.md - Blocking async, silent catch, no logging, Windows-only Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4.5 KiB
4.5 KiB
Coding Conventions
Analysis Date: 2026-05-18
Naming Patterns
Files:
- PascalCase for all
.csfiles:FanucMachine.cs,CncResult.cs - Interfaces: I-prefix PascalCase:
ICncMachine.cs,IFocasDialect.cs - Tests:
{Subject}Tests.csor{Subject}IntegrationTests.cs - Config classes:
{Manufacturer}ConnectionConfig.cs
Classes:
- PascalCase for all classes
- Sealed preferred for implementations (not open to inheritance)
- Examples:
NcProgramValidator.cs,CncResult.cs
- Examples:
- Manufacturer-prefixed where relevant:
FanucMachine,HeidenhainMachine,SiemensMachine
Interfaces:
- I-prefix strictly followed:
ICncMachine,IFanucMachine,ILicenseValidator,IFocasDialect
Fields:
- Private:
_camelCasewith underscore prefix- Example:
_config,_validator,_state,_hndlinCnc/Fanuc/FanucMachine.cs
- Example:
- Constants (public): PascalCase —
AlarmSlots,TransferChunkSizeinCnc/Fanuc/FanucMachine.cs - Constants (private): can be UPPER_CASE or PascalCase
- Static readonly:
_camelCasewith underscore
Properties:
- PascalCase, read-only preferred
- Example:
Name,Comment,Content,PathinCnc/Models/CncProgram.cs
- Example:
Methods:
- PascalCase for all public methods:
ConnectAsync(),ReadProgramAsync() Asyncsuffix on all methods returningTask<T>orTask- Private helpers:
PascalCase(same as public, no underscore)- Example:
NcProgramValidator.cs
- Example:
Enums:
- PascalCase for type name, PascalCase for values
- Examples:
CncManufacturer.Fanuc,ConnectionState.Connected,FanucTransport.Ethernet
- Examples:
Code Style
Formatting:
- 4-space indentation
- Allman brace style (opening brace on new line for classes and methods)
- Example:
Cnc/Fanuc/FanucMachine.cs
- Example:
- Single-line property getters: inline
{ get { return _x; } } - No
.editorconfigor StyleCop — conventions enforced by practice
String Formatting:
string.Format()for parameterized messages (not$""interpolation)- Example:
Cnc/NcProgramValidator.cslines with format strings
- Example:
+concatenation for console output inProgram.cs
Async:
defaultparameter forCancellationTokenon async methodsConfigureAwait(false)on library-level codeTask.Run()for blocking FOCAS calls in async context (RunGuardedAsync pattern)
Import Organization
Order:
- System namespaces
- External packages
- Internal project namespaces
No path aliases (not applicable to .NET Framework / no source generators).
Error Handling
Patterns:
- Null guards at constructor:
if (config == null) throw new ArgumentNullException("config")- Example:
Cnc/Fanuc/FanucMachine.cs
- Example:
- Null-coalescing for optional deps:
_validator = validator ?? new NcProgramValidator(...) CncResult<T>wrapper for all CNC operations (not exceptions)- Exit codes at CLI boundary: -100 to -208 in
Program.cs try/finallywithconnectedflag for connection cleanup inProgram.cs
Result Wrapper Factories:
CncResult<T>.Ok(value)— successCncResult<T>.Fail(errors)— failure with error listCncResult<T>.Cancelled()— cancellationCncResult<T>.OkWithWarnings(value, errors)— partial success
Logging
Framework: None — Console.WriteLine only
Patterns:
- User-facing output:
Console.WriteLine()inProgram.cs - Error output: same Console (no stderr separation)
- No log levels, no timestamps, no structured logging
- Debug mode via
-debug=arg keeps terminal open post-operation
Comments
When to Comment:
- Document intent/constraints, not obvious code
- Example:
NcProgramValidator.cs— "Name-format check (uses just the bare filename without path)"
- Example:
- Separator line style for section breaks:
// ── private helpers ─────────────────- Example:
NcProgramValidator.cs
- Example:
XML Doc Comments:
- Sparse; only on public classes and key methods
- Format:
/// <summary>Brief description.</summary>- Examples:
NcProgramValidator.cs,CncResult.cs,ValidationResult.cs
- Examples:
No TODO/FIXME comments found in codebase — known deferred work tracked in STATE.md.
Function Design
- Private async methods wrap blocking/mixed code with semaphore locking (RunGuardedAsync pattern)
- Example:
Cnc/Fanuc/FanucMachine.csRunGuardedAsync
- Example:
- Large transfer methods split into chunked helpers (
TransferChunked,UploadProgramByIdentifier) - Interface/implementation pairs for all protocol clients (I-prefix interface + concrete)
Conventions analysis: 2026-05-18 Update when style decisions change