Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Welcome to the world of programming!</strong></p> <p>I don't think your question is a symptom of an error on your part. Rather it is a <strong>basic problem</strong> which appears in many guises throughout the programming world. Strings that have some structure and <em>meaning</em> are passed around between different subsystems of an application and each subsystem can only do much parsing and validation. </p> <p>The problem of verifying an email address, for example, is quite tricky. The regular expressions various people offer accepting an email address, for example, are generally either "too tight" (don't accept everything) or "too loose" (accept illegal things). <a href="http://www.regular-expressions.info/email.html" rel="nofollow noreferrer">The first google hit</a> for 'regex "email address"', for example says:</p> <blockquote> <p>The regular expression I receive the most feedback, not to mention "bug" reports on, is the one you'll find right on this site's home page: \b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b Analyze this regular expression with RegexBuddy. This regular expression, I claim, matches any email address. Most of the feedback I get refutes that claim by showing one email address that this regex doesn't match.</p> </blockquote> <p>The fact is the what is or isn't a valid email address is a complex problem, one that a given program might or might not want to solve. The problem of URLs is even worse, especially given the possibility of malicious URLS. </p> <p>Ideally, you can have a library or system-call which solves problems of this sort instead of doing anything yourself (Microsoft windows calls a custom dialogue box to allow the user to select or create a file, since validating file names is another tricky problem). But you can't always count on having an appropriate system call for a given "meaningful string" either. </p> <p>I would say that there no a generic solution to the problem of strings-with-structure. Rather, it is a basic problem that appears right when you design your application. In the process of <strong><a href="http://c2.com/cgi/wiki?RequirementsGathering" rel="nofollow noreferrer">gathering requirements</a></strong> for your application, you should determine what data the application will take in and <em>how meaningful that data will be</em> to the application. And this is where things get tricky, since you may notice the possibility that the app may grow in ways that your boss or customer might not have thought of - or the app may in fact grow in ways that none of you thought of. Thus the application needs to be a <em>little</em> more flexible than what seems like the minimum BUT only a little. It should also not be so flexible you get bogged down. </p> <p>Now, if you decide that you need to validate/interpret etc a given string, putting that string into an object or a hash can be a good approach - this is one way I know to make sure your interface is clear. But the tricky thing is deciding just how much validation or interpretation you need. </p> <p>Making these decisions is thus an art - there are no dogmatic answers that work here.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload