Should a Software Architect Code? is the Wrong Question

It’s a long-running argument in software architecture and I’ve seen some quite emotional comments on it. But it’s the wrong argument. The right question is surely one about ratios:

“What ratio of non-coding architects to coders will work best for us?”

A ballpark answer to this question would follow logically from calculating how many full-time-developers worth of work results in an amount of non-coding-but-still-requires-deep-or-broad-technical-understanding-and-vision work that adds up to one full time job.

I suggest, based mostly on e-commerce & similar SMEs, something like:
(1) 25 developers’ worth of coding results in 1 full-time non-coding-architect’s worth of work.
(2) Every team needs at least one coding-architect-or-architecturally-competent-developer per 5 developers

Which gets me to a ratio of

1:5:25

for

non-coding-architect : coding-architect-or-lead-dev : developer

Architecture features plenty of non-coding work. Dealing with people, plans, business change, technical design, design decisions, frameworks, principles, patterns, catalogues, quality attributes… There’s more than enough of it if you have 25 coders’ worth of development going on.

So in a workplace with 100 developers, you may want a chief architect, 3 or 4 non-coding architects and 20 coding-architects-or-architecturally-competent-developers. But if you are chief architect or even CTO of a company with 15 developers, you probably still code.

There’s no right answer to the question, how much coding does a coding-architects-or-architecturally-competent-developers do. It can vary from nearly-nothing to 95% as projects progress. Perhaps 50% is a good average?

Discussions

There having been not one but two still-live threads on this on LinkedIn software groups since 2012:
LinkedIn – 97 Things Every Software Architect Should Know – Should architects continue coding … ?
LinkedIn – IASA – Should software architects code?
Anthony Langsworth’s 2012 post

Posted in Code | Tagged | Leave a comment

Clojure (and some Lisp) in 10 mins for OO developers

Notes from a short talk at xp-manchester:

No doubt the most useful slide is 3, which is a 1-slide “how to read lisp” tutorial.

We did a series of 10 minute talks on the evening, including a set of 3 on features of functional languages: Haskell’s strong typing, mostly inferred; & Erlang’s agents. Erlang’s agents are almost like an OO language in which every ‘class’ (agent) gets its own process; which is what OO seemed to suggest to me when I read descriptions of the grand idea in the 80s/90s. My headlines for Clojure are largely the points made in http://clojure.org/rationale

Posted in Code | Tagged , | Leave a comment

Max de Vries Interview – What every project manager should know

I was recently fortunate enough to catch Max de Vries on a trip to the UK. Max has overseen complex IT projects in Europe, Asia and the US, in finance, public sector and now games for over 20 years, most recently being in charge of Popcap’s Plants vs Zombies franchise, overseeing the launch of PvZ 2 and PvZ-Garden Warfare. I managed to fire off two quick questions before he had to go:

Q: What are the top 3 things every project manager should know?
Who to trust; how to communicate; and what would success look like.
Q: What are the common mistake that inexperienced project managers make?
  • Not realizing they are inexperienced
  • Making estimation a political process
  • Miscalculating the cost of saying no vs the cost of failure
  • Not thinking about the critical path hard enough
  • Thinking that people know what they want
  • Underestimating the value of a high functioning team
  • With agile processes: Modifying a process without understanding the reasons why the process works and doesn’t work

So now you know.

Posted in Code, working life | Tagged , | Leave a comment

Command line concatenate PDFs on OS X

A great post at http://gotofritz.net/blog/howto/joining-pdf-files-in-os-x-from-the-command-line/ which does what it says on the tin.

He explains how to link to a python script included in OS X since some years ago so as to make concatenating PDFs as easy as typing

pdfconcat -o output.pdf *.pdf

The heavy lifting is all done with calls to OS X Quartz.CoreGraphics module so this isn’t going to work on other platforms, but for the curious it demonstrates how easily you can do such stuff on OS X.

#! /usr/bin/python
#
# join
#   Joing pages from a a collection of PDF files into a single PDF file.
#
#   join [--output <file>] [--shuffle] [--verbose]"
#
#   Parameter:
#
#   --shuffle
#	Take a page from each PDF input file in turn before taking another from each file.
#	If this option is not specified then all of the pages from a PDF file are appended
#	to the output PDF file before the next input PDF file is processed.
#
#   --verbose
#   Write information about the doings of this tool to stderr.
#
import sys
import os
import getopt
import tempfile
import shutil
from CoreFoundation import *
from Quartz.CoreGraphics import *

