Posts

So what is quality code?

Image
So what is your interpretation of good quality code? I’ve been asked this on most technical interviews, to varying levels of grilling. I figured it’d be good to spend some time self-reflecting about how I answer this question, and researching to fill in the gaps of my knowledge. Just to give you a heads up, a lot of this will be heavily opinion based. I’d love to hear other points of view. An important thing to reflect on first, is what does not account for code quality. Code that just ‘looks nice’ is not necessarily quality code. This includes general styling such as, whitespace, member and function naming conventions (underscores or not, camel, snake or pascal casing), brace placement, or anything else that can be resolved with a basic linter. Quality code to me is one that has a solid, well tested foundation such that new features can be built upon it without falling over, or becoming needlessly complex. A good indicator is that you should be able to come back to the cod

Mutation Testing with Stryker

Image
This is a first look into Stryker Mutator . As for what it does; you might have already done this yourself, albeit manually, when reviewing someones PR. You’re considering how effective a given test is, so you pull the code and run the tests, and sure enough, you see the test pass and 100% code coverage. You’re still not convinced so you tweak the code in some minor way, expecting the test to fail. Surprise! It still passes and you still have 100% code coverage! So this is a bad set of tests! So what is Stryker Mutation testing? Consider the following example code (taken from the stryker docs ). function isUserOldEnough ( user ) { return user . age >= 18 ; } When Stryker is run against this code base, it will automatically mutate the return statement, recompile your application, and re-run the tests. For every mutation that Styker tries, a test MUST fail, otherwise we have a mutant. Here’s what mutations Stryker will make here: /* 1 */ return user . age &g

NestJS tutorials

NestJS is a react framework for building efficient, scalable, server-side applications. It also provides built in dependency injection out of the box, which I really like the sound of! I plan on learning about this framework and the ansillary frameworks, libraries and modules that surround it. I’m fairly new to front-end development, so I hope this will be useful to people in a similar position. Getting Started First up, read the NestJS intro and overview docs , which shows how to setup the dev environment, how to generate a hello world app, and some of the basics of how things fit together. I often come up with trivial problems to solve when having a go of new frameworks. In this case I wanted to eventually implement these rules: AskQuestion - what's for tea? - get strategy based on person asked - if mike, provide response based on day of the week - if mrs, randomise response between "beans on toast" and "scrambled eggs on toast" - i

Fun Retros - Crazy 8 + Impact Effort Map

This 60 minute session is designed to find problems that we might not collectively be aware of, gather ideas on how to solve them, prioritise those ideas, and ensure that they are enacted. [10 minutes] on the jamboard, ask the group to write post-its of problems that need to be solved. These post-its should follow the sentence structure how might we… e.g. How might we get customers to contact us when they have an issue with our product? , or How might we migrate more of our customers from our old system to the new one [4 minutes] ask them to dot vote the post-its with 2 or 3 votes each. Choose the top voted How might we.. question, or if there is no clear winner, ask the group to collectively choose one. [10 minutes] Crazy eight : ask the group to write one post-it every minute for 8 minutes with ideas on how to solve the chosen problem. Start a timer, and when each minute passes ask the group to move on to their next idea. [10 minutes] ask each participant to talk through the

next.js testing with jest

