Skip to content

Electrical power engineering calculation (a functional programming design)

Notifications You must be signed in to change notification settings

t2wain/ElectricalFunc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Electrical Libraries

This repository consists of several libraries that perform various engineering calculations such as voltage drop, NEC tray fill, and cable routing. These are some of the features in applications that I have developed over the years. I have recoded these features many times as an exercise to apply the latest software design practices. The redesign this time is to apply the principles of functional programming.

There are four (4) projects that implement the main features:

  • VDropLib
  • GraphLib
  • NECFillLib
  • RouteLib
  • RacewayLib

The other three (3) projects are testing projects:

  • AppConsole
  • RouteDB
  • UnitTestroject

Splitting into Sub Domains

It would be appropriate to include all functionalities in these libraries within a single engineering application. However, to include all these functionlities into a single domain (a single library) would make software development a lot more complex. Splitting these functionalities into multiple sub domains (libraries) allow a more focus and simpler solution. Although some entities are common to these sub domains, such as cable and raceway, the data types are still developed separately within each library to minimize dependency.

Functional Programming Principles

Belows are some of the principles I tried my best to follow in this code redesign:

  • Object only contains data (no method)
  • Object is immutable. All modifications return new objects.
  • Minimize the use of primitive data type as argument. Use simple object instead to convey semantic meaning.
  • Functions implement behaviors of objects (not methods).
  • Implement pure functions with no side effect
    • The return value will depend only on the function arguments.
    • The function will not modify the external environment.
  • Function is referential transparent
    • It always returns the same output for the same inputs.
  • Implement partial application (currying) with the use of higher order function
    • A function that return another function.
    • Leverage the closure principle to capture state for a function
    • As a design to reduce the number of arguments of a function and create a simpler function to use.
  • Rail programming
    • The output of a function is the input of the next function. This call chain should continue to completion even when there is an error.
    • Within each function, there should be branches for success and failure to allow for continuation.

Functional Language Features in C# 10

  • Use immutable record instead of class to implement object
  • Pattern-matching statement and expression
  • Object and tuple destructuring
  • Copy constructor for cloning immutable object
  • Inner function
  • Extension method
  • LINQ

Releases

No releases published

Packages

No packages published

Languages