ID:151942
 
goto, the : operator for DM, there's always bad ones right?
What sitautions call for either to be used?

What're the "forbidden" ones for other programming languages and what sitaution are they used for? (if you explain what they do, cookies to you.)
Goto is "forbidden" (as you call it) in most programming languages...
Save for goto (which does have use), most languages probably avoid adding things that just shouldn't be done.
DemonSpree wrote:
What're the "forbidden" ones for other programming languages and what sitaution are they used for? (if you explain what they do, cookies to you.)

Not just bad statements such as : or goto but also design patterns.

There is a singleton design pattern which creates one (and only one) object of a class for the entire program. Bad because it is a global variable and it is a pain to refactor.

George Gough
In response to KodeNerd
KodeNerd wrote:
There is a singleton design pattern which creates one (and only one) object of a class for the entire program. Bad because it is a global variable and it is a pain to refactor.

Singleton has its uses.
In response to KodeNerd
In BYOND, defining a single global object makes handling libraries a breeze. It takes all of the instantiation trouble out of the client program and allows any person who installs the library to access library functions that are totally encapsulated within the library itself like a namespace -- no name conflicts!

For instance, jt_vectors has a global variable like this: <code>var/jt_vectors/jt_vectors = new</code>

And then when someone wants to use a jt_vectors library function, they don't have to do this:
var/jt_vectors/jt_vectors = new
jt_vectors.DoSomethingPlease()
del jt_vectors

and waste CPU time and effort when a small memory footprint for a small object can handle it just fine. Instead, they can just call a library function from any proc or verb they want, just by prepending "jt_vectors." to the proc name.
In response to Alathon
Alathon wrote:
KodeNerd wrote:
There is a singleton design pattern which creates one (and only one) object of a class for the entire program. Bad because it is a global variable and it is a pain to refactor.

Singleton has its uses.

http://www.gamedev.net/community/forums/ topic.asp?topic_id=494027

From that topic:

The problem with the singleton is that it solves an extremely niche case, is far too easy to implement, is entirely too popular given its limited applicability, gives beginners a false sense of sophistication, and is the least useful of the available design patterns. I wish beginners were learning MVC or adapter or observer like this.

Personally, I don't even consider the singleton to be a design pattern - there's a huge difference between "I only need one" and "There can be only one," and the fact that it conflates the two makes it suspect to me.

:End topic

I never said that the Singleton was not able to be used, just that it is a generally unneeded global and is a pain to refactor.

George Gough
In response to KodeNerd
Singleton is a Pattern for a reason, like all patterns, it solves a particular common problem in a neat and effective manner.

Just not the problem most people use it on.
In response to Popisfizzy
C (and consequently C++) will happily let you do a good number of things that you really shouldn't do, like throwing pointers to local stack variables out of functions, one cause of the mighty segmentation fault.
There aren't really any forbidden constructs in any languages. They are in the language for a reason, it's just typically the 'bad' ones are in for reasons you rarely come across. What you really have is incorrect application of a perfectly good construct.

One that comes to mind for Java would be single iterator loops from data structures. The for (element : collection) will happily fetch and unwrap an iterator for you and will be a heck of a lot better to read, not to mention save you time. Iterators (like goto) permit a level of flexibility not afforded by for (element : collection), at the expense of readability and thus increases the chance of bugs.

Goto and : aren't forbidden in DM, it's just if you're using them, you better have a damned good reason to be sacrificing so much readability and opening yourself up to obscure bugs, which a good 99% of people don't. As such, it's easier for people to say "Don't use it. You'll know when you need to.".
In response to Stephen001
Just like how "cursing" isn't forbidden :D.
In response to A.T.H.K
The notion of "cursing" is just stupid, considering it is intended to stigmatise certain terms that are considered offensive, but I can think of a very large number of ways to be entirely offensive to an individual, harmful to their character, or cause them considerable personal distress, that don't even go near "curse" words. Most would probably do more harm than plain name-calling would, I suspect. It seems like a good portion of politics is actually built on this practice. Not to mention, making those terms taboo has most probably increased their use by virtue of today's commonly uncaring, thoughtless, self-centered, hard attitude.

Perhaps instead of teaching children not to "curse", we should teach them not to be social thugs, that look to verbally destroy people for minor things, or even just for kicks.

My apologies for that, seriously off-topic. But yes, they are forbidden in so far as "curse" words are fobidden, in a way.
In response to Stephen001
Stephen001 wrote:
My apologies for that, seriously off-topic. But yes, they are forbidden in so far as "curse" words are fobidden, in a way.

Actually, I found that to be a great explanation.

George Gough
In response to KodeNerd
KodeNerd wrote:
There is a singleton design pattern which creates one (and only one) object of a class for the entire program. Bad because it is a global variable and it is a pain to refactor.

Welcome to my world.

Lummox JR
The goto statement, usr in procs, and : operator are "forbidden" in DM in much the same way a responsible adult would forbid a 4-year-old from playing with matches or a handgun. They're really great tools for niche purposes that seldom come up, and only a lot of training and experience makes it clear when and how to use them.

I've seen you pressing for an answer on this in other threads, but the simple truth is that if you have to ask, you don't yet have the experience needed to use them. To the extent that anyone could provide a valid test case, it'd be difficult to understand and you'd still be left wondering how that differed from any other scenario. It's kind of a zen thing, but true: The answer is pretty much meaningless unless you already know it.

What I can do though is point you in the right direction. The way to discover these things is to take on ambitious projects. I don't mean a full game or anything, but even something that's a simple proof-of-concept can teach you a great deal. Incursion was born out of a simple map generator using partial tiles. Think of something that BYOND can probably do well but is difficult to achieve: like perhaps an extensible upgrade to Skysaw's dictionary library; a good AI system for monsters/companions in a Roguelike game; a way of quickly updating items in a grid control; a pathfinding system that can be used by multiple mobs. I wrote Regex mostly to see if I could, and it happens to involve loops complex enough to warrant the use of goto. Take on something feasible (not like sidescrollers or pseudo-3D, for instance) that will stretch your abilities, and reach. This is the sort of experience that will answer your question.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Welcome to my world.

Lummox JR

I take it Dan was using them a lot?

George Gough
In response to KodeNerd
KodeNerd wrote:
I take it Dan was using them a lot?

I don't know if it's Dan exclusively, and heck, it's not like I'm any saint when it comes to misusing design patterns myself. But there are a fair number of singletons in BYOND's code, yes.

Lummox JR
In response to Lummox JR
Vote Lummox JR as BYOND's official motivational speaker today! That was probably the most inspiring post on the forums I've seen in a long time.