I stumbled upon the testing overview in the react docs, which says The default template of React Native ships with [Jest](https://jestjs.io) testing framework . Interesting. I’ll have a quick go of Jest just to see what’s what. Jest [about 30 minutes later…] Well… I wish I’d stumbled across this first, this was super easy! yarn add --dev jest in package.json: { "scripts" : { "test" : "jest" } } Create a ./tests/foo.spec.js file with the contents: test ( 'true is true' , ( ) => { expect ( true ) . toBe ( true ) ; } ) ; And run yarn test The nice thing about Jest, is that it: has fluent syntax so I don’t feel the need for chai, appears to have mocking functionality, but we’ll see later if that’s any good for TDD. This might mean we don’t need sinon. it clearly is a replacement for mocha, so we can swap that out Enzyme on the other hand might still add value if it makes testing components easier! We’ll

next.js testing frameworks

I figured the next step was to learn how to approach writing react components using TDD. I found this guide that recommends some libraries for assertions , spies , and also a testing framework and DOM simulator . Also a test runner … Ahhh so many to learn! Why so many libraries?!? This is one of the reasons I’ve previously been so detracted from starting to learn a front-end development framework, as the learning curve appears very steep. Spoiler alert, I don’t end up using most of these, so just read on. Let’s try and understand what each library is for and where it fits in. I’ve been a C# developer for a long time, so I’ll draw a parallel between the two ecosystems. Sinonjs Sinonjs is a spies, stubs and mocks framework. To draw a parallel; it’s pretty much how I’ve used AutoMocker on C# projects. Par examplĂ© : it ( 'needsLogin returns false when the user has been authenticated' , ( ) => { spy = spyOn ( service , 'isAuthenticated' ) . and

next.js tutorials

I figured I’d keep track of the resources I’ve consumed on my road to learning React with the nextjs framework. I’ve previously had a play with straight React, but I’m starting from practically zero so… let’s see how this goes! Next.js Tutorials First up, I took a look at nextjs.org , which seems to have pretty good documentation and tutorials . I just followed this tutorial through from start to finish one morning. This tutorial gives you plenty of code to copy and paste, but sometimes doesn’t give much explanation as to what each bit is doing. It’s worth spending some time actually reading the code you’re copy/pasting to understand what is going on. There are links for further reading for most sections, which are also worth a read. You can also read further into any given feature in the next.js docs . I also configured a CNAME record under my domain name Name : nextjs . portfolio Data : cname . vercel - dns . com . Resulting in https://nextjs.portfolio.mikemcmillan.dev

Clean Engineering

In the last couple of years or so, I’ve been getting more into researching clean code and quality engineering in general. I figured I’d keep track of the resources I’ve consumed, so that I can revisit them in the future. Youtube Video Watched Clean Code - Uncle Bob / Lesson 1 Yes Clean Code - Uncle Bob / Lesson 2 Yes Clean Code - Uncle Bob / Lesson 3 Yes Clean Code - Uncle Bob / Lesson 4 Yes Clean Code - Uncle Bob / Lesson 5 Yes Clean Code - Uncle Bob / Lesson 6 Yes DevTernity 2019: Ian Cooper – The Clean Architecture Yes Agility ≠ Speed - Kevlin Henney Yes GOTO 2016 - Small Is Beautiful - Kevlin Henney No The Forgotten Art of Structured Programming - Kevlin Henney [C++ on Sea 2019] No Books Book Owned? Read? Test Driven Development: By Example 1st Edition - Kent Beck Yes No Agile Principles, Patterns, and Practices in C# 1st Edition - Robert C. Martin Yes Reading Clean Architecture: A Craftsman’s Guide to Sof

Fun Retros - Liberating Structures - Wicked Questions

Articulate the Paradoxical Challenges That a Group Must Confront to Succeed (25 min.) The aim is to find one or more paradoxical questions in roughly the form of “How is it that we are ____ and we are ____ simultaneously?”. (put this template at the top of your jamboard) It’s important that both sides of the question are appreciative, otherwise this exercise can quickly turn into finger pointing. Once we’ve found some wicked questions, we’re not actually aiming to solve them. A really good wicked question just represents an undeniable reality. An example to help explain it, without anchoring thought processes: “How is it that we are raising our children to be very loyal and attached to the family and also independent individuals?” [5 mins] on the jamboard, add post-its of positive traits of the team. [5 mins] go through each post-it, see if there is already an appreciative opposite or paradox elsewhere on the board. If not can you think of one? [10 mins] pick out the most

Fun Retros - Liberating Structures - Min Specs

Specify Only the Absolute “Must dos” and “Must not dos” for Achieving a Purpose (35-50 min.) [10 mins] On the jamboard, put everything that you strive to do on a yellow post-it. And everything you try to avoid doing (bad practices, or processes) in orange. xp practices agile practises coding practises whatever you can think of [10 mins] Now imagine you’re a consultant, going into a business and trying to encourage the adoption of these practices. Your time is finite, so between yourselves choose 5 do, and 5 do-not cards that you absolute can not do without. [5 mins] All of these tickets should be important to you. So instead of dot-voting, you have $100 budget. Allocate your $100 among the tickets. http://www.liberatingstructures.com/14-min-specs/ https://www.workshoptactics.com/pages/100-dollars

Load testing with artillery

So you need to load test an application to find its maximum capacity? This set of basic scripts will get you started. Install artillery with: npm install -g artillery … assuming you already have npm installed. The premium version of artillery comes with all sorts of fancy features, such as the ability to run distributed load tests. But the free version is more than enough to do a basic set of tests. As a word of warning, if you’re running this against a production system, you’ll want to schedule it to run out of hours. loadtest.ps1 Npm only allows a certain amount of CPU to be in use by a process before it starts throwing warnings out. So to get around this, we can spawn multiple processes using this script: param ( [int] $clients = 1 ) <# .SYNOPSIS Run load tests .PARAMETER clients Runs this many concurrent load tests .EXAMPLE .\loadtest.ps1 This will run the load test with a single client .EXAMPLE .\loadtest.ps1 -clients 3 This will run the load test with three cl

Taking a memory dump of a w3wp process

Taking a memory dump of a w3wp process Taking a memory dump of an IIS worker process in a live system can be problematic, as IIS will kill the process if it has been suspended for more than 60 seconds. Only use these steps if your application is on a high availability cluster, else you’ll take your app down! copy sysinternals procdump.exe and pssuspend.exe to target machine create powershell file with: $iispid = Get-Process svchost | ? { $_ . modules . ModuleName -eq "iisw3adm.dll" } | Select - First 1 - ExpandProperty Id $workerpid = Get-Process w3wp | Sort ws - Descending | Select - First 1 - ExpandProperty Id & ".\pssuspend.exe" $iispid Write-Output "Creating memory dump for w3wp PID $workerpid " & ".\procdump.exe" - ma $workerpid & ".\pssuspend.exe" $iispid - r (taken from stackoverflow ) 3) check the w3wp process has reached the high level of RAM usage that you’re intending to

tempdb

Image
So what is tempdb? Well… it’s is a system database that is used by queries that contain: joins, aggregations, cursors, xml variables, triggers, online index builds, sorting, hash matching, temp tables or table variables. There are other bits that use tempdb, but they’re beyond me right now… How should it be configured? 8 tempdb files, 1024mb initial size, 256mb auto growth (unlimited), all located in the same directory. The files must be evenly sized, otherwise more traffic will go to the largest file.

Integration Testing with Cypress

To give a bit of background… I’m working with a small, cross-skilled team of Ruby and dot-net engineers, and we were interested in streamlining our awkward development process. We were feature branch based, but were hoping to incrementally move to trunk based CI/CD. One part of our process that we wanted to optimise first was the QA’s manual regression testing. Doing the same tests over and over is not only a waste of their time, but can’t be the least bit fun. For each test our QA was manually conducting we instead wanted to pair up and write an integration test. This would not only give us better confidence to release, but also expand the automation skill-set of our QA. These tests should automatically run as part of the GitLab pipeline whenever code is committed to source control. If any of the tests fail then the pipeline is to be marked as failed. What is Cypress? Enter cypress.io . This is an opensource javascript framework that can run a set of integration tests from t

Search for Text in all DB objects

The other day I needed to alter a bunch of sprocs, views, and UDFs, as they had hard-coded references to other databases. I needed to change these to target a different database for testing some new indexes. This bit of SQL saved me a bunch of time: SELECT OBJECT_NAME ( id ) AS ObjectName , [ text ] as ObjectDefinition FROM sys . syscomments WHERE [ text ] like '%\[Foo\]%' ESCAPE '\' FOR XML PATH(' Row '), root(' Table ' ) It outputs a single xml doc that contains the definition of every database object that contained your search terms. This allowed me to easily search through them and update accordingly.