How good are my codes?

When we code, are we supposed to make sure our code works in all ramification, or just for a particular area of our scope?
For example, my JavaScript code for the Roman numeral converter project was only valid in the range of 1-10000.
It satisfied the checks, but can it be regarded as a good code?

Specifically about the Roman numeral converter - I remember from another thread that the largest Roman numeral is 3999, unless you use an additional system called vinculum, so the tests end at that number:

https://numeralsconverter.com/information/what-is-vinculum-notation/

But in principle you’re right, your code should work for all (relevant) ranges. If you write a converter for miles → kilometers, you don’t want it to break above 10000 miles.

1 Like

For conversion of that style, I think the solution is unlimited, but some solutions have restricted scope.

Not sure I understand what you mean, which solutions have restricted scope?

1 Like

I believe there are codes that have restricted range of solution. Please forgive my inexperienced little brain machine.

If your code covers the range of numbers expected by the tests, then you’re fine.

It’s a MVP - Minimum Viable Project.
A common term in programming is to start doing a program that does exactly what you were asked to do and little to nothing more. Because you don’t get paid for the extra work.

In more complex coding-tasks, you could always do more. Catch all kinds of invalid inputs, return all kinds of error-message, adjust for all kinds of possible specifications.

Depending on your field and the programs and customers, levels can change drastically.
Obviously when working in medicine, you cannot be like “maybe an error happens” because that could cost lives. Meanwhile in Web-Development, well maybe you make a mistake and a website looks weird or is down for a couple minutes. Not perfect but not that big of a deal.

The point is to value your time and you pay. Do you need to deal with bigger values? Will a bigger value cause any significant problems?

Also keep in mind “good code” is not only functional, but most importantly easy to read and understand. If you want to work on something, always consider that first.
Also also, the site is meant to learn to code. If you are concerned about your code being to restricted - just try to make it better. Shouldn’t be to hard to adjust the code to work for all numbers.

5 Likes

Technically, you are coding against tests (the curriculum is set up like doing TDD). So if you believe the code is not covering all cases then the issue is really with the tests.

Not saying the tests are set up to be all-encompassing, just that the tests are what you are coding against.

you cant really jump ahead of yourself and write “the best”, or the most contemporary code and in most cases there can always be enhancement. Meeting the requirements is enough, from there on any improvements are welcome and they come over time. As you go thru the courses and become more experienced, adopt more skills and techniques, you will produce better code, so look at it as work in progress, dont set higher standards than you can meet.

1 Like

Thank you so much for your contributions, I really appreciate.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.