I'm currently trying to improve the design of a legacy db and I have the following situation
Currently I have a table SalesLead in which we store the the LeadSource.
Create Table SalesLead(
....
LeadSource varchar(20)
....
)
The Lead Sources are helpfully stored in a table.
Create Table LeadSource (
LeadSourceId int,...
G'day Stackoverflowers,
I'm the author of Perl's autodie pragma, which changes Perl's built-ins to throw exceptions on failure. It's similar to Fatal, but with lexical scope, an extensible exception model, more intelligent return checking, and much, much nicer error messages. It will be replacing the Fatal module in future releases of...
In particular I'm looking for an IP address that I can put in my hosts file that will black-hole a given DNS name. Right now I'm using 127.0.0.1 but that would start acting odd if I installed any services.
How can I prevent a 3rd party program from contacting a given server?
...
Long before you practice writing readable code, what "magic numbers" you still remember up to this day?
here's some of my list:
72 80 75 77 13 32 27 - up down left right enter space escape
1 2 4 128 - blue green red blink
67h 33h 17h - interrupt for EMS, mouse, printer
function AH 9, interrupt 21
alt+219 for block ASCII
alt+164 ñ
90 N...
I want to get the size of a file on disk in megabytes. Using the -s operator gives me the size in bytes, but I'm going to assume that then diving this by a magic number is a bad idea:
my $size_in_mb = (-s $fh) / (1024 * 1024);
Should I just use a read-only variable to define 1024 or is there a programmatic way to obtain the size of a...
I've been working with xml lately. And have noticed a bit of a phenomenon (maybe not that big of a deal to the rest of the world, but to me it was). Perhaps, it is me being a newb. But shouldn't most hard coded or magic numbers be broken out to a configuration file? For example,
string url = "http://www.domain.com/aDocument.xml"...
I have seen this in legacy code and in some .NET open source projects.
I can't imagine a reason to do this. Just using "null" seems so much easier to me.
Example:
public class Category
{
int parentID;
bool HasParent
{
get
{
return parentID != -1;
}
}
}
versus
public class Category
{
int p...
Can I avoid magic numbers when matching keypresses in javascript?
An example would be using 13 to match the enter key.
I could specify my own constants, but I don't know if these values are stable enough across different platforms/browsers/locales.
...
A commonly used term is "Magic numbers". As discussed in a related question, this is considered a code smell. I assume the same would go for string constants, although the term "Magic strings" is not in common use.
So to generalize a bit, it would seem that ALL constants should be named, thus making them "unmagical". Or am I missing som...
There is a strange problem I've run in using RIM compression API, I can't make it work as it's described in documentation.
If I gzip plain text file using win gzip tool, add gz to resources of blackberry project and in app try to decompress it, there will be infinite loop, gzis.read() never return -1...
try
{
InputStream inputStrea...
News reports such as this one indicate that the above number may have arisen as a programming bug.
A man in the United States popped out
to his local petrol station to buy a
pack of cigarettes - only to find his
card charged $23,148,855,308,184,500.
That is $23 quadrillion (£14
quadrillion) - many times the US
nationa...
How do I store numbers in an Access column and then associate some meaningful string to each value?
Because I don't want to be seeing raw numbers when I can define the meaning of each value once at for all, and have those meanings displayed in the Datasheet View, like:
ID Name Type
1 Jack 1 (Friend)
2 Jill 1 (Frien...
Hi, I'll cut to the chase. I have two questions about switch that are simple, but I can't figure them out.
First:
in c# switch statements, do case statements have to be consecutive (with ints)?
For example:
switch(someInt)
{
case 1
// some code
case 2
// some code
case 3
// some code
}
or is it possible t...
We do a lot of lexical processing with arbitrary strings which include arbitrary punctuation. I am divided as to whether to use magic characters/strings or symbolic constants.
The examples should be read as language-independent although most are Java.
There are clear examples where punctuation has a semantic role and should be identifi...
I'm trying to code an applet and put it in my website. I remember doing this a long time ago using Borland back when 1.4 was the latest version. It of course used the applet tag (which I'm using currently) and it had no issues. But anyways, I put the class files in httpdocs/ under its own directory, and then used this code in the web ...
I have a few specific places in my code where I use specific pixel dimensions to blit certain things to the screen. Obviously these are placed in well named constants, but I'm worried that it's still kind of vague.
Example: This is in a small function's local scope, so I would hope it's obvious that the constant's name applies to what t...
Hi all,
I've a web page that that can be used to upload files.
Now I need to check if the file type is correct (zip, jpg, pdf,...).
I can use the mimeType that comes with the request but I don't trust the user and let's say I want to be sure that nobody is able to upload a .gif file that was renamed in .jpg
I think that in this case I s...
I was wondering whether others find it redundant to do something like this...
const double RESET_TIME = 0.0;
timeSinceWhatever = RESET_TIME;
rather than just doing
timeSinceWhatever = 0.0;
Do you find the first example to aid in readability? The argument comes down to using magic numbers, and while 0 and 1 are considered "exception...
Hi there,
I'm a fairly new programmer, and I apologize if this information is easily available out there, I just haven't been able to find it yet.
Here's my question:
Is is considered magic numbers when you use a literal number to access a specific element of an array?
For example:
arrayOfNumbers[6] // Is six a magic number in this...
Hi there,
I'm a programming student in my 2nd OOP course, which is taught in C++. I know that it is generally bad practice to use magic numbers in code, so here's my question:
In the next program I have to write for this class, there is over 120 numbers given to us in tax tables, and we need to use them to compute tax and other relevan...