verbose = False

def createPDFDocumentWithPath(path):
	global verbose
	if verbose:
		print "Creating PDF document from file %s" % (path)
	return CGPDFDocumentCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, path, len(path), False))

def writePageFromDoc(writeContext, doc, pageNum):

	global verbose
	page = CGPDFDocumentGetPage(doc, pageNum)
	if page:
		mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox)
		if CGRectIsEmpty(mediaBox):
			mediaBox = None
			
		CGContextBeginPage(writeContext, mediaBox)
		CGContextDrawPDFPage(writeContext, page)
		CGContextEndPage(writeContext)
		if verbose:
			print "Copied page %d from %s" % (pageNum, doc)

def shufflePages(writeContext, docs, maxPages):
	
	for pageNum in xrange(1, maxPages + 1):
		for doc in docs:
			writePageFromDoc(writeContext, doc, pageNum)
				
def append(writeContext, docs, maxPages):

	for doc in docs:
		for pageNum in xrange(1, maxPages + 1) :
			writePageFromDoc(writeContext, doc, pageNum)

def main(argv):

	global verbose

	# The PDF context we will draw into to create a new PDF
	writeContext = None

	# If True then generate more verbose information
	source = None
	shuffle = False
	
	# Parse the command line options
	try:
		options, args = getopt.getopt(argv, "o:sv", ["output=", "shuffle", "verbose"])

	except getopt.GetoptError:
		usage()
		sys.exit(2)

	for option, arg in options:

		if option in ("-o", "--output") :
			if verbose:
				print "Setting %s as the destination." % (arg)
			writeContext = CGPDFContextCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, arg, len(arg), False), None, None)

		elif option in ("-s", "--shuffle") :
			if verbose :
				print "Shuffle pages to the output file."
			shuffle = True

		elif option in ("-v", "--verbose") :
			print "Verbose mode enabled."
			verbose = True

		else :
			print "Unknown argument: %s" % (option)
	
	if writeContext:
		# create PDFDocuments for all of the files.
		docs = map(createPDFDocumentWithPath, args)
		
		# find the maximum number of pages.
		maxPages = 0
		for doc in docs:
			if CGPDFDocumentGetNumberOfPages(doc) > maxPages:
				maxPages = CGPDFDocumentGetNumberOfPages(doc)
	
		if shuffle:
			shufflePages(writeContext, docs, maxPages)
		else:
			append(writeContext, docs, maxPages)
		
		CGPDFContextClose(writeContext)
		del writeContext
		#CGContextRelease(writeContext)
    
def usage():
	print "Usage: join [--output <file>] [--shuffle] [--verbose]"

if __name__ == "__main__":
	main(sys.argv[1:])
Posted in Code, Computers | Tagged , , , , | Leave a comment

Visual Studio 2013 Command Prompt Here for Windows Explorer Context Menu

To get a Visual Studio 2013 Command Prompt Here as a Context Menu (i.e., Right Click Menu) item in Windows Explorer, save this snippet to a .reg file and double click to import it into your registry:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2013]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2013\command]
@="cmd.exe /k echo on & pushd \"%1\" & \"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\VsDevCmd.bat\"" 

If you prefer to manually create the key path in RegEdit and add the command as the default value, drop the outermost quotes and the backslash escaping:

cmd.exe /k echo on & pushd "%1" & "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"
Posted in Code, Computers | Tagged , | Leave a comment

Mono MVC System.UnauthorizedAccessException Access to the path “/Library/Frameworks/Mono.framework/Versions/…/etc/mono/registry” is denied

Is an error you are likely to see if you run a Visual Studio MVC template in Mono. There are two options for fixing it.

  • Do this from the command line:
    sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
    sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry

    (replacing 3.2.5 with your mono version, which you get at the command line with mono --version)

  • Or delete the reference to Microsoft.Web.Infrastructure.dll from the project and delete it from the bin directory too.

The important difference is that deleting Microsoft.Web.Infrastructure.dll will stop your project working on .Net, so the registry access is simpler for cross-platformers. Another option for cross-platform project files would be something like this in the .csproj file:

<Target Name="AfterBuild">
    <Delete Files="$(WebProjectOutputDir)\bin\Microsoft.Web.Infrastructure.dll" Condition=" '$(OS)' != 'Windows_NT'" />
  </Target>

I prefer the ‘grant access to the registry approach’ myself but it does mean having to re-run the 2 line script for every new version of mono.

Posted in Code | Tagged , , , | Leave a comment

Visual Studio Template ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588

If you use the VS template to create a new ‘internet’ web application, then the template includes code for Asp.Net simple membership. But the template is written for SqlExpress. If you instead have a full SQL Server install on your machine it won’t work.

The first exception you might see when debugging in visual studio is,

Exception has been thrown by the target of an invocation.

or if you aren’t debugging you might see

The system cannot find the file specified

neither of which help at all.

so first, change the connection string in web.config to use your local SQL Server:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20140225162244;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20140225162244.mdf" providerName="System.Data.SqlClient" />

changing the connectionString‘s Data Source property to Data Source=.;

Now you might get the same or a different exception message:

The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588

but the linked page doesn’t tell you how to fix it.

The inner exception is more helpful:

Directory lookup for the file "c:\...etc...\MvcApplication1\App_Data\aspnet-MvcApplication1-20140225162244.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

Which tells you that the login account under which SQL Server is running doesn’t have write permissions to the directory in which you write you code. It does have write permissions in the SQL Server data directory, for instance C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA so you’d think that by looking at that directory to see what user it runs under you’d be able to give it permissions.

Almost. The Explorer GUI Security tab showed me a usergroup called ‘MSSQLSERVER’ but if you try to give permissions to that group you’ll find it doesn’t exist. More helpful is the command line:

cacls "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL"

which, if you look carefully at the output,

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL 
    CREATOR OWNER:(OI)(CI)(IO)F
    NT AUTHORITY\SYSTEM:(OI)(CI)F
    BUILTIN\Administrators:(OI)(CI)F
    BUILTIN\Users:(OI)(CI)R
    NT SERVICE\MSSQLSERVER:(OI)(CI)R

shows you that you the actual name is NT SERVICE\MSSQLSERVER

So I gave modify permissions on my App_Data directory to NT SERVICE\MSSQLSERVER (I carefully copy-pasted the full name) and it worked.

Posted in Code | Tagged , , , | Leave a comment

Why OO Business Applications Always Wind Up Splitting Methods from Data And Not Encapsulating Either

One of the main—perhaps the main—selling point of OO is Encapsulation. Which is actually two selling points. Firstly Information Hiding, that is, hiding the innards of a class so you can use it without needing to know how it works. Secondly Modularity, holding related data and methods together in one place. It’s the use of objects & classes to achieve these two effects that gives OO a large part of its flavour, distinct from procedural or functional programming.

The power this gives is the ability to model the domain naturally. This is power of OO. Given a business having customers with addresses, orders, invoices, products etc, we can model the domain – the entities and their relationships – very naturally in code by creating classes to represent them.

So as OO developers coming to line-of-business applications we expect to apply these techniques. We think about what should be private or public to each class, and we think about what responsibilities belong with classes, and what methods & data are needed to fulfil that responsibility.

The problem is, businesses don’t do modularity and information hiding. (Well they do of course, by being split up into business functions – sales, accounting, warehouse, customer services etc. Information private to one department is not usually available or even of interest to staff in another. But that’s not the level we’re interested in in a domain model).

Look again at our OO classes: customers, addresses, invoices, orderlines, products etc. These things are not encapsulated in business use at all. Firstly, there is no hidden information; when a business user goes to their information system to get information about a customer they expect just that: Information. No hiding. Secondly, information is all they expect. They do not expect the information system to model the customer’s ability to Walk() and Talk(). No methods – and so little modularity – are needed.

This is true of almost everything in a business’s domain model. From a business users point of view, it’s all just screens of information. Documents. And this – the humble document – is the heart of what we missed in our sketch of a domain model. The real thing we are modelling is not the flesh and blood Customer, or the physical Product they want to buy. What we’re really modelling in line-of-business apps is paper documents in a filing cabinet.

A piece of paper in a filing cabinet has no methods to model. It’s just a data-holder. An accurate domain model for a piece-of-paper-for-a-customer is just a list of fields or properties. You can wrap get() & set() methods round them if you like, but all you’re doing is adding boilerplate. (As an aside, a big advantage of computers over paper is much better performance in modelling relationships between those pieces of paper. A database can look up a customer’s order history much faster than a human with a set of filing cabinets).

So where are the methods in a business? They are largely in the business processes. (The phrase ‘business process’ is one that your business people use, which tells you that business processes should be part of your domain too).

To the business, a process is usually a sequence of actions done by a chain of people. In a typical business process, a piece of paper (actual or virtual) is passed around; information is updated on it, or on other pieces of paper; and very occasionally something is actually done, such as finding an item in a warehouse and putting in a box.

