ID:181373
![]() Sep 14 2010, 3:13 pm
|
|
Never, ever, ever, ever use usr inside a procedure.. Use src. I see this all to often, I can't take it anymore..
|
![]() Sep 14 2010, 8:21 pm
|
|
What if they know how to use that usr?
|
Toadfish wrote:
I don't this a rule of thumb, but a useful generalisation. As Stephen mentioned that's a rule of thumb by definition. But it's a little firmer than that; I wouldn't call this a rule of thumb so much as a major guideline. If you find yourself putting usr in a proc, just like with using goto or the : operator, you should strongly question why you're doing it and if there isn't a better way. There are exceptions to all of these "big three"; I've broken with them at times in my own code, but always with strong justification. Also as one of the few DM programmers who can legitimately call themselves advanced, I'm well aware of where to draw the line on what's a good usage of these and what isn't; since most newbies (and people who don't think they're newbies but basically are) aren't so aware, they should avoid these cases at just about any cost. Lummox JR |
I've found that the colon operator is especially useful for getting the value of an object without actually loading an object. You can retrieve the initial value of a variable or get some constant or static data. And it's the only use I've found for it so far.
var/initialValue = /MyDatum:variable
|
Why are these undocumented features NEVER documented or noted anywhere? Knowing this would be tremendously useful.
|
And it doesn't compile.
mob Gives this error: code.dm:7:error: return/mob/:/myVar: invalid expression |
That whole sentence was botched....
I am in agreement with what you say, and I will add, that while a newbie programmer might sometimes find it difficult to detect the fine line between "fair use" and botched code, by thinking of something as a restriction rather than a rule of thumb, we are always losing certain properties of a language. I support teaching such a newbie to treat the big three as "restricted" aspects of DM, but the same thing is of course not ideal for a more advanced user. The simplistic way they taught us mathematics as we passed our years in elementary school was suitable for that environment and our intellect at the time, but a middle schooler, and a high schooler still, need a deeper, more foundational approach. |
Doesn't work quite as you'd expect it, due to how the compiler uses the look-up and look-down operators (: and .) it goofs up and spits the wrong error out. To get around it you have to define a variable for the compiler to catch on to. It doesn't have to be initialized. There's also another compiler goof that makes it not consider said variable used. So you have to workaround that too. You also need to use the undocumented (and 100% legacy) 'static' keyword.
When it comes down to it, static variables were an idea that never really took off, they worked as expected at one point, but other compiler changes broke them somewhere down the line. A functional example of static variables with all of the hacks and workarounds to make it compile without errors or warnings. mob |
Toadfish wrote:
I am in agreement with what you say, and I will add, that while a newbie programmer might sometimes find it difficult to detect the fine line between "fair use" and botched code, by thinking of something as a restriction rather than a rule of thumb, we are always losing certain properties of a language. I support teaching such a newbie to treat the big three as "restricted" aspects of DM, but the same thing is of course not ideal for a more advanced user. The simplistic way they taught us mathematics as we passed our years in elementary school was suitable for that environment and our intellect at the time, but a middle schooler, and a high schooler still, need a deeper, more foundational approach. Well note I said "major guideline" and not "restricted" for that reason. I tell newbies to avoid these three things at all costs in the hopes that if one of them is ever pushing into more advanced/intermediate territory, they'll have the good sense to ask on the forums how to work around whatever design quandary they're in. The problem is, basically most newbies are not graduating to intermediate code. To improve as a programmer they have to 1) challenge themselves, 2) communicate with other programmers, and 3) learn from experience. I've seen many manage any one of those without ever trying the other two. I've seen some who were obviously never capable of learning at all, who made the same mistakes over and over again with such predictability that they had no hope--and some of them regarded themselves as good programmers. Lummox JR Lummox JR |