Is it common to spend the whole day building a single function

Is it common to spend the whole day building a single function
0

Just spent probably 6 hours straight working on getting a uri validator to work just right.

I think i understand now that tests are just basically debuggers that you write yourself.

Heres my repo - code critiques are welcomed

I’d say it depends on the function’s requirements. One function might be “figured out” before you even finish writing the name of the method/function. In other cases you find a function isn’t even doing its job after you get it to pass all the originally written tests. Such is the nature of code itself :smiley:

There are a few things when it comes to development that are in the realm of “don’t do it yourself if you can”. Time/date related stuff is one, complex validators are another.

The reason for this is simple, there is a spec that is to be followed for the requirement, then tests that need to be written covering the spec, then code that is written that passes the tests. Screwing up any of the steps will result in the code not working as expected. As such covering all the use-cases might not be worth your time.

Here’s a fantastic video about the nightmare that is date/time validation

I’d say kinda sorta. I consider tests to be the actual requirement that needs to pass to verify the code works as intended for that use-case.This sort of thinking is great for unit testing, which is what your going for at this stage. :smile:

Finally I want to bring up the good old advice of “don’t reinvent the wheel”. Its one thing to re-invent the wheel, its another to re-engineer a complex solution to a complex problem that is already solved. Such a path usually results in extra work, code that doesn’t work as well as the original and extra bugs down the line due to missing use-cases. If you can’t don’t re-do it unless its trivial. URL parsing is semi trivial, but I’m sure there is a trivial solution already out there that has done the work.

Good luck :smile:

PS. In your code I recommend using Python’s multi-line doc strings rather than single-line ones when writing comments for docfiles. This actually **allows python to leverage the comments as part of the code (!!!) which isn’t true for single line docstrings.
Here’s an example:

def my_func():
  """
  Mind blown!
  """
  print("foo bar")

my_func.__doc__ # Mind blown!
2 Likes

Yeh I was wondering about that. I thought the single line didnt look as messy but its worth it for the docfiles

httrack on linux already does the thing im trying to build but there are things i dont like about it that I want to improve on, also I thought it would be fun and great for the experience which Ive gain a lot of since starting. for now im cool with reinventing the wheel for the sake of learning, but yeh if im building for other people then im using standard lib, pypi and npm all day

1 Like