Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write a bulletproof date validation routine.
#25
ToohTooh:

Quote:I'd like to clarify your concerns about my suggestion numbered (4) by giving a brief understanding of Discrete Maths. This is the area of maths which deals with discrete, unconnected objects, events which we use in analyzing our programming methodology -- that is algorithms, artificial intelligence applications, and so forth.
To be exact, Discrete Maths (a part of a.o. Linear Algebra) is the face of maths that deals with functions that cannot be expressed in multiple "normal" maths functions (like +, -, *, /, ^, int, diff, etc). Also, the return value of these discrete functions may differ completely from those in Algebra. Resulting from these 2 statements, we conclude that Discrete Maths cannot be analyzed by standard algebra only. That's why there is Discrete Maths. The easiest example of a discrete formula is:
Code:
f(x): x -> INT(x);
As you can see, this formula cannot be expressed in a normal algebraic formula.
Using this Discrete Maths, we can now analyze trends without using incredibly difficult algebra. The perfect example for this is trying to find an discrete formula for the amount of days in a specific month of a specific year. Wink This would then look something like this (my code):
Code:
f(m, y): m, y -> 30 + ((m + (m > 7)) MOD 2) + 2 * (m = 2) + (m = 2) * (((y MOD 4 = 0) AND (y MOD 100 <> 0)) OR (y MOD 400 = 0))
Of course, this formula will only be valid from a specific date in the past, as there were severe calendrical changes around year 1600-1700 and earlier.

Quote:(a) Algorithmic thinking: This deals with the ways we use to build unique solutions to the unique problems. My IsAValidDate() is a good example of this, and it is pretty well written: You can subdivide it into discrete sets to understand or test separately [IsALeapYear(), Tokenize()].
Exactly, but keep in mind that we need not build unique solutions for each unique problem. Many solutions for completely different problems may well suit on a specific other problem.

Quote:(b) Discrete structures: This deals with the ways we include "others' solutions" to our projects. What are they? Binary trees they are, linked lists they are, hashing they are. On many of them, much discussion have been made, and they are 'de facto' standards in some cases. Please refer to my suggestion numbered (1) of my past post to understand what I mean.
I'd like to make a note about this, correct me if I'm wrong. I think Binary Trees and Linked Lists are no specific solutions to any problem, so I don't think they will fit in as an example. This, as binary trees and linked lists were made in order to accomplish a specific goal using those things. In most cases, binary trees and linked lists are just ways or utilities to accomplish a goal. When cut loose from its purpose-serving environment, Binary Trees and Linked Lists are useless and are no goal on its own.

Quote:So, my efforts on suggesting 'break them down!' aren't just a matter of obsession, but the Computer Science itself.
Correct. It is essential in any field of computer science (and other) to break apart bigger problems into smaller, easier to solve problems. Of course, many big problems can be split apart in many different ways, and it's the trick to find a way that suits well your needs.

Quote:Let's say our IsAValidDate() went international to meet different sorting of Date, Month, Year trilogy. If we were to pack everything into a single function, testing and updating it would be tad more painful. Think of giant games, database systems, or operating systems functions!.. But in this case, we only need to update and test result = Tokenize(...) or better, just implement
Code:
result = Tokenize(FormatDa$(Da$), ...)
and only test FormatDa$() to see if it meets our criterias.
Make your functions orthogonal! It's the key in large scale programming. Making your projects this way will save you extremely much hassle later on, either when you need to correct bugs, or when you need to globalize your program (make it accept multiple data formats, often bound to specific countries).
As said before, the ideal orthogonal function doesn't depend on anything else but itself. In reality though, this ideal goal is often too imaginary to pursue. Try to make it as orthogonal as possible.

Quote:If you are interested, I may suggest you some books on Discrete Maths. But, better, search for them in your favorite searching engine. Even better, go to your local library and find the one which suits you best.
I have a very good book "The Pragmatic Programmer". It teaches extremely helpful things needed in programming.

Hope I was a bit useful,

Neo
Reply


Messages In This Thread
My entry - by Meg - 10-11-2004, 09:03 PM
updated - by Meg - 10-12-2004, 08:01 PM
/nod - by Meg - 10-23-2004, 01:34 AM
Foo - by ToohTooh - 10-26-2004, 10:36 PM
Reply on Clarification Suggestion - by Neo - 10-26-2004, 11:37 PM
Re: Reply on Clarification Suggestion - by oracle - 10-27-2004, 02:00 AM
Hmm... - by ToohTooh - 10-27-2004, 02:12 PM
Re: Hmm... - by Neo - 10-27-2004, 10:12 PM
Thank you. - by ToohTooh - 11-01-2004, 04:54 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)