Qbasicnews.com

Full Version: Write a bulletproof date validation routine.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Quote:Here's what I made today (in 20 minutes):.....
Looks interesting. Give me some time to run a test on it (more than 20 minutes) like I did with Meg's solution. I'll get back to you.
*****
Quote:Hello, Moneo......
ToohTooh,
Your dissertations are much Tooh much for me. :wink:
*****
Moneo:

Ok Smile
Btw:
[syntax="QBasic"]'prepare maxdays variable (numbers of days in the month)
I = Month
MaxDays = 30 + ((I + (I > 7)) MOD 2) + 2 * (I = 2) + (I = 2) * IsLeapYear[/syntax]
If this piece of code needs some explanation, just tell me Wink
Let's handle those!..

Hello, oracle!..
Quote:Having said what you did however, creating a whole function to do some very simple algorithm may do nothing more than clutter up the namespace and confuse some people... not so much a problem in object orientated languages however!
:humm: I think my 'dissertation' wasn't to the point on your side. *Sigh*, and such...

And, Mexico City!.. Hola!..
:o
Quote:ToohTooh,
Your dissertations are much Tooh much for me. :wink:
*****
You are getting on a bit, Moneo. Big Grin
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
Quote: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.

That's like saying the square root function has no use on it's own Wink. The square root function only helps you to accomplish a goal, but by itself it only calculates square roots. Binary trees only help you to accomplish a goal, but by itself only stores data providing log(n) add, search and remove (providing the tree remains height balanced).

ADTs are a way of storing collections of data, so in a sense they solve the problem of storing collections of data Wink
  • Tin openers, binary trees, and Anatolia Music;
    Car radios, orthogonality, and OO.
Neo, I like it!..

Let's take a peek... :wink:

Quote: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.
Well, no... This is like saying
Quote:I have a thing for tin openers; will they teach me how to design one if I am to enroll at Mechanical Engineering?
When you enroll at mechanical engineering, they won't be teaching you to design a tin opener. But, you will learn 'principles of designing.'

Binary Trees are just the same: It's your own duty to tailor them to your own needs. Computer Scientists of Turkish Ministry of Culture are designing a virtual 'Music Museum.' Artists will be able to search for matching notes. They are using Patricia Tries. Were scientists thought musical searching through Patricia Tries? Probably not (well, some new programmes have 'Musical Searching' CS courses in Turkey).

Quote:Make your functions orthogonal!
Your intent isn't clearly understood on the 'orthogonal design.' May be you are confused. Did you mean 'orthogonal expansions of recursive functions?' Or, 'orthogonal system design' of software engineering? I was thought some 'orthogonality' in Business Statistics when was in Business School, too. Either case, it would go beyond the scope of this forum.

'Orthogonally designed software system' is one which enables us to make complex designs feasible and compact. Orthogonality is achieved when technical effects (produced by a component) of modifying the system do not create or propagate side effects to other components of the system. I like it best when orthogonality meets encapsulation of object oriented languages.

Let's give an example: Does your car's engine start when you turn the radio on? Probably, not: Turning the radio on should influence no system other than the radio itself. System is orthogonal.

Much software is designed in a non-orthogonal fashion: Even much of Windows. Because, it is very hard to design one orthogonally. Personally, I haven't designed one, either (hey, I'm only 22).

Some books should occupy the rest!.. Happy reading!..

Orthogonality:
The Art of Unix Programming (http://www.faqs.org/docs/artu/).

Programming methodology in general and programming language theory:
Concepts in Programming Languages (Cambridge University Press, 2002), and
Theoretical Aspects of Object-Oriented Programming (MIT Press, 1994).

Discrete Mathematics:
(No books at my office -- I'll compile when I get home!)

Do a related search at:
http://www.lib.metu.edu.tr/
http://www.library.itu.edu.tr/
http://www.library.boun.edu.tr/
_____

Edit history:
(i) Links added, spelling corrected.
... am I the only person that has absolutely no idea what is going on in this thread?
Canopeners... music...

Quote:When you enroll at mechanical engineering, they won't be teaching you to design a tin opener. But, you will learn 'principles of designing.'
Binary Trees are just the same: It's your own duty to tailor them to your own needs. Computer Scientists of Turkish Ministry of Culture are designing a virtual 'Music Museum.' Artists will be able to search for matching notes. They are using Patricia Tries. Were scientists thought musical searching through Patricia Tries? Probably not (well, some new programmes have 'Musical Searching' CS courses in Turkey).
I noticed my thinking mistake after oracle posted his reply. Sorry about it. (I think I missed some steps in my logical thinking process).

Quote:Your intent isn't clearly understood on the 'orthogonal design.' May be you are confused. Did you mean 'orthogonal expansions of recursive functions?' Or, 'orthogonal system design' of software engineering? I was thought some 'orthogonality' in Business Statistics when was in Business School, too. Either case, it would go beyond the scope of this forum.
Every time I post "serious" posts like last one, it is preceded by a lot of thinking and logical deduction. I couldn't have possibly been confused, as I clearly have the same definition of orthogonality. The only thing might be that I explained it fuzzy and perhaps even incorrect. Again, sorry.

The orthogonality principle has much to do with the DRY principle. (DRY stands for "Don't Repeat Yourself"). And the programming rule derived from orthogonality:
Code:
PROGRAMMING RULE 13:
ELIMINATE EFFECTS BETWEEN UNRELATED THINGS
Design components that are self-contained, independent, and have a single, well-defined purpose.
(If you want to see more programming rules, just ask or PM me Wink)

This is my definition of orthogonality:
Orthogonality is a term borrowed from geometry. In computing, this term has come to signify a kind of independence or decoupling. Two or more things are orthogonal if changes in one do not affect any of the others.

The perfect example of a non-orthogonal system is an aircraft or helicopter. (Let's talk about aircrafts, I know more about them than about helicopters Wink).
Each normal aircraft has 3 basic movements, pitch using the elevators, yaw using the rudder and roll/bank using the ailerons. Though it might seem easy to control an airplane, all these movements have side-effects on other controls.
When you pitch, you speed will change as well, due to the change in angle of attack of the wings (inclination angle).
When you yaw, the airplane will tend to roll in the opposite direction, due to the fact that the rudder generates a force that will not only generate a moment in the topview axis (y), but also a moment on the longitudinal axis (x).
And when you roll, the airplane will tend to yaw in the opposite direction, since when you roll, the drag of the far wing increases, which causes the airplane to tilt back around it's topview (y) axis.
An airplane or helicopter are definitely not orthogonal.

Orthogonal systems have many advantages (semi-quoted from the TPP book).
- Gain productivity: changes are localized, development time and testing time are reduced.
- Orthogonal approach promotes reuse.
- A subtle gain in productivity.
Also, orthogonality reduces risk:
- Diseased sections of code are isolated.
- The resulting system is less fragile.
- Orthogonal systems will probably be better tested.

Quote:Much software is designed in a non-orthogonal fashion: Even much of Windows. Because, it is very hard to design one orthogonally. Personally, I haven't designed one, either (hey, I'm only 22)
I already said something similar in my previous post, and I think it can be stated that very few *real* orthogonal systems have been designed yet, as it is so difficult to make one. As far as I can see, even major software developers have trouble making it as orthogonal as possible.

Quote:Some books should occupy the rest!.. Happy reading!.
As I said, I already have a good book which almost covers every aspect of projects and programming Wink Btw, I don't really have the time to read books atm Wink

I hope I was of any use,

Neo

___________________
Note: This post has been created after thoroughly searching the book "The Pragmatic Programmer. From journeyman to master" by Andrew Hunt and David Thomas.
___________________

Quote:... am I the only person that has absolutely no idea what is going on in this thread?
Well, I think we're discussing some of the deeper topics of programming Wink
Orthoganality is like the concept of independence in statistics, as well as a concept from gemotry I think Smile. Object orientated libraries are a prime example of this - plug it in, read the API documentation, code your use of it. Performance gains using this method are huge Smile
Pages: 1 2 3 4 5 6