From The Challenges - Sort
John Crickett
Helping you become a better software engineer by building real-world applications.
Welcome To Coding Challenges - From The Challenges!
In this Coding Challenges newsletter I’m sharing some of the common mistakes I see software engineers make when tackling the Coding Challenges.
I’m sharing the mistakes people make and some thoughts on how you can you avoid making the same mistakes when taking on the coding challenges or when writing software professionally.
Aside: Performance Quiz
If we re-wrote Docker in Python, what impact would it have on the performance of the containers you run?
If you want to understand Docker and figure out the answer, check out the build your own Docker challenge. By building your own Docker, you’ll gain a deeper understanding of Docker and become a better software engineer.
If you’d prefer a version of build your own Docker that has automated tests, then check out check out?codecrafters.io?build your own Docker. You can get?40% off?as a?Coding Challenges?reader plus it helps support?Coding Challenges.
If you’d rather I added automated tests, hit reply to this email or comment on Substack and let me know!
Recapping The Build Your Own Sort Coding Challenge
In the build your sort coding challenge the goal was to write your own version of the Unix command line tool sort!
It sounds like a simple utility, but if you build everything in this challenge you’ll be using five different sorting algorithms and at least three different data structures.
If you fancy giving it a go, check out the the build your own sort challenge now and come back to this when you’re done.
Five Common Mistakes Software Engineers Make Solving The Sort Coding Challenge
I’ve pulled together this list of common mistakes from the hundreds of submissions I’ve been sent privately and the many shared in the Coding Challenges Shared Solutions GitHub Repo.
Mistake 1 - Binary / Artefacts In The Repo
This is a recurring issue across many different submissions to many different coding challenges!
Source code repos are for source code. Binaries do not belong in them. It should be possible to re-create the binary from the source code so there is no need for the binary. Equally it’s not obvious from a binary if the current binary is built from the current version of the code or an earlier one. Or even if the binary has been compromised.
Mistake 2 - Pivot Selection For Quicksort
Don’t just pick the first element of the partition to be the pivot. This will lead to the worst-case behaviour of already sorted (or near sorted) input (which is common). Instead pick a random index or read up on the research into alternative pivots.
When it comes to quicksort, you should also consider the implications of large files. Think about the implications of large input and the recursive nature of quicksort.
领英推荐
Mistake 3 - Reading The Whole File Into Memory And Sorting That
A common mistake I see people making for all of the Unix command line tools is to load the whole file into memory.
The problem with this approach is that it doesn’t scale, if someone tries to use the program on a large enough file the program crashes having run out of memory.
If you’re writing code to handle files, do remember to check you can handle large files. Sure it’s not easy to test this - you might not have the disk space for a 100GB test file for example, but there are ways around this. For example to test?sort?with a large file we can leverage the power of the Unix command line tools to generate one on the fly without actually taking up any disk space.
Here’s how:
seq 1 300000 | xargs -Inone cat test.txt | sort
To address this mistake there are two steps:
As I understand it the original version of sort handles large files by splitting anything too big to fit into files sized based some portion of the total available RAM into several smaller files. I then sorts the smaller files and combines them.
Mistake 4 - Not Reading/Understanding The Requirements
Part of the benefit if building real-world software is having a clear unambiguous set of requirements. You make your solution have the same interface and produce the same output as the real thing.
When you ignore the specification, either in the coding challenge or implicit in the thing we’re cloning you build software that doesn’t work to specification.
Mistake 5 - Not Testing Edge Case
It’s easy as software engineers to take a requirement, code up the solution and check it works.
But that’s not enough, we should also think about the edge cases and error conditions and both code to detect and handle them and ensure we’re testing our handling of them.
It’s great to see tests in the submitted solutions, it would be even better to see tests that check edge conditions. For sorting, at very least consider:
Replace file with dataset if you’re testing the sort function rather than the whole program.
P.S. If You Enjoy Coding Challenges Here Are Four Ways You Can Help Support It
Full Stack Developer | React & Next.js | Freelance Professional
5 个月Absolutely love this approach! ?? Building real software is the best way to learn, and your project ideas are a fantastic resource
Tech Director @ Amazon Payment Services | I help professionals lead with impact and fast-track their careers through the power of mentorship | #1 LinkedIn Arab World Creator in Management & Leadership
5 个月Appreciate the challenges you share John Crickett - a true enabler of upskilling.
Assistant Professor @ SJEC
5 个月Absolutely love this. The point of pivot selection for quicksort is definitely interesting. Sometimes we fail to read the finer details (I know I do) but learning to look for them and correct them matters.
Providing services,digital marketing,marketing consulting,advertising,social media,real estate consultant,property investment adviser
5 个月Hey john you are spot-on but how could none techys wanting to start on such journey get along such track?
Software Engineer | Frontend | Backend | Creating Value & Solutions | Sharing Insights in Software Engineering | Author Inside Tech Newsletter
5 个月Absolutely! The best way to learn is to build something