- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
You have to use BBCode, but then, like breaks don't seem to work either. (Also, that posting on this forum has no Preview button, though I'm pretty sure its built-in.)
Admin
His colleagues at Bell Labs were sometimes equally unimpressed
to quote Bjarne :
"A notable exception to this agreement was Doug McIlroy, who stated that the
availability of exception handling would make systems less reliable because
library writers and other programmers will throw exceptions rather than try
to understand and handle problems. Only time will tell to what extent Doug's
prediction will be true."
On Thu, 20 May 2004, Rob Pike wrote:
> when ken and i described the new features we were proposing for plan 9 C,
> including inherited structure elements, to bjarne stroustrup, he said, "if you
> want C++ you know where to find it." and stormed from the room.
> i don't think he understood exactly why we were proposing these features.
> -roband to quote bj again (he really should come and read wtf) :
> "The C trick of having the declaration of a name mimic its use
> leads to declarations that are hard to read and write
Admin
This is a WTF even on its own terms. For maximum code reuse, fields should be Object, not String.
Admin
Maybe you weren't here, but the preview button caused ten times as many wtf comments. I kinda miss all the html spews now. ;_;
I'd love to meet the sap who has to come in and maintain a program with a complex algorithm punctuated by swarms of
out.field3 = dict.field1 * dict.field5;
See, I do it the PHP way, where with __get() and __set(), you can create a class that can define any variable, or even turn simple variable access into crazy functions. =D
$class->keanu('whoa');
$class->duck = '12'; // drop database
$twelve = $class->mong; // whatever duck was set to ends up here
Admin
Well, properties are harly anything new (but for Java guys that is). Ruby has them natively and in a most graceful way, Python has them as well (although the construct is much less graceful than Ruby's), even C# has them...
Methinks Java6 should do it the Ruby way, any getter and/or setter generates a property, read, write or both (if both getter and setter exist) and be done with it, maintains backward compatibility and stops having to write shitty code.
Admin
http://www.perkel.com/politics/gore/internet.htm
Admin
Oops.. ignore the above post :)
http://www.perkel.com/politics/gore/internet.htm
Admin
Do you know why I hate to read about politics?
Because they start the page with:
"Here's the story behind the story and you determine who is lying and who is telling the truth. "
And end with:
<FONT color=#c000a0>"So, it would appear that Bush is the one lying and can't be trusted. "</FONT>
<FONT color=#c000a0></FONT>
<FONT color=#c000a0>Yea, right.</FONT>
Admin
What I meant by my example is that __get() and __set() aren't tied to any property. One function controls all properties, rather than naming properties and calling get/set methods on them. The wtf is that there's no interface to document, and anyone who looks over the code of a sufficiently braindamaged class will have a siezure trying to figure out what to call. =D Plus the magic of no compile-time (or what passes for compile-time in php) checking.
Sadly, it's the only way to do that. Instead of providing properties with get/set, we get a bizarre universal catchall get/set property that I'm pretty sure no other language has. The only way around it is public members or individual methods.
Admin
Python?
LUA?
Admin
The third way around it is to not use, or at least minimize, getters and setters. See http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox_p.html for details. This article really needs a followup with some good examples, unfortunately.
Admin
Python actually has some "catchall" methods, namely __getattr__, __setattr__, __delattr__ and __getattribute__.
These "magic methods" are called when no existing member exists, and are given the attribute name that was called as their parameter. They are not used often, but allow for fine tuning of specific objects, and work on top (or behind) of the regular attributes/properties of the Python objects.
An object will, of course, resume to AttributeError exception if these methods are not explicitely implemented, and you as the implementer are supposed to throw it manually if the attribute name doesn't fit your filters.
Admin
Wonderful... Why not just:
<FONT face="Courier New" color=#000000>string serializedObject;</FONT>
Covers all bases and is very reusable [:P]
Admin
Yeah, that's what I meant, I just missed them when I went over python's OO a while back. It's good to know that bizarre mindfucks are somewhat portable. =D
Admin
You can always use your favourite aspect oriented weaver to really screw things up for the hapless sod who has to debug your work. A particular fave I left an employer was a horrible (partly necessary) solution which created classes and methods using Reflection.Emit and wove them into target classes. :(
Admin
Very interesting and usefull link, thanks.
Admin
Sorry to burst your bubble, but since "penta" is greek, just to be consistent, the successor would have had to be called "Hexium" ;)
Admin
'Hexium'? Oooh, that's pagan, innit? Can't have that, it might upset the fundies!
Admin
We have a more generic aproach, we use Object instead of Strings:
class Tuple {
Object a, b;
Tuple(Object a, Object b) {
this.a = a;
this.b = b;
}
public Object getFst() {
return a;
}
public Object getSnd() {
return b;
}
}
Admin
I hope he didn't get to Sextuple, don't want this guy reproducing
Admin
The advantage of using these structures instead of for example arrays is that the compiler can check the proper number of elements at compile time. For this reason using (public) inheritance for the longer tuples isn't a good idea.
Obviously these classes were written for a piece of code that manipulated only strings, otherwise they could be Objects instead of Strings - which would lead to horrible code clutter, casting to and back. Java Generics would (almost) fix that..
Many functional languages have tuples built-in to the language, so no need for hacks like these..
Admin
I'm not sure if that is sarcasm or not. If not then you missed the point. The intent was to replace all of the classes with a single String array object
Admin
No no no, this is NOT how you should do it.
Please observe this example:
public class Unary
{
int unaryID;
string field1;
}
public class Binary
{
int binaryID;
Unary unaryField;
string field2;
}
public class Ternary
{
int ternaryID;
Binary binaryField; //Brillant! Less code!
string field3;
}
Admin
Ah the beauty of java.util.Map.
public class Person
{
public String id;
public Map attributes;
public setAttr(Object key, Object value) {
this.attributes.put(key, value);
}
public getAttr(Object key) {
return this.attributes.get(key);
}
}
usage:
Person me = new Person();
me.attributes.put("field1", field1Value);
Or if you don't like all the dots, use the setter:
Person me = new Person();
me.setAttr("field1", field1Value);
Admin
Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide. [:O]
Admin
Properties go back (at least) to early Lisp (or LISP, as it was called then) implementations. I'm too lazy to look it up, but I'm guessing that this dates to around '61 (Lisp dates to around '59). Properties in Lisp are interesting in that they can be attached to any variable (well, any symbol, which is a slightly different thing). The implementation is generally not very efficient for large numbers of properties (usually a linked list of tuples), and I wouldn't normally use them in "real" code for reasons unrelated to efficiency, but they can be quite handy for prototyping.
Admin
That was really uncalled for. To think that the pun has been unjustly impugned, all these years, as the lowest form of humour...
---
I'd rather split etyms than atoms - James Joyce
Admin
<font size="2">public class Combination
{
private string id;
private string [] values = {};
public Combination(int length)
{
if (length > 0)
this.values = new string [length];
}
public string this [int index]
{
get { return this.values[index];}
set { this.values[index] = value; }
}
public string ID
{
get { return this.id; }
set { this.id = value; }
}
public int Count
{
get { return this.values.Length; }
}
public string [] ToArray
{
get
{
string [] clones = {};
if (this.values.Length != 0)
{
clones = new string[this.values.Length];
this.values.CopyTo(clones,0);
}
return clones;
}
}
}
example:
Combination c = new Combination(3);
c.ID = "Triplet";
c[0] = "Hello World!";
c[1] = "Test It";
c[2] = "Yesterday!!";
</font>
Admin
OneFactor: "Agreed, mixing your Latin and your Greek should be grounds for justifiable anthrocide"
On television.
Admin
<FONT face="Courier New" size=2>tbs presents, "my big fat latin/greek wedding"</FONT>
Admin
<FONT face="Courier New" size=2>i suppose one could make a union of pairs, triples, etc. what a pain in the ass. alright, check it. these structures are defined for primes up to say, 100. that's about 25 of them, no? they should be able to represent most numbers in common ranges, producing wider gaps as you get into larger and larger numbers. if one of these "skipped over" numbers is needed, create the missing factors and add them to the list. after a while, the probability of needing a "skipped over" number diminishes, and you get the minimal set of prime-tuples that are needed for your application. viola! the fewer basic structures used make the program run faster, since aggregates of structures are optimized by the compiler. everybody wins! yay!</FONT>
Admin
[:D] That's hilarious! I can't believe no one got that joke before now.
Admin
I was referring to this one:
I'm used to VBulletin, which autoquotes when you hit Reply... sorry. [:$]
Admin
That C++ code is truely scary. Just as I thought templates couldn't possibly be any worse, you drag me right back to earth again. :-)
It's truely a marvel.
Admin
Ironically most languages now suppport strongly typed Tuples... So the concept was sound, but the implementation was not.