|
If you compare it to Eddy Vluggen's trolling, I think you'll agree that it's soft.
|
|
|
|
|
You are evil
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
ZurdoDev wrote: 844 now.
I'm putting you in a special box.
[ ZurdoDev ]
Ok, just glad to know where you are.
|
|
|
|
|
raddevus wrote: I'm putting you in a special box. As well you should. My momma says I'm special.
But in seriousness, there are times when globals make sense. That's all the comment was saying, I believe.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
ZurdoDev wrote: But in seriousness, there are times when globals make sense. Agree...
But if python really behaves as raddevus is saying, then it is a bit odd and might give problems faster than in other languages regarding to this topic
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
No, but also injection is a kind of global behavior in the broadest sense
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: No
Good, I will continue talking to you then.
0x01AA wrote: but also injection is a kind of global behavior in the broadest sense
Ok,I might concede on that point. However, writing the code to do injection is far more extensive than just writing:
extra = "i am global"
Barriers to entry are necessary.
Imagine if anyone could just flip a switch and turn off gravity!?!
Oh, man, you'd never get any work done because your keyboard would keep floating into the clouds.
|
|
|
|
|
Global constants, yes.
Global variables, no.
|
|
|
|
|
Greg Utas wrote: Global constants, yes.
Global variables, no.
Ah, great point! +5 points for the Globals.
|
|
|
|
|
Global variables being defined by you... still might be ok.
Every variable being global in the whole file / "class" where they are defined without you making it on purpose... is looking for problems.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 26-Jun-20 19:55pm.
|
|
|
|
|
Nelek wrote: Global variables being defined by you...still might be ok. Am I really that much of a paragon?
|
|
|
|
|
It might be useful to avoid "out" parameters or overcomplicating things
I think it is like "goto" using it with moderation can be helpful and a still a "good" approach, use it without care and you will shoot in your foot or somewhere worse.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Some people consider singletons a type of global variable, but I have no qualms about using them freely. Only having one of something sometimes makes sense and doesn't mean that encapsulation has to be violated.
|
|
|
|
|
Global vars matter.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
AAAaahhhh!!!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Ever the lighter-of-bonfires, John .
Software Zen: delete this;
|
|
|
|
|
My job is to color outside the lines.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
|
|
Shouldn't that be:
var a='matter', b='matter', c='matter';
|
|
|
|
|
Perfect!
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Globals are a tool. Sometimes that tool comes in handy. I like globals a lot more than I like Singletons, especially if globals are wrapped in a class so they aren't scattered everywhere. Singletons, on the other hand, gnnhhhh!
(I've never felt that the verbiage to use Singletons was any better than just making sure you only implement a class once in the codebase. But if I found a place where a Singleton absolutely made sense, I'd use a Singleton.)
|
|
|
|
|
David O'Neil wrote: But if I found a place where a Singleton absolutely made sense, I'd use a Singleton I use it to keep a single instance of a logger that is used all over the application. The logger uses a blocking collection and so all other places can send stuff to the logger, the collection takes care of the entries and the logger just writes down in FIFO mode.
Would that be something making sense to you? (Just curious, I am not saying is absolutely making sense or correct, but I found the approach not that bad)
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Viewing it from your perspective, it makes sense. Personally, I'd just create one instance of the logger in a global and use that everywhere. I know there is only one global, and everything in that global only has one instantiation, so I never worry about it beyond that point. I'd just make certain to place the logger at the top of the declarations in the global, so it can be used by any of the following items.
The reason I settled on the global approach is linked to my Pimple article. It just makes things easier for me. It might not make your workflows easier. I don't know, and I'm not going to be all evangelical about my methods. If it works, it works. The goal is software the user can use. Not to avoid singletons or gotos or globals.
For instance, here's the current global header for my main MIDI project at this point:
#pragma once
class Globals {
private:
uchar lastNoteVelC;
MUSIC_TIME lastNoteLenC;
MUSIC_TIME snapValueC;
public:
Globals();
~Globals();
void saveAppDefaults();
enum NoteDurations { wholeNote=3072, halfNote=1536, quarterNote=768, eigthNote=384,
sixteenthNote=192, thirtySecondNote=96, sixtyFourthNote=48, tick=1 }
noteButtonDurationC;
int noteButtonDuration() { return noteButtonDurationC; }
uchar lastNoteVel() { return lastNoteVelC; }
void lastNoteVel(uchar vel) { lastNoteVelC = vel; }
MUSIC_TIME lastNoteLen() { return lastNoteLenC; }
void lastNoteLen(MUSIC_TIME newLen) { lastNoteLenC = newLen; }
MUSIC_TIME snapValue() { return snapValueC; }
void snapValue(MUSIC_TIME val) { snapValueC = val; }
private:
std::unique_ptr<app::ControllerNames> controllersC;
public:
app::ControllerNames & controllerNames() { return *controllersC.get(); }
private:
std::unique_ptr<app::NoteValMap> noteValMapC;
public:
app::NoteValMap & noteValMap() { return *noteValMapC.get(); }
private:
std::unique_ptr<midi::KeySignatures> keySignaturesC;
public:
midi::KeySignatures & keySignatures() { return *keySignaturesC.get(); }
private:
bool useSyncLogicC;
public:
void useSyncLogic(bool state) { useSyncLogicC = state; }
inline bool useSyncLogic() { return useSyncLogicC; }
private:
bool playPriorEventsC;
public:
bool playPriorEvents() { return playPriorEventsC; }
void playPriorEvents(bool state) { playPriorEventsC = state; }
private:
double ticksPerPixelC;
int keyHeightC;
public:
inline double ticksPerPixel() { return ticksPerPixelC; }
inline void ticksPerPixel(double val) { ticksPerPixelC = val; }
int keyHeight() { return keyHeightC; }
void keyHeight(int height) { keyHeightC = height; }
public:
enum DisplayVal { DisplayTicks, DisplayTimes };
private:
DisplayVal displayValC;
public:
DisplayVal displayVal() { return displayValC; }
void displayVal(DisplayVal val) { displayValC = val; }
private:
int stopSleepTimeC;
public:
int stopSleepTime() { return stopSleepTimeC; }
private:
bool showHelpOnStartupC;
public:
bool showHelpOnStartup() { return showHelpOnStartupC; }
void showHelpOnStartup(bool state) { showHelpOnStartupC = state; }
public:
enum StopMethod { PlayNotesOff, PlayOmniModeOff, PlayOmniModeOn, PlayMonoModeOn,
PlayPolyModeOn, PlayNothing };
private:
StopMethod stopMethodC;
public:
StopMethod stopMethod() { return stopMethodC; }
void stopMethod(StopMethod newMethod) { stopMethodC = newMethod; }
private:
int pianoViewBottomNoteC;
public:
int pianoViewBottomNote() { return pianoViewBottomNoteC; }
void pianoViewBottomNote(int x) { pianoViewBottomNoteC = x; }
private:
std::unique_ptr<ui::UIManager> uiManagerC;
public:
ui::UIManager & uiMan() { return *uiManagerC.get(); }
private:
std::unique_ptr<medit::Strings> stringsC;
public:
medit::Strings & strings() { return *stringsC.get(); }
public:
wString appWorkDir();
private:
int buttonHeightC = 25;
public:
int buttonHeight() { return buttonHeightC; }
private:
std::unique_ptr<utils::DateVersioner> dateVersionerC;
public:
utils::DateVersioner * dateVersioner() { return dateVersionerC.get(); }
public:
bool breakPointTrigger;
private:
int minTicksBetweenCurveEventsC;
public:
int minTicksBetweenCurveEvents() { return minTicksBetweenCurveEventsC; }
};
It is simple, and I control the instantiation order of everything in it. Some of it is rarely used in the rest of the codebase, but the UIManager it extensively accessed from almost everywhere for all the color choices and everything else related to UI. Knowing that things are there, my life as a programmer is easier.
As per gotos, I only have a few in my work. Here's one location that seems to be a good choice, from my perspective. It is the way my brain thinks of the solution. I know they could be eliminated, but I believe it would take several more lines of code to do so, and I have better things to worry about than whether the code is 'goto'-free:
void Repeat::createRepeatedMsgs() {
if (!createdMsgsC.empty()) throw dwl::Exception(_T("Delete created msgs prior to "
"creation"));
app::MsgPlayMap & holder = trackC.playMap();
holder.setPtrPos(s_cast<MUSIC_TIME>(0));
midi::BaseMsg * msg;
midi::BaseMsg * msgToCopy;
while ((msg = holder.msgAtPtr()) && msg != nullptr && msg->tick() < endTickC) {
if (msg->tick() < tickC) goto breakout;
for (size_t i=1, count=numRepeatsC; i<=count; ++i) {
midi::BaseMsg::Type type = msg->type();
if (type == midi::BaseMsg::Type::NoteOn) {
midi::NoteOn * noteOn = s_cast<midi::NoteOn *>(msg);
midi::Note * note = s_cast<midi::Note*>(noteOn->parent());
if (note) msgToCopy = note;
else msgToCopy = noteOn;
}
else if (type == midi::BaseMsg::Type::NoteOff) goto breakout;
else if (type == midi::BaseMsg::Type::KeyAftertouch) goto breakout;
else msgToCopy = msg;
if (msgToCopy->copyOf()) goto breakout;
std::unique_ptr<midi::BaseMsg> newMsg = msgToCopy->copyToTick(msgToCopy->tick() +
durationC * i);
if (newMsg->type() == midi::BaseMsg::Type::Note) {
s_cast<midi::Note*>(newMsg.get())->noteOn().copyOf((midi::BaseMsg*)1);
s_cast<midi::Note*>(newMsg.get())->noteOff().copyOf((midi::BaseMsg*)1);
}
createdMsgsC.push_back(newMsg.get());
newMsg.release(); }
breakout:
holder.incMsgPtr();
}
for (auto msg: createdMsgsC) {
msg->addToVisible();
}
}
|
|
|
|