Which class in your domain is responsible for these actions? Probably none of them. You could create a WarehouseWorker class responsible for Pick()ing and Ship()ing the product, but you’ll quickly realise (unless your warehouse is staffed by robots for whom you are writing the control programs) that you can’t write any code that actually belongs in those methods. You can write code for UpdateStockCount(), to record the fact that stock is decremented; and you could write an UpdateCustomerOrderStatus() so that the customer services department can tell the customer how their order is getting on. Indeed, that’s probably exactly what’s being required of your system. But which class in your domain responsible for these actions?

If you think that the Customer class, or the Order class, is responsible for UpdateCustomerOrderStatus(), then you would appear to be imagining a piece of paper updating itself, which is not a normal responsibility for a piece of paper. (Either that, or you’re imagining the ghost of the customer coming on-site to keep track of their order. The real customer has no such responsibility. Their only responsibility at this point is to sit at home waiting for their package to arrive). In the world before computers it was probably the responsibility of the Stock Controller or Inventory Controller (yes, those are real job titles still held by real people) to do this book-keeping. So your domain model could/should include a StockController class with that responsibility.

Now ask yourself, what data do I need to encapsulate in the fields of a StockController class? The answer is almost certainly none whatsoever. You are not usually asked to model the real stock controllers’ working hours or height or physical strength in a line-of-business application. All you need to model is their ability to UpdateStockCount() & UpdateCustomerOrderStatus(). You need model no internal state.

This is typical of business process modelling. Business processes are nearly always stateless – all the information they need is given to them each time they are invoked. This is true for so-called ‘long-running’ processes too: the classes responsible for performing each step of the process are not responsible for holding state. Rather, they expect to have data (or ids/keys to look up the data) passed to it.

In short: ninety percent of the domain of a line-of-business application is usually correctly modelled as:

  • Documents holding data
  • Stateless public processes which receive these documents as their inputs

Because most of what you are modelling is paper documents (which do nothing, except record data) being worked on by employees (about whom you know nothing, except their ability to update the documents).

And that’s why data is not encapsulated in business applications, nor are methods and data held together in the same class.

Objections

But wait – surely we still have encapsulation and information hiding between for instance the UI layer vs data access layer vs domain model?

Yes, that’s right. The StockController exposes the fact that it can UpdateStockCount() but hides the fact (in fact, doesn’t even know itself) that this is achieved by writing to a copy of SQL Server installed on machine XYZ. A clear sign of concerns that should be separated at quite a high level is that they are semantically unrelated, that is, they speak a different language. The UI layer and the domain model know nothing of this ‘Sql Server’ of which you speak.

The point is rather that you should not be disappointed if it turns out that your domain model feels more anaemic than rich. That models the reality of typical business domains.

What about business rules & logic? They aren’t stateless business processes?

Also true. And the above line of thought need not be applied to them. (Does an abstract concept such as ‘business rule’ have state? Yes if it’s the-rule-as-applied-to-a-specific-case; no if it’s ‘The Rule’ in abstract).

Posted in Code, Computers | Tagged , , | 2 Comments

Compile & Build Mono on Mac OS X

In spite of what you might still read on http://www.mono-project.com/, mono source moved to github.com/mono/mono. To build and compile on the mac however the simplest instructions are still the “One Stop Shop Build Script” at the bottom of http://www.mono-project.com/Compiling_Mono_on_OSX. They worked for me first time although I hit a couple of issues:

  1. Having a space in the path to where I built it broke the build script
  2. Fetching the mono repo from git failed several times. This may – or may not – be related to the OS X 10.9 Mavericks / Versions issue noted at http://www.git-tower.com/blog/make-git-rebase-safe-on-osx/ but I’ve had no further problems since following their instruction to
    git config --global core.trustctime false
Posted in Code | Tagged , , | Leave a comment

New Microsoft Remote Desktop client for Mac

Remote desktop for Mac is old, and can’t always connect. It can’t connect to Windows 8.1 for instance. I keep getting the “Remote desktop connection cannot verify the identity of the computer that you want to connect to”, even though I tell it to connect anyway.

If like me your first reaction to “it doesn’t work” was to try the “Check for Upgrades” menu item then you’ll want to know that _that_ doesn’t work either.

Instead, go straight to the App store and install it from there. The spiffy new version is a great new app and works just fine.

Posted in Computers | Tagged , | Leave a comment