Development questions…

I’ve been working on compiling a set of questions we should ask at the outset of each new feature. In my experience, teams often become laser-focused on coding and implementing new features without considering the broader context. I believe it’s crucial to be proactive and demonstrate the value of our work to the company, as ultimately, the bottom line is what matters most.

For every new feature, let’s ensure we ask these questions. The responses we gather can then inform the creation of tickets and specifications, ensuring that we’re aligned with both technical requirements and organizational objectives.

AspectQuestions
Top Level User Story– What is the main objective or goal of this feature/change?
Security Concerns– Are there any potential security vulnerabilities or risks associated with this work?
Organizational Policies and Processes– Are there specific policies or processes that need to be adhered to during development?
Value Addition– How does this work enhance the application/product?
– What additional benefits or improvements does it bring?
Justification– Why is this work necessary or important?
– What problem or need does it address?
Proving Worth– How can we demonstrate the impact or value of this work?
– What criteria or metrics can be used to measure its success?
Monitoring– What metrics or indicators can be used to track the performance or usage of this feature/change?
– How will we monitor its effectiveness over time?
Technical Requirements– Are there any specific technical constraints or dependencies that need to be considered?
– What technologies or frameworks should be utilized for this work?
User Experience (UX)– How will this work impact the user experience?
– Are there any usability considerations to be aware of?
Testing and Quality Assurance– What testing strategies will be employed to ensure the quality of the implementation?
– Are there any specific test cases or scenarios that need to be addressed?
Scalability and Performance– How will this work scale as the application grows?
– Are there any performance considerations or benchmarks to meet?
Documentation– What documentation needs to be created or updated as part of this work?
– How will knowledge transfer be facilitated for other team members?
Deployment and Rollout– What is the deployment plan for this work?
– Are there any rollout or release strategies to consider?
Feedback and Iteration– How will feedback be collected and incorporated into future iterations?
– What mechanisms are in place for continuous improvement?
Collaboration and Communication– How will communication be maintained between team members and stakeholders throughout the process?
– Are there any collaboration tools or platforms to be used?
Risk Management– What potential risks or challenges could arise during implementation, and how will they be mitigated?
– Is there a contingency plan in place for unexpected issues?

Replacing ObjectId with a string in JSON. Using RegEx

Problem: I have a data dump of a MongoDb query in a JSON file. I need to replace the ObjectID(“12345677abc”) with “12345677abc”.

Using Visual Studio Code’s find and replace

Find:

ObjectId\("([0-9a-fA-F]{24})"\)

Replace with: “$1”

Turns this

"_id" : ObjectId("5e3b1890e032d225a091d43f"),
"userId" : ObjectId("65ed1c2c-922c-4c82-b5bc-7324f69eea10"),

To this

"_id" : "5e3b1890e032d225a091d43f",
"userId" : "65ed1c2c-922c-4c82-b5bc-7324f69eea10",


Bonus:

ISODate\("([^"]+)"\)

Mastering New Software with Ease: The Three “Software Whisperer” Principles

Introduction:
Have you ever wondered how some people effortlessly grasp new software applications with minimal training? I was intrigued by this ability and decided to explore the secrets behind their success. Through my journey, I discovered three powerful principles that transformed my approach to learning new software. In this blog post, I’ll share my experience applying the three “Software Whisperer” principles that have made me a more adept learner in the digital landscape.

Embracing the Intuitive Explorer:
The first principle I adopted was the fusion of intuition and curiosity as a powerful learning tool. I began trusting my instincts and letting my inquisitiveness guide me as I delved into new applications. Embracing various approaches and adapting my mindset based on my discoveries proved highly effective. With each encounter, my intuition strengthened, enabling me to navigate new software environments effortlessly.

Uncovering the Hidden Threads:
Identifying similarities with applications I’d used before became my focus. I familiarized myself with common user interface patterns and leveraged transferable skills from past experiences, which significantly accelerated my learning. Embracing trial and error allowed me to learn from mistakes and refine my approach. By unveiling the hidden threads connecting interface patterns, transferable skills, and trial and error experiences, I quickly mastered new software.

Becoming an Analytical Visionary:
Applying analytical thinking, problem-solving skills, and visual thinking also played a crucial role in my software learning journey. I broke down complex tasks into manageable steps and analyzed the underlying logic of the software to comprehend its workings. Creating mental images or visual representations of information within the application aided in grasping complex concepts and systems. The combination of these three aspects empowered me to conquer challenges and navigate new software with ease.

Conclusion:
By applying the three “Software Whisperer” principles—Embracing the Intuitive Explorer, Uncovering the Hidden Threads, and Becoming an Analytical Visionary—I have significantly improved my ability to understand and use new software applications with little to no prior training. While patience and persistence are essential when venturing into unfamiliar digital terrain, the rewards are well worth it. I now conquer software challenges effortlessly, akin to a true Software Whisperer. I encourage you to try these principles for yourself and witness the difference they can make in your software learning journey. Trust me, they have been a game-changer for me, and I believe they can do the same for you too!

Time to come clean, I used ChatGPT to create this! I copied the original text (see link below) pasted into ChatGPT and experimented with different prompts.

Reference: https://www.linkedin.com/pulse/unlock-your-inner-software-whisperer-3-simple-vishvakanth-alexander%3FtrackingId=u0nGp05rTpawtiS5CF9NAQ%253D%253D/?trackingId=u0nGp05rTpawtiS5CF9NAQ%3D%3D

With a “Ranting Donald Trump” prompt:

Then, we’ve got the Hidden Threads. You won’t believe what I uncovered. I looked at other applications, and I saw similarities, big similarities! It’s like they were all connected, like a beautiful web, a tremendous web!

Postman and Faker

I am a huge fan of Postman when developing API’s. I dont think i use even 20% of its abilities.

Today I found out that the Postman Pre-request scripts also have access to Faker.

Here is an example dynamic request body for creating a user.

const randomInt = Math.floor((Math.random()*100 +1));

const firstName = pm.variables.replaceIn("{{$randomFirstName}}");
const lastName = pm.variables.replaceIn("{{$randomLastName}}");
const domain = pm.variables.replaceIn("{{$randomCompanyName}}").replace(/[, ]+/g, ".").trim();


const body = {
firstName,
lastName,
email: ${firstName}.${lastName}@${domain}.c
om

}

pm.environment.set('body', JSON.stringify(body))

Here is Postman’s list of Faker options

https://learning.postman.com/docs/writing-scripts/script-references/variables-list/

API development: Lazy tip # 25

TL;DR;

Use cURL and pipe to json_pp “| json_pp

So for the longest time when working on API’s my process would look like this:

  • Write code in Visual Studio Code
  • Change to Postman and click send (try again as Nodemon has not finished restarting)
  • Check result
  • Change back to Visual Studio Code
  • Repeat

But now its

  • Write code in Visual Studio Code
  • In the Visual Studio Code terminal press ‘up arrow’ then ‘return’
  • Check result
  • Repeat

This has speeded up my development and reduced frustration.

How?
In the terminal I make use of cURL and append the command with | json_pp

For example

curl --location --request POST 'localhost:61100/my-service/report/progress' \
--header 'Authorization: <token> \
--header 'Content-Type: application/json' \
--data-raw '{"ids":["5d765d10a13c116f3ce44d04","62bc1433eb87da610a436a48","62bc7a1147f2e0f3854aa268","62bc2dd747f2e04f724a9e26"]}' | json_pp

Top tip:

Use postman on the first iteration, then use it to export cURL command

NPM update

So, for a long time now our projects CI/CD pipelines have an audit step and will prevent merging if there and high risk issues. Nothing complicated just

npm audit

Then a developer would need to sit down and follow their own approach to updating NPM packages. Mine was to install all the patch versions – test, minor versions and test. Then I’d take a stab at any major versions after reading any release notes.

See: https://docs.npmjs.com/about-semantic-versioning

It works, but it is a pain.

Then I found NPM GUI

https://www.npmjs.com/package/npm-gui

After installing it globally, I run the following command

npm-gui

This opens a browser tab and will first show all the global packages and versions. Navigate to your directory that has the package.json file, a nice table of installed node packages is displayed with required, current, compatible and latest versions. Clicking the versions will install them.

I still follow the same work flow of patches, minor and major versions but it takes me far less time and cognitive load to update projects.

It might not be perfect, but the rest of my team have started using this and its helped overcome the dread of package maintenance.

Code rot and technical debt

I do not know why “technical debt” is such a common phrase in the developers world? Or why “code rot” is so rarely used as they are both essentially the same thing.

Actually I do know why.

  • “Debt” implies that at some point in the future time and resources will be made available to address the short cuts, the rushed code, the fixes to the fixes
  • “Rot” implies that what has been created is rotten, dead and worthless.

But how often is time, money and resources allocated to pay back the “debt”? Can you go to a client and say, “Yes its working well enough today but we can make it better” Or how do you demonstrate the return on investment to a client?

