23 Feb, 2011, David Haley wrote in the 81st comment:
Votes: 0
You think posting childish, insulting pictures and mocking posters is "succinct", "on point" and "fruitful"?
23 Feb, 2011, sankoachaea wrote in the 82nd comment:
Votes: 0
plamzi said:
I re-read Tyche's contributions to this thread and find no basis for the above observations.

Good for you.

Quote
He is, as usual, succinct, and on point.

In your opinion.

Quote
Some of his "fancy terms", if one takes the time to look them up, may teach one something new.

If looking up AOP code injection, indirection, and reflection was going to teach me something new then I wouldn't be posting here in the first place.

Quote
If you don't think a post or a poster is fruitful, find one that you think is, and steer the discussion towards it. Useless bickering over who's a troll far exceeds the damage done by any actual trolling.

I'm optimistic about him having the potential to post constructively. No one is bickering over who's a troll.. it's obvious. If people are going to call me a 'purist' or assert that I'm regurgitating childish stories from CS-101 or that I'm an asshole* or any other equally untrue statements, then I'm going to challenge them. Tyche's only response has been.. more trolling.






* I might be an asshole.
24 Feb, 2011, plamzi wrote in the 83rd comment:
Votes: 0
Tyche said:
I looked at TeensyMud and there's one global, and it's only referenced in the line after it's defined.
Doesn't even need to be declared. Of course there are quite a few ruby built-in globals.

However, all locals in ruby are globals including those on the stack (other than immediate values).

Check this out…
def afunction
a = "xyzzy"
puts a
change_local_a
puts a
end

afunction


$ ruby globals.rb
xyzzy
plugh

Function change_local_a
Spoiler
def change_local_a
ObjectSpace.each_object(String) do |x|
if x == "xyzzy"
x.replace "plugh"
end
end
end


And if course all automatics in C are allocated on a global stack and can also be accessed from anywhere in your program.


In the above example, I not only learned something about Ruby (which I haven't yet used) but I also looked up "automatics": http://en.wikipedia.org/wiki/Automatic_v.... I'd say that's as good as a forum post can get.

Honestly, I think you guys are just reacting to Tyche's posting with the mittens picture, which I'm guessing you felt was a personal attack. However, there was more to that post, and the picture was clearly intended to illustrate a point he was trying to make about globals. In the context of his post, I think the illustration was on-topic. If you disagree with his view, address it with a counter-argument (with a counter-picture, if you want). Accusing him of trolling does not move the discussion forward and does not automagically overrule his central argument.

If I may take the liberty to sum up the argument again: Aversion to globals is to a large extent "received knowledge" from coding classes which teach best practices as if they are absolute rules and don't dwell too much on exceptions–the stuff of real-life coding.
24 Feb, 2011, sankoachaea wrote in the 84th comment:
Votes: 0
Try http://en.wikipedia.org/wiki/Algorithmic...

The stuff of real life coding? Have you ever been hired to maintain software (or a system) previously designed by one or many programmers who each had their own views on paradigm efficiency and locality and globals? Have you ever been hired in that position and discovered that they didn't document things well?

I know hobbyists are all about "real world coding" like MUDs and MUD clients - but schools are conducting business under the impression that after school you'll be going to "fantasy land" where you have a job maintaining legacy code for existing software systems.
24 Feb, 2011, plamzi wrote in the 85th comment:
Votes: 0
sankoachaea said:
Try http://en.wikipedia.org/wiki/Algorithmic...

The stuff of real life coding? Have you ever been hired to maintain software (or a system) previously designed by one or many programmers who each had their own views on paradigm efficiency and locality and globals? Have you ever been hired in that position and discovered that they didn't document things well?

I know hobbyists are all about "real world coding" like MUDs and MUD clients - but schools are conducting business under the impression that after school you'll be going to "fantasy land" where you have a job maintaining legacy code for existing software systems.


That's a very good point, many aspects of which I and David Haley have already addressed earlier in the thread.

I did not mean to suggest that working as a coder and as part of a team is any less "real-world" than coding as a MUD enthusiast. Instead, I wanted to suggest (and I have) that in actuality, code often stays in first-draft form. This happens maybe less often in a team/business environment, but I'm sure it does happen. Like you say yourself, nobody documents. Likewise, hardly anybody writes a second or third draft with future generations in mind, when the first draft compiles and works fine. I'm not saying they should or shouldn't–that varies greatly case by case.

Speaking of documentation: Even though I don't shy away from adding more globals, I think I'm much better than the previous coders of my MUD in that I try to leave a good amount of comments inside the code. I believe that's more effective than leaving SVN comments, or minimizing my use of globals and other "shortcuts." Using globals when you see an opportunity for saving time, but documenting it in-line is, I believe, a good balance for my project.

As for what we should be teaching new MUD coders, I think something along the lines of what David Haley has said will do: "A global must earn its existence." Let them discover the shortcuts themselves, and let them find their own coding style.
24 Feb, 2011, Tyche wrote in the 86th comment:
Votes: 0
plamzi said:
I re-read Tyche's contributions to this thread and find no basis for the above observations. He is, as usual, succinct, and on point.


About six months ago I wrote some javascript that "skins" the site by filtering out features and posts/quote blocks coming from a particular source. It makes most threads 25-50 percent shorter and eliminates any temptations to respond to the deliberate misinterpretations and mischaracterizations of what I and other posters have written. It's possible that he's not able to filter out that noise and instead 'reading' something altogether different.

plamzi said:
Some of his "fancy terms", if one takes the time to look them up, may teach one something new.


I'm fairly sure that the poster I responded to, Runter, has a grasp of what those terms refer to in the context of the design of those Ruby servers, although we may well disagree with the effects they have on understanding the code. That side discussion with him isn't essential.
24 Feb, 2011, Tyche wrote in the 87th comment:
Votes: 0
sankoachaea said:
..but I wanted to clarify, by 'good point' I meant 'you should re-read all of my posts and your 'responses' to them while reflecting on the advice you just gave me'.


Why? Up to this point I've only responded to assertions you raised about mud programmer experience in post #46. You indicated that you really didn't care about experience that differs from your own in post #67, so I made an off-topic response to the flames.

Just to illustrate using your last post.
sankoachaea said:
The stuff of real life coding? Have you ever been hired to maintain software (or a system) previously designed by one or many programmers who each had their own views on paradigm efficiency and locality and globals? Have you ever been hired in that position and discovered that they didn't document things well?

sankoachaea said:
I don't need to hear your credentials and I don't really care where you went to school or didn't. It's not about where we've been, it's about where we're going. As it happens, I didn't learn to program in a Computer Science class.


sankoachaea said:
I clearly and openly stated I was going to troll you.


I'm afraid that I either missed the declaration or didn't understand your intentions.
You may want to review this –
By posting t...
24 Feb, 2011, Tonitrus wrote in the 88th comment:
Votes: 0
David Haley said:
You think posting childish, insulting pictures and mocking posters is "succinct", "on point" and "fruitful"?

Immensely.

Tyche said:
About six months ago I wrote some javascript that "skins" the site by filtering out features and posts/quote blocks coming from a particular source. It makes most threads 25-50 percent shorter and eliminates any temptations to respond to the deliberate misinterpretations and mischaracterizations of what I and other posters have written.

Share?
24 Feb, 2011, KaVir wrote in the 89th comment:
Votes: 0
Tonitrus said:
Tyche said:
About six months ago I wrote some javascript that "skins" the site by filtering out features and posts/quote blocks coming from a particular source. It makes most threads 25-50 percent shorter and eliminates any temptations to respond to the deliberate misinterpretations and mischaracterizations of what I and other posters have written.

Share?

I'd very much like a copy as well please Tyche, if you're willing to share. I've asked several times for an "ignore" feature, and at one point it looked like it might be added, but by now I'm willing to try pretty much anything short of painting TipEx on the screen.
24 Feb, 2011, plamzi wrote in the 90th comment:
Votes: 0
KaVir said:
Tonitrus said:
Tyche said:
About six months ago I wrote some javascript that "skins" the site by filtering out features and posts/quote blocks coming from a particular source. It makes most threads 25-50 percent shorter and eliminates any temptations to respond to the deliberate misinterpretations and mischaracterizations of what I and other posters have written.

Share?

I'd very much like a copy as well please Tyche, if you're willing to share. I've asked several times for an "ignore" feature, and at one point it looked like it might be added, but by now I'm willing to try pretty much anything short of painting TipEx on the screen.


[offtopic]

Sounds like a job for a greasemonkey script. Is that what you used?

Maybe a new thread is in order…

[/offtopic]
24 Feb, 2011, Runter wrote in the 91st comment:
Votes: 0
It sounds like it's probably something pretty easy to do. You just need to search the DOM and change the visibility property on matching elements. Well, might be a little tougher since you'd need to set the visibility of parent elements based on that search. Although, I think it's a little unclear what Tyche meant. Is it completely filtering out posts from certain users?
24 Feb, 2011, Davion wrote in the 92nd comment:
Votes: 0
plamzi said:
KaVir said:
Tonitrus said:
Tyche said:
About six months ago I wrote some javascript that "skins" the site by filtering out features and posts/quote blocks coming from a particular source. It makes most threads 25-50 percent shorter and eliminates any temptations to respond to the deliberate misinterpretations and mischaracterizations of what I and other posters have written.

Share?

I'd very much like a copy as well please Tyche, if you're willing to share. I've asked several times for an "ignore" feature, and at one point it looked like it might be added, but by now I'm willing to try pretty much anything short of painting TipEx on the screen.


[offtopic]

Sounds like a job for a greasemonkey script. Is that what you used?

Maybe a new thread is in order…

[/offtopic]


[link=post]47606[/link]

Works beautifully :D
24 Feb, 2011, David Haley wrote in the 93rd comment:
Votes: 0
plamzi said:
If you disagree with his view

The disagreement is not with the view per se, but with his insistence that other people hold such a silly view in the first place. (It makes it easier and more fun to post insulting pictures – yes, you're correct that they're personal attacks.)
24 Feb, 2011, Tyche wrote in the 94th comment:
Votes: 0
Davion said:
[link=post]47606[/link]

Works beautifully :D


The quoting is broken since then.
Change this:
if (divElements[j].className == "quotebox") {
var strongElement = divElements[j].childNodes[0];
var whoSaid = strongElement.innerHTML.split(" ", 1)[0].toLowerCase();
for (var k = 0; k < usersToIgnore.length; k++) {
if (usersToIgnore[k] == whoSaid) {
divElements[j].childNodes[1].innerHTML = "IGNORED";
break;
}
}
}

To:
if (divElements[j].className == "quotebox") {
var strongElement = divElements[j].childNodes[0];
for (var k = 0; k < usersToIgnore.length; k++) {
if (strongElement.innerHTML.match(new RegExp(usersToIgnore[k],"i"))) {
divElements[j].childNodes[1].innerHTML = "IGNORED";
break;
}
}
}
25 Feb, 2011, sankoachaea wrote in the 95th comment:
Votes: 0
"Don't use global variables" is kind of a stylistic choice.

If you're learning to program and planning to write non-trivial software, it's understood to be a "safe" and "proven" stylistic choice.

Tyche seems to think that finding any reason to support that stylistic choice makes a person ignorant, inferior, "going through a phase" or possessive of some other undesirable characteristic and that arguing against that stylistic choice by making attacks on the persons holding that view is somehow demonstrative of a superior understanding of both programming and social behavior.

I think it's more likely to be interpreted as him being an asshole or a troll - as a number of people have confirmed.
25 Feb, 2011, Orrin wrote in the 96th comment:
Votes: 0
Let's move on please and try not to derail the thread with personal attacks, accusations of trolling or discussion of who is or isn't an asshole.
25 Feb, 2011, sankoachaea wrote in the 97th comment:
Votes: 0
Agreed.

Google C++ Style Guide (Chromium) said:
Static or global variables of class type are forbidden: they cause hard-to-find bugs due to indeterminate order of construction and destruction.
Objects with static storage duration, including global variables, static variables, static class member variables, and function static variables, must be Plain Old Data (POD): only ints, chars, floats, or pointers, or arrays/structs of POD.

The order in which class constructors and initializers for static variables are called is only partially specified in C++ and can even change from build to build, which can cause bugs that are difficult to find. Therefore in addition to banning globals of class type, we do not allow static POD variables to be initialized with the result of a function, unless that function (such as getenv(), or getpid()) does not itself depend on any other globals.

Likewise, the order in which destructors are called is defined to be the reverse of the order in which the constructors were called. Since constructor order is indeterminate, so is destructor order. For example, at program-end time a static variable might have been destroyed, but code still running – perhaps in another thread – tries to access it and fails. Or the destructor for a static 'string' variable might be run prior to the destructor for another variable that contains a reference to that string.

As a result we only allow static variables to contain POD data. This rule completely disallows vector (use C arrays instead), or string (use const char []).

If you need a static or global variable of a class type, consider initializing a pointer (which will never be freed), from either your main() function or from pthread_once(). Note that this must be a raw pointer, not a "smart" pointer, since the smart pointer's destructor will have the order-of-destructor issue that we are trying to avoid.


Google on Global Functions said:
Prefer nonmember functions within a namespace or static member functions to global functions; use completely global functions rarely.

Pros:
Nonmember and static member functions can be useful in some situations. Putting nonmember functions in a namespace avoids polluting the global namespace.

Cons:
Nonmember and static member functions may make more sense as members of a new class, especially if they access external resources or have significant dependencies.

Decision:
Sometimes it is useful, or even necessary, to define a function not bound to a class instance. Such a function can be either a static member or a nonmember function. Nonmember functions should not depend on external variables, and should nearly always exist in a namespace. Rather than creating classes only to group static member functions which do not share static data, use namespaces instead.

Functions defined in the same compilation unit as production classes may introduce unnecessary coupling and link-time dependencies when directly called from other compilation units; static member functions are particularly susceptible to this. Consider extracting a new class, or placing the functions in a namespace possibly in a separate library.

If you must define a nonmember function and it is only needed in its .cc file, use an unnamed namespace or static linkage (eg static int Foo() {…}) to limit its scope.

Place a function's variables in the narrowest scope possible, and initialize variables in the declaration.
C++ allows you to declare variables anywhere in a function. We encourage you to declare them in as local a scope as possible, and as close to the first use as possible. This makes it easier for the reader to find the declaration and see what type the variable is and what it was initialized to. In particular, initialization should be used instead of declaration and assignment, e.g.

int i;
i = f(); // Bad – initialization separate from declaration
int j = g(); // Good – declaration has initialization

Note that gcc implements for (int i = 0; i < 10; ++i) correctly (the scope of i is only the scope of the for loop), so you can then reuse i in another for loop in the same scope. It also correctly scopes declarations in if and while statements, e.g.

while (const char* p = strchr(str, '/')) str = p + 1;


There is one caveat: if the variable is an object, its constructor is invoked every time it enters scope and is created, and its destructor is invoked every time it goes out of scope.

// Inefficient implementation:
for (int i = 0; i < 1000000; ++i) {
Foo f; // My ctor and dtor get called 1000000 times each.
f.DoSomething(i);
}

It may be more efficient to declare such a variable used in a loop outside that loop:

Foo f; // My ctor and dtor get called once each.
for (int i = 0; i < 1000000; ++i) {
f.DoSomething(i);
}


For the Objective-C style guidelines, they defer to the C++ guidelines in regards to globals. They also mention the following.

Google Python Style Guidelines said:
Avoid global variables.

Definition:
Variables that are declared at the module level.

Pros:
Occasionally useful.

Cons:
Has the potential to change module behavior during the import, because assignments to module-level variables are done when the module is imported.

Decision:
Avoid global variables in favor of class variables. Some exceptions are:

Default options for scripts.
Module-level constants. For example: PI = 3.14159. Constants should be named using all caps with underscores; see Naming below.
It is sometimes useful for globals to cache values needed or returned by functions.
If needed, globals should be made internal to the module and accessed through public module level functions; see Naming below.
25 Feb, 2011, Tyche wrote in the 98th comment:
Votes: 0
sankoachaea said:
"Don't use global variables" is kind of a stylistic choice.

If you're learning to program and planning to write non-trivial software, it's understood to be a "safe" and "proven" stylistic choice.


The choice to use globals can be for functional reasons or stylistic (form) reasons or for both.
But proven? See Heuristic Rule. It's also at the top of the page, GlobalVariablesAreBad, that you copied almost verbatim into your first post.

sankoachaea said:
Tyche seems to think that finding any reason to support that stylistic choice makes a person ignorant, inferior, "going through a phase" or possessive of some other undesirable characteristic and that arguing against that stylistic choice by making attacks on the persons holding that view is somehow demonstrative of a superior understanding of both programming and social behavior.


You appear to be engaged in channeling, reading auras, or some other nonsense.
I am the authority on what Tyche thinks.

"I don't think you need to justify your use of globals either."

"It's purists versus pragmatists. Conditioning versus critical thinking. You don't need to do any thinking to regurgitate the children's stories that may or may not have been taught in CS 101(?) like "Globals are bad" or "GOTOs are bad". Advice to newbies aren't commandments for experts."
Gotos Considered Harmful and Other Progr... said:
Programmers are constrained not just by conscious application of rules and procedures, but also by
taboos that they have acquired as part of their formal education or informally from colleagues. These
taboos usually embody perceived sound advice and have generally been concerned with the breaking
of abstraction boundaries. However their effect can be to needlessly restrict the range of solutions to
design problems that programmers consider. This paper examines a set of common programming
taboos, and addresses both social aspects and technical reasons as to why programming taboos have
arisen.


"Some people have to code with these [pink mittens with strings] on and think everybody else should too. Some people don't."
Gotos Considered Harmful and Other Progr... said:
People are loathe to cross boundaries, either for reasons of safety or for lack of skill. And it is
the latter that makes taboos dangerous. As we have shown, the introduction of a taboo can cause
knowledge and experience to be lost.

'GOT0 Considered Harmful' Considered Har... said:
It is like butchers banning knives because workers sometimes cut themselves.


You might wear mittens for safety. You might wear them because you have no skill. You might wear them because you aren't confident in your skills yet. You might wear them because you don't want to get your hands dirty. All mud programmers are not equal. All of us have different experiences and different skills. There are both professionals and amateurs here. Conforming to some egalitarian orthodoxy of 'we' do this or 'we' are that simply has no place here, IMNSHO.

Since the forum is C/C++ and the topic is global variables, it seems appropriate to post the only formal study I am aware analyzing globals in C and C++ programs.
Assessing the Impact of Global Variables... said:
The results show that, while most global variables have essentially no impact on program dependence, there are a few that have a large and significant effect. Moreover, though there may be few such global variables, many programs (more than half those studied) have at least one such significant variable.


My take on what this study is that on average 80% of globals are perfectly harmless, don't create maintenance nightmares, and don't influence the ability of a programmer to comprehend programs. YMMV
03 Mar, 2011, quixadhal wrote in the 99th comment:
Votes: 0
For the benefit of Mr. Kite
There will be a show tonight on trampoline
The Hendersons will all be there
Late of Pablo-Fanques is there, what a scene
Over men and horses hoops and garters
Lastly through a hogshead of real fire!
In this way Mr. K. will challenge the world!
03 Mar, 2011, Rarva.Riendf wrote in the 100th comment:
Votes: 0
Scandum said:
For my mud I use a global data structure called mud, so I've got mud->time, mud->first_player, mud->first_area, etc, about 80 nested variables total, and 1 global variable. It gives the ease of use of global variables, without the worry about rogue variables.

It is the best use of a global variable: the one you need like everywhere, in every kind of methods.
It would be hard to access the player list everywhere you need it in a mud if it were not global.
And if you do not use multithread, it is quite safe.
But you have to limit them to the strict minimum (the start of the list of char is obviously the start, but what if a newbie decide to put the index to some value while in a method, then call another that is not aware of that, before returning and putting it back to the start of it).
A global should always be true to its name (if it is called mud->first_player, well it should NEVER be something else). Otherwise it is hell to debug.
80.0/100