h a l f b a k e r yactual product may differ from illustration
add, search, annotate, link, view, overview, recent, by name, random
news, help, about, links, report a problem
browse anonymously,
or get an account
and write.
register,
|
|
|
Many object-oriented programming languages offer a "With" structure, which lets you quickly alter several properties of the same object. For example:
With MyPage.MyForm.TextBox1.Font
.bold = true
.italic = true
.size = 16
End With
But often you'd like to change the
same named property of several *different* objects, and so far I haven't seen a language with a statement that allows this. Here's what I'd like:
Concerning Font.bold
MyPage.MyForm.Textbox1. = True
MyPage.MyForm.Label1. = False
MyOtherPage.MyOtherForm.CommandButton1. = True
End Concerning
This would not speed up processing time, but it would make the syntax easier to read (for humans), and faster and less error-prone to type.
[link]
|
|
pardon my mixing metaparticles but "bold" is an attribute, not an object: if you want to do what you want to do you have to associate it with an object and transfer the object's properties, ie: if it seems that important then start looking for an heretofore intangible object you may have missed somewhere along the line. |
|
|
I think the more logical way to construct this is as a 'ubiquitous method' to any object within the current scope: |
|
|
function ubiquitous boldit(state)
{
try {this.Font.bold = state;}
catch {return false;}
}
MyPage.MyForm. Textbox1.boldit(true);
MyPage.MyForm. Label1.boldit(false);
MyOtherPage.MyOtherForm. CommandButton1. boldit(true);
|
|
|
[bs] you can do it in quite a few programming languages: I'm thinking a multiple "SET" type statement, but OO/C# no clue. |
|
|
Can I ask a silly question? Yes. May I? |
|
|
Is there a sort of meta-language that lets you write
sections of code in the most appropriate programming
language, something like: |
|
|
LANG=C++
do this; do that; do something else; this bit written in C |
|
|
LANG=FORTRAN
some cuneiform fortran |
|
|
The reason I like the "Concerning Font.bold" statement is that, when reading the program, as soon as you see that, you know right away what that whole section does and whether you care about it or not. |
|
|
[MB] some language compilers allow for inline code from other languages... obviously you'd need a compatible other-language compiler on hand. |
|
|
In any case, if you are making so many individual changes to the boldaility of items, it is likely that you should be collecting them into some form of group and applying a general transform. However, if the boldality is an expression of logic (e.g. transmitting information other than style) then writing things out in the 'traditional' and non-concerning way would make more sense to me. |
|
|
Then you are just left with the challenge of ensuring that screen-readers relate your boldality as you expect. |
|
|
I'm not convinced that the With statement makes code any easier to read. Concerning might do slightly better though. A series of assignments on one object will line up on the screen, while a series of assignments on one property will not line up without odd formatting. |
|
|
This is kind of the whole point of lambdas and similar access to functions as first-class objects. The problem you're addressing is an artifact of Java sucking, not a general problem. |
|
|
lists:map(
fun (X) -> bold(X) end, [Form1, Form2, Form3]) |
|
|
[form1, form2, form3].map { |x| x.bold = true } |
|
|
map { $_->bold } ($form1, $form2, $form3) |
|
|
Just use a language that isn't actively hostile to programmers. |
|
|
//some cuneiform fortran// |
|
|
I've seen something a bit like this home-brewed. |
|
|
As I recall, someone had set up their makefile to run a pre-processor program before calling the compiler, and that pre-processor recognized certain home-made tokens in the source code to mean "*this* part is to be passed as-is to a vanilla C-compiler, but *that* part is to tapped on the shoulder and led off to a quite different and undocumented destination". It was an extraordinary rendition of program logic. It also involved some steganographic bamboozling of compilers in relation to the source code that *was* passed to them. I now forget the details. |
|
|
Something not unlike this also happened in a poorly thought-out API that I once had to work with, whereby fragments (not complete statements) of SQL had to be delivered via bits of home-made syntax embedded in un-XSDed XML documents, manipulated at various stages of the process in C# (or, in earlier versions, VB script). Now, *that* was concerning. |
|
|
Ruby can do this. Put the objects you want to set the
property for into an array, and iterate over them with the
each method, calling the setter method on each object.
This is pretty basic stuff, actually. |
|
|
Basically, Ruby is the best programming language ever, and
everyone should use it because of its sheer awesomeness. |
|
| |