Maybe by having an explicit understanding how the rot develops can slow its progress. How about these 3 sources of debt/rot?

  • Deliberate debt. Limits on time and money necessitate the need for a quick delivery.
  • Accidental debt. Where decisions made early on in a project might not be the best solution as the project evolves and requirements change. Additional new functionality will become difficult and slow to implement. Incremental refactoring might not be the solution and a more rigorous approach to refactoring is needed
  • Unnecessary complexity through lots of incremental changes, often exacerbated when multiple individuals or teams work on discrete aspects of the code with out fully understanding of original code or design decisions

I’ve spoken to friends who work in other industries about this and I feel that coding in its many forms suffers from lack of scheduled/planned maintenance. Which is fine until 6/12/18 months down the line something stops working.

JS does a string/number exist within a nested array collection?

I have the following and need to test if a user id is present anywhere in the collection.

const meetingCollection = [
  { id: "2", userIds: [12, 34, 55, 6, 7, 43543, 45345, 545] },
  { id: "21", userIds: [3, 425, 5, 33, 7, 68, 76, 99, 66, 99] },
  { id: "22", userIds: [767, 5654756, 5658, 86, 45, 23456, 666] },
  { id: "23", userIds: [6, 43562, 5645747, 4654, 2577, 4345, 45777] },
  { id: "24", userIds: [45645, 124, 4, 435, 6, 7755, 7, 8] },
  { id: "25", userIds: [1, 2, 455, 647, 753] },
]
const queryString = 7755;

meetingCollection.some(m => m.userIds.some(userId => userId === queryString))

Array.prototype.some() tests the method against each “row” of the collection and returns true on the first hit and then stops. If you have a 1000 elements and the method returns true on the 10th iteration .some() stops looping over the collection and returns true.

If a method fails to return true then false is returned.

The above example I’ve nested .some()

Try this in the console….

const meetingCollection = [
  { id: "2", userIds: [12, 34, 55, 6, 7, 43543, 45345, 545] },
  { id: "21", userIds: [3, 425, 5, 33, 7, 68, 76, 99, 66, 99] },
  { id: "22", userIds: [767, 5654756, 5658, 86, 45, 23456, 666] },
  { id: "23", userIds: [6, 43562, 5645747, 4654, 2577, 4345, 45777] },
  { id: "24", userIds: [45645, 124, 4, 435, 6, 7755, 7, 8] },
  { id: "25", userIds: [1, 2, 455, 647, 753] },
]

const findId = (queryString) => {
  return meetingCollection.some(m => m.userIds.some(userId => userId === queryString))
}

console.log(findId(2577)); // true
console.log(findId(257)); // false

JS rounding numbers

I have a requirement to be able to round numbers to either a whole number or to a specified number of decimal places….

Every now and then i find myself looking over my current solution to a problem when applying it in a new project. In this case it was very simple statistics and mean values.

For example:

const dec = [2, 678, 65.67467, 10.5452453453, 1, 0];
// Required outcome to 3 decimal places
// 2, 678, 65.675, 10.545, 1, 0

// Or to 2 decimal places
// 2, 678, 65.67, 10.55, 1, 0

My solution:

const round = (n, decimal = 2) => {
    return Math.round(n * Math.pow(10, decimal)) / Math.pow(10, decimal);
};
// Quick test
dec.forEach(n => {
console.log(round(n, 3));
});

dec.forEach(n => {
console.log(round(n));
});

As an aside: I need to have a set of numbers rounded and set with 2 fixed decimal places. So the same data set would be:

const dec = [2, 678, 65.67467, 10.5452453453, 1, 0];

// Required response would be
// 2.00, 678.00, 65.67, 10.55, 1.00, 0.00

There is the Number.toFixed() method

dec.forEach(n => console.log(n.toFixed(2)));

Visual Studio Code – colours

Background: I am working developing a number of Express.js micro services and at times I have two or three VSCode windows opened at once. After a long day it gets confusing which project I am working on.

To solve this I found out that you can change the colours of the top and bottom bars. Now each of the projects is colour coded and reduces my cognitive load a little bit.

In VSCode create a folder called .vscode an in that a file called settings.json. For the above dark green and off white colour scheme

{
  "workbench.colorCustomizations": {
    "titleBar.activeBackground": "#1d7e05",
    "titleBar.activeForeground": "#e1dcdc",
    "titleBar.inactiveBackground": "#1d7e05",
    "titleBar.inactiveForeground": "#e1dcdc",
    "statusBar.background": "#1d7e05›",
    "statusBar.foreground": "#e1dcdc"
  }
}

Top Tip

Don’t make the colours too bright or you will get “after image” which is a bit off putting.

https://en.wikipedia.org/wiki/Afterimage