| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |
Only if you've allowed a subclass of the PhoneNumber class to be AmericanPhoneNumber ... hang on, that can't be the correct approach - where's me gang-of-four, I feel a Pattern coming on ... |
Re: Self Documenting
2012-05-02 15:30
•
by
Some Damn Yank
(unregistered)
|
From a practical standpoint this actually isn't a bad idea. For example, no value in the AreaCode and CentralOffice classes should be of the form N11 as those are reserved for 411, 911, etc. Also, the allowable values in the AreaCode class are well-known, as new area codes are introduced in a controlled fashion by a central authority, much like state/province codes and zip/postal codes, so ideally you'd make the user select from a list, or at least validate what they type. Then there's the whole country code business, too, which is also a well-known fixed set, so if you're doing international phone numbers you need a CountryCode class. There's no reason for the PhoneNumber class to know how to validate all these parts. When you're looking at the PhoneNumber class you can easily see what it does without getting into the details of validating an area code, and if you want to see that you just look at the AreaCode class. |
Re: Self Documenting
2012-05-02 15:36
•
by
Some Damn Yank
(unregistered)
|
That's NorthAmericanPhoneNumber - per Wikipedia, the United States and its territories, Canada, Bermuda, and 17 nations of the Caribbean use that format. |
|
ThisFunctionReturnsTrueIfInputParameterArgumentIsOneAndFalseIfInputParameterArgumentIsZero(int InputParameterArgument)
{} |
Re: Self Documenting
2012-05-02 16:38
•
by
The Mr. T. Experience
(unregistered)
|
|
Your mom had to call Maury because she was quite the gang-of-four whore. The worst thing is you still don't know who's your daddy, and you got to see four dudes dance a celebratory jig.
|
Re: Self Documenting
2012-05-02 18:12
•
by
gratuitous_arp
(unregistered)
|
Ah, I thought you were using "properties" as a general description for class attributes -- I wasn't aware that Python had a property keyword. I still have a hard time understanding the disagreement expressed at having some unneeded but trivial get/set functions, and how this is worse than having code use multiple ways of accessing a member variable in the same way. The difference between obj.setVar() and obj.var isn't clear without looking through the class file. The "property" keyword seems like a get out of jail free card -- it shouldn't be part of the plan, but it's very handy when you need it. Maybe as I think about it more, I'll see the light that you see. In any case, thank you for taking the time to explain. |
|
What is "frist", and which purpose did your post serve?
|
|
It scares me that I had to get half way down page two of the comments before reading a comment by someone with a brain.
|
Re: Self Documenting
2012-05-03 06:46
•
by
eric
(unregistered)
|
|
Perhaps he expected validation checking to be more complicated, but it didn't end up that way.
|
Re: Self Documenting
2012-05-03 08:07
•
by
Hmmmm
(unregistered)
|
I'm not sure if you meant to reply to my comment as I don't see the connection and I assume you haven't read all the comments yet but if you have then can you explain how the complexity of the required validation checking has any bearing on why he felt it necessary to write the bool wrapper functions when they are only used after an explicit, fairly well named, test, e.g. if (NoActivityTypesAreAttachedToThisEvent(activityTypes)) return TrueBecauseThereAreNoActivityTypesToFilterOnThisEvent(); The Because... stuff is implicit in the fact that it is being done as a result of the test. The only thing that could possibly induce me to change my opinion about this code is if the original author gave a different reason (and I would still find it very hard to believe). |
Re: Self Documenting
2012-05-03 08:30
•
by
clive
(unregistered)
|
And in that case, changing what the function does so it no longer agrees with the name should also be done with a similar amount of caution. Adding some logging code to a "GetTransaction" method is fine, adding some validation is probably fine, and neither require a name change. If you're adding something which requires a name change, you're back in 'serious problems' territory. |
Re: Self Documenting
2012-05-03 12:24
•
by
Lurch
(unregistered)
|
|
Re: Self Documenting
2012-05-02 13:40 • by Jay Re: Self Documenting: Rodd: Matt Westwood: You're doing it wrong. A phone number should be defined by a class in its own right with its own internal validation. If you're holding it as a string and banking on the class you're holding it in validating it, you've got it backarsewards. Obviously. And inside that class, you store a PhoneNumberDigitArray class containing 9 instances of the PhoneNumberDigit class. For north american phone numbers, ten instances would be more effective - but good point anyway. That's why the PhoneNumber class needs to be subclassed into AmericanPhoneNumber, BritishPhoneNumber, RussianPhoneNumber, etc. =========================== NO NO NO What about Skype? You need a VoiceCommunicationsFactoryFactoryFactory returning an InternationalPhoneNumberFactoryFactory returning a PhoneNumberFactory, returning a PhoneNumber object. Yeah, that's a good start. |
|
Three things could be at play here
1) idiocy 2) The developer thought the evaluations would need to be more than they actually turned out to be (Kind of YAGNI - see #1) 3) There is some injected tracing/diagnostic code that gets put into the product at a later state. AOP or something like that. But its probably #1. |
|
What does a 50 characters identifier has to do with memory? Much less performance?
Compiler theory indeed.... |
|
I believe it originated on Slashdot. At least, that's the first place *I* saw it, although there may have evolved elsewhere, or evolved multiple times in parallel.
Whenever a new article would go up, some lamer would try to claim "First post!" in the comments section, without adding anything to the conversation. On Slashdot, I believe they started moving such comments randomly down the page, so the next step naturally was to mis-spell it, leading to "frist post" or "frost pist" or any other tortured locutions. On FARK, the phrase "first post" gets turned into "boobies", and "last post" gets turned into "wieners", if I recall correctly. Its filter was inspired by similar problems. |
For interpreted code (remember BASIC?), it ate up your variable store. Depending on your flavor of BASIC, it could also lead to lower program speeds for variable lookup. For compiled languages, shorter variables and terser comments lead to smaller source files and therefore faster floppy disk access. (Remember those?) I'm always surprised how large my source files are, and then I remember I use spaces instead of tabs, have full-paragraph comments when needed, and write things out long-hand when it helps clarity. When I look at a floppy's worth of source code from 30 years ago, I think to myself "wow, that's terse." And then I realize "But if it were less terse, the source probably wouldn't have fit on that floppy alongside the executable." |
That's true these days. There was a time not that long ago when such a loquacious program might not fit cleanly in the system memory, though, or would fill your floppy prematurely. I have written compiled programs on an Apple ][, where the computer had 128K and the floppy was only 140K. One valid criticism against such verbosity is that my ability to read and discriminate between strings falls off quickly with length. If faced with two long identifiers that differ only in one word in the middle, it's sometimes difficult to keep them straight. |
Re: Self Documenting
2012-05-03 21:19
•
by
Luiz Felipe
(unregistered)
|
But we build intagible things, that is the problem. |
And hey, it's a built-in time bomb, too. If the customer doesn't update, and new area codes get introduced: poof -- they can't handle customer phones in those. |
I think you still don't get it, though! Python properties are completely generic attributes of a class, so you thought right and it doesn't make the property system somehow impossible, not at all. All that is special about the properties is that they are bound to an interesting object. The property "keyword" is a plain old built-in library function. It returns a customized property object, that's all. Said object has getter, setter and deleter methods that invoke the relevant functions passed as arguments in the property() call. AFAIK you can write your own reimplementation of the built-in property(), there's nothing magic about it. Python has a few fairly powerful mechanisms like that. Another interesting one is the decorator system. A decoration is just you telling the compiler to pass the decorated function as an argument to a decorator, and binding the return value of such a call to the decorated name. A decorator is just a function, only that it expects a callable object (say, a function) as an argument, and should return a yet another callable object. The latter can wrap the invocation of the former in some clever way -- say, by building up a property object. This is why property getters/setters/deleters can be just as well declared by using decorators. Here's a pretty example from StackOverflow: def makebold(fn): |
Ye gods, it's functional programming!
2012-05-04 06:17
•
by
Watson
|
Callable objects? Passing functions as arguments and return values?! WHAT MANNER OF SORCERY IS THIS?!! |
What have identifiers to do with performance. |
Don't feed the trolls. He's a Web 2.0/Facebook/iPad kid imposing a Real Programmer who uses Real Compilers. |
Actually quite a lot of the modern compiled languages (Java, C#, to name the most popular) provide a feature called Reflection that allows to access attributes and methods of an object by name. To be able to do this, the names of the attributes and methods must be present in the runtime environment - the compiler will not erase them! You can use byte code obfuscators to replace your long identifiers with shorter ones, but reflection will not work for the obfuscated code. |
|
bling blong blang, this isn't spam...
TheOnlyProblemWithThisIsThatAfterThreeToFourWordsTheReadabilityOfAMethodIsCompletelyDestroyedOhAndReturnTrue(); |
|
Looks like COBOL to me!!
|
Re: Self Documenting
2012-05-05 04:10
•
by
pressureman
(unregistered)
|
Most languages implement message digests (and crypto functions) like this, because they're designed to be fed input in chunks. Consider generating a hash of a 4.7GB DVD ISO. Do you want to feed all 4.7GB at once to your hash function? |
Re: Self Documenting
2012-05-11 06:55
•
by
LeChuck
(unregistered)
|
|
return "Fail";
|
Re: Self Documenting
2012-05-13 21:14
•
by
Andrew
(unregistered)
|
|
The rule to always encapsulate your field is there because there is a need to change without propagating to client, and the rule is there unchanged.
In C++, if you exposed a field, and then some client depended on it, there is no way you can change that to a property without touching client code. So you better write the accessor methods. In C#, with the property keyword, make life easier. When code is changed from a field to a property, client code does not need to change, but they need to be re-compiled. To make life easier, it is better to expose as property to begin with. In Python, it is possible now. No code change, no recompile. Still, the rule doesn't quite change. We should always encapsulate the field to make it possible to change, it is just that the authoring needed to accomplish this changed. The key is to keep the capability to add logic at field access. |
Re: Self Documenting
2012-05-15 14:51
•
by
A. Nonymous Coward
(unregistered)
|
You're both doing it wrong. Anyone who creates a class for a phone number should stick to astronaut architecting at home, and stay away from production code. |
Re: Self Documenting
2012-05-15 19:26
•
by
Gedhead
(unregistered)
|
I remember when engineers built bridges, and programmers wrote code. |
Re: Self Documenting
2012-06-20 13:16
•
by
comment'appelle tu
(unregistered)
|
|
I was always told not to rely on remembering, but to use comments.
"I'm going to get some tea now." |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |