I’ve managed to do a bit of professional reading in the recent past, from process to PLC to mind-blowingly functional.
Business Process Books
I read one business book, Profit Beyond Measure by Johnson and Broms.Â They use the Toyota Production System and Scania’s modular design process to examine how to manage by means (MBM), instead of manage by results (MBR).
In MBR, management sets financial targets such as profit margins, sales level, or marketÂ share.Â In the MBM approach, management focuses on the process (how) the company achieves its result, for example, how work flows through from customer order to customer delivery (and payment!).
Three Fun, Mind Blowing MEAPs
I skimmed three MEAPs.Â A MEAP means you get to download and read the book while it is being written.Â Since I still like dead tree books, I paid a little bit extra so when the books are finished, I will get real books hot off the presses.Â I thought all three books were good, maybe excellent.Â My selections were:
- Grokking Functional Programming (Grokking FP) by Aslam Kahn is an introductory book on functional programming.Â The goal is to introduce the fundamentals of functional programming in an easy manner, without any scary mathematics, and then to get you to truly understand (“grok”) how to approach programming challenges in the functional way.Â The book is filled with examples and exercises, since you don’t really understand a method until you do it yourself.
- Functional Reactive Programming (FRP) by Blackheath and Jones.Â FRP uses cells (representing values over time) and streams (actions/events over time) to handle dependencies.Â Since you declare what depends on what, when something happens (such as a new event), the FRP system knows how to update everything that depends on that change in the proper order.Â Think of how a spreadsheet updates itself when you change a value.Â FRP is a good match for event-based systems such as GUIs, but not so good when you need actions to happen in a predictable sequence (especially hard real time systems).
I found FRP to be very interesting, but I don’t see an immediate need for it right now.
I do plan on going back through Grokking FP and doing all examples because although I am somewhat familiar with a lot of functional ideas, I do not yet think in functional way — I haven’t grokked it yet.
I am also planning on going through Rx In Action in depth, because I think it may be a good way to re-factor one of my programs at work that has significant event handling.Â I’m interested in Rx because I like its:
- Support for handling events as streams (like FRP)
- Support for event timeouts
- Support for propagating errors that occur in event handlers
- .NET support (I like to program in C#)
- Better support for sequences (which I need)
- Concurrency control with schedulers
- The ReactiveUI GUI library
Functional programming is hot right now because some of its features (such as immutable types) can make parallel programming significantly easier.Â I do think automation programmers should learn it (I can wholeheartedly recommend Grokking FP) because it will truly expand your mind, and FP is becoming more popular.
Programmable Logic Controller (PLC) News
On the PLC side, I have decided to skim through Programmable Logic Controllers: An Emphasis On Design And Application by Kelvin Erickson.Â I started trying to read it thoroughly, but haven’t made much progress so I am changing my approach to skimming.
Based on a reader recommendation, I just bought Progammable Logic Controllers: A Practical Approach to IEC 61131-3 Using CoDeSys by Dag Hanssen.Â I plan on skimming it next, and then will share my findings.
Both appear to be well written, both are a bit pricey, both were writtenÂ by professors, and both are introductory books.
The contrastÂ with mainstream programming books is fun:
- My three Manning books (print and ebook)Â cost the same as PLCs by Hanssen.Â I paidÂ $70Â to ManningÂ withÂ a 50% discount (you can get that by signing up with Manning and being patient).Â I paid $70 for PLCs by Hanssen (new, with $9 Alibris discount; list price is $120), and $50 for PLCs by Erickson (first edition, used; list price for current version (Third Edition) is $85).
- The MEAPs are well written,Â advanced books covering cutting edge topics.Â The PLC books are good, too, but they are introductory textbooks.
- The MEAPs were written by developers who use these tools in their day to day jobs.Â The PLC books were written by professors.
So I haven’t found an advanced PLC programming book yet, however, there is good news: Frank Lamb, proprietor of the Automation Primer blog and author of Industrial Automation: Hands On, has announced that he has started writing one.
April 19, 2016 No Comments
I’ve done a fair amount of VB.NET and C# .NET development.Â So here are some notes about .NET development techniques along with comments about theÂ .NET books I own.
C# is deservedly the most popular .NET languages.Â Although some tasks such as COM interoperability are easier in VB.NET, overall I strongly prefer C#.Â C# has a more coherent syntax and better support for cutting edge programming techniques such as functional programming.
It’s worth considering the other .NET languages, especially in combination with C#.Â However, you also have to consider whether the advantages (such as clearer code and quicker development) out way the disadvantages (such as most programmers not knowing the language).Â For example, I’m very tempted to F# at work, but won’t, because it’s not very likely anyone else who might have to maintain my code will know F#.
Microsoft is now putting more emphasis on C++, is pushing functional programming with F# and new C# features, and has basically dropped its support of dynamic languages such as IronPython and IronRuby.Â However, these projects are still alive, and can make a lot of sense: for example, adding scripting to easily customize your base software for different customer requirements.
I learned C# basics using Programming C# 4th Edition, 2005, by Jesse Liberty.Â I’d say it’s a good book; reviews for later versions are mixed.Â However, depending on where you’re starting from, there are probably better books.
C# In Depth by Jon Skeet is a superb advanced book on C#.Â I have the second edition, and am very impressed with its coverage of C#’s evolution, and its explanations of how and why to use these new features.
This book illustrates one of the biggest advantages of mainstream software development: excellent advanced books.Â There are no PLC programming books comparable to C# In Depth.
I bought Juval Lowy’s Programming .NET Components, Second Edition, many years ago for half price at Fry’s.Â It sat around until I needed to handle asynchronous programming, send .NET events, use Remoting, and handle some concurrency.Â The book is a bit dated, but recently I’ve been referring to it constantly, and appreciate the well written explanations and the author’s tips based on his experience.
Programming .NET Components has chapters on component-oriented programming essentials, interface-based programming, lifecycle management, versioning, events, asynchronous calls, multithreading and concurrency, serialization, remoting, context and interception, and security.Â So it covers a lot of useful areas, but its age shows: for example, there’s no coverage of WCF (Windows Communication Framework) or newer approaches to concurrency.
Microsoft classifies Remoting as a legacy technology: it won’t disappear (heck, COM/DCOM is still around), but won’t be actively developed.Â I looked at using WCF, but decided its advantages didn’t matter to me, and that it was considerably more complex than Remoting.
I’ve looked into some of the newer .NET technologies but haven’t had a reason to use them yet, including:
- The Task Parallel Library (TPL) – Microsoft’s preferred way of handling concurrency in .NET 4.0 and higher.
- The Concurrency and Coordination Runtime (CCR) – originally shipped with the Microsoft Robotic Studio, but can be used for non-robotic applications.
- Reactive Extensions (Rx) – intended to simplify asynchronous and event driven programs.Â It uses cool advanced programming techniques.
My current applications don’t benefit from massive amounts of parallelism, so right now the TPL and CCR don’t offer any major benefits.Â I do have some event driven programs, which I suspect could really benefit if rewritten using Reactive Extensions.
GUIs and Programming
Most developers use GUI designers to create the user interface; Visual Studio has a good designer.Â Using a designer is easy, initially requires less code, provides instant feedback on the GUI’s look, and provides pixel level control.Â However, most designer-created GUIs don’t scale well, don’t handle modifying the user interface at run time, and require a lot of work every time you want to change something.
Another approach is to create the GUI in code.Â This was pretty tough in the old days of straight Windows or MFC — there’s a good reason VB became so popular.Â However, when I did a project using Python and tkinter, I didn’t have a choice, since tkinter doesn’t have a designer.
Instead, you use layout managers to tell the GUI how to automatically place the controls (e.g. grid, vertical pack, horizontal pack).Â Java has similar methods.Â Initially, WinForms did not, but later versions added layout managers, although I doubt they’ve been used a lot.
The advantages are that you can make the GUI much more flexible: scalable, adding controls at run time or based on a table or configuration file, and such.Â On the flip side, there’s more work up front, you don’t have the same level of layout control, and you do spend a lot of time running the GUI just to tweak the layout.
A third approach is to use a declarative GUI, where you can define the GUI’s elements by declaring them in a configuration file.Â (Side note: Windows Installer uses a similar declarative approach.)Â WPF (Windows Presentation Foundation) supports declarative GUIs using XAML files.Â You can also create WPF GUI’s using a designer (including Microsoft’s stand alone designer, Expression) or using code.
As my readers from Kickdrive.de have pointed out, the well regarded Qt GUI library now supports declarative GUIs.Â However, Qt is not well supported in the .NET world although there are bindings such as Qyoto and Qt4Dotnet (which hasn’t been updated in a while).
I’m currently still using WinForms, but that’s because of the project’s requirements.
DSLs and Meta-Programming
DSLs are domain specific languages; in other words, special purpose programming languages made for a specific use, not general usage.Â The advantage is that DSLs can be tailored to match the needs of the domain users, not those of programmers.Â Â Then there are DSLs for developers, such as easyb, a story verification framework using a DSL written in Groovy.Â Take a look at easyb in action — it’s very different from C# or Java.
There’s at least one book on creating DSLs in .NET: DSLs in Boo by Ayende Rahien.Â I don’t own it yet, but I’ll probably add a used copy to my next Amazon order.
Metaprogramming is programs that write or manipulate programs.Â Metaprogramming is impossible in ladder logic and many other languages; it’s easiest in dynamic languages such as IronPython.Â At its best, metaprogramming can add a lot of flexibility and eliminate huge swaths of boilerplate code.Â At its worst, metaprogramming can make spaghetti code look good, so it should be used with care.
I wrote a settings module with metaprogramming; to add a settings variable, I just added its specification (name, type, etc) to a table, and the Python code could automatically load and save the variable, add it to the settings dialog, and add it to the settings object — pretty cool, and a lot less work than doing all that by hand.
Functional programming has attracted a lot of attention recently, partly because it can ease the pain of parallel programming.Â I’m not a total convert, but I do like to use some functional techniques, and have been learning more.Â I have three books on functional programming using .NET:
- Functional Programming in C# by Oliver Sturm– a good book with clear explanations of how to do various functional techniques in C#.Â If you’re looking for an introduction to functional programming, look elsewhere.Â But if you want to use functional programming in C#, get it.
- Programming F# by Chris Smith.Â I have the first edition, and I’ve done a quick first read — it’s aÂ good book, and F# is an intriguing and very powerful language.
- Real World Functional Programming With Examples in F# and C# by Tomas Petricek with Jon Skeet.Â I haven’t read it yet, but it looks very interesting: at a glance, it’s chock full of practical examples.
F# is pretty far above ladder logic.Â I wouldn’t recommend it as the control language for a high speed packaging line, but it can easily handle data manipulation tasks that would be impossible in ladder logic.
Testing and Development
As I’ve mentioned before, The Art of Unit Testing by Roy Osherove is an excellent book, well written and filled with practical advice.Â I recently boughtÂ Test Driven Development in .NET by James Newkirk and Alexei Vorontsov; the review are good but I haven’t read it yet.Â Applying unit testing is a bit harder with automation: I can see how I could apply it to communications code, but not to motion code.
IronPython In Action by Michael Ford and Christian Muirhead is worth considering, even if you don’t plan on using IronPython as your main language, because it can show you some different approaches with its chapters on unit testing, metaprogramming, WPF, and scripting.
One big difference between mainstream software development (such as Java, .NET, and C/C++) and automation development is that on automation side, development is vendor driven, while the mainstream development community has drive a lot of advances such agile development, lean development, unit testing, Test Driven Development (TDD), Behavior Driven Development (BDD), continuous integration, distributed version control (git, mercurial), refactoring, design patterns, and DSLs.
July 17, 2013 1 Comment
I just bought a lot of software development books, mostly centered on Microsoft’s .NET Framework.Â I have a code base that is getting old and creaky (for example, parts are written in VB6) and it’s time to look at re-doing it, using Visual Studio 2010.
I’m tempted to write everything in a mix of F# and Boo, but I won’t, because it would be hard for almost anyone else to maintain it.Â Instead, I’m planning on mostly C#, with maybe some IronPython thrown in (for rapid customization).
I’m reading each book quickly first to get an idea of what I can learn, then I will go back in depth for the techniques that I will use.
So what is on my list?
- C# In Depth, Second Edition — to make sure I’m up to speed with all the latest changes to C#.Â I haven’t read it yet.
- Functional Programming in C# — highly recommended; it’s well written and shows how to use a lot of the functional techniques I’ve come to love from using Python; in short, it makes C# much more usable.Â However, if you aren’t already familiar with concepts such as closures, first class functions, and lambdas, it’s going to be slow going for a while — and consider learning them in another language first (such as Lua using Programming in Lua).
- The Art of Unit Testing: With Examples in .NET — highly recommended; it provides lots of practical advice and best practices for creating unit tests that work well.
- IronPython In Action — I haven’t read it yet, but it looks good, with a lot of best practices advice.
- Practical Statecharts in C/C++, First Edition — I haven’t read it yet.Â This book is really aimed at embedded developers, and although I don’t plan on using the author’s Quantum Programming framework, I think I will get some good ideas from it.
The Manning books all include a free PDF of the book when you register your book.Â I haven’t done this yet, but I will soon.
All my books are real, not e-books, because I prefer real books when learning a new topic, the paper books were cheaper or about the same price, and I won’t buy ebooks that require a proprietary reader (such as Kindle or Apple books).
September 12, 2011 No Comments
Recently, I needed to compile some code for Visual Studio 2003, which I don’t have (I have VS 2002 and VS 2005).
The obvious approach is to convert the project to VS 2005, which uses .NET 2.0.Â However, I wanted to compile to .NET 1.1 for various reasons, and VS2005 does not allow this out of the box.
The first approach I tried was using the MSBee program.Â MSBee is a program for MSBuild to allow compiling a program in VS 2005 to .NET 1.1.Â MSBee requires modifying the project file, and has to be run from the command line.Â I gave it a try, and it gave me a lot of errors.
I probably could have figured out those MSBuild errors, but I found a better solution: SharpDevelop 2.2.Â SharpDevelop typically allows you to compile to either the current .NET version or the previous one.Â So SharpDevelop 2.2 can target either .NET 2.0 or .NET 1.1 — and it can read and convert VS 2003 project files.
Sharp Develop read my VS 2003 solution files without a problem, and I went to the Project menu, selected Project Options, clicked on the Compiling tab, and set the Target Framework to .NET Framework 1.1.Â Success!
September 2, 2011 No Comments
even if you’re using C# or VB.NET. How? By using Boo’s interpreter to try out ideas, test usage of .NET framework functions, and interact with components (COM, .NET). Then when you’re comfortable, you can write the polished code in the language of your choice.
This is one use for mixed language programming, mentioned by me here, but where the final software might not use both languages.
In fact, any .NET interpreter such as IronPython or IronRuby could be used. And it’s a great technique for other than .NET – I’ve used it a lot with Python on Win32, and you can use it in Java with JRuby, Jython, Groovy, etc. This approach could be very useful for embedded and factory software development.
On .NET IronPython and IronRuby have advantages because they’re official Microsoft languages (and IP has a book coming out – IronPython In Action) and the languages are already in wide use (Win32, *nix, Java). I’m using Boo because it comes with the open source SharpDevelop IDE, and right now it integrates better with .NET (IP does not support attributes well, and it’s not easy to make an IP assembly callable by other .NET languages, etc).
Short example – interactively using DirectoryInfo in Boo (text I typed in bold):
>>> di = DirectoryInfo(“C:\\Download”)
>>> files = di.GetFiles()
(AdbeRdr80_en_US.exe, AdbeRdr80_en_US_Nosso_error.log, Firefox Setup 22.214.171.124.exe, SharpDevelop_126.96.36.19948_Setup.msi, TortoiseSVN-188.8.131.5245-win32-svn-1.4.3.msi)
>>> files = di.GetFiles(‘t*’)
Interactively calling a COM object in Boo:
>>> ieType = System.Type.GetTypeFromProgID(‘InternetExplorer.Application’)
>>> ie = System.Activator.CreateInstance(ieType)
>>> ie.Visible = true
So far I haven’t had to use InvokeMember to call COM functions. At least for C# and VB.NET (and probably Boo) it appears you need to use it if you are using late binding. BTW, it is possible to use late binding with COM events, but it is significant extra work.
September 26, 2007 No Comments