Why people dislike global variables so much while I find them so convenient?

forkit forkit at gmail.com
Thu Jan 27 00:45:20 UTC 2022


On Wednesday, 26 January 2022 at 23:40:48 UTC, H. S. Teoh wrote:
>
> After many experiences of this, I've come to the conclusion 
> that the convenience of using globals is usually not worth the 
> trouble they cause down the road. I rather "waste" a bit more 
> time writing things the "right" way now, than to waste a LOT of 
> time (and frustration) later trying to debug code riddled with 
> global state.
>
>
> T

I just counted the globals in my GUI IDE (that I developed with 
C#/Winforms.

34

many set deafault, that can later be modified during function 
calls, depending on needs at the time.

Without globals, I'd never have bothered ;-)

bool new_compile_needed = true;
public bool new_record_mode = false;
static string custom_tmp = System.IO.Path.GetTempPath() + 
@"EZ_Compiler\";
string vcvar64 = "";
string vcvar32 = "";
string clang_exe = "clang.exe";
bool Is64Bit;
string clang_xp = @"C:\LLVM\bin\clang-cl.exe";
static string g_cl_c_options = @" /nologo /W4 /GS- /Od";
string g_cl_c_options_new = g_cl_c_options;
static string g_cl_cpp_options = @" /nologo /EHsc /W4 /GS- /Od";
string g_cl_cpp_options_new = g_cl_cpp_options;
static string langversion = @" /langversion:default";
static string g_csc_options = @" /nologo /warn:4 /warnaserror+ 
/nowarn:168,164 /checked+" + langversion + " /optimize+ 
/target:exe";
string g_csc_options_new = g_csc_options; // see compile method...
static string g_csc_unsafe_options = @" /nologo /warn:4 
/warnaserror+ /nowarn:168,164 /checked+" + langversion + "  
/optimize+ /unsafe /target:exe";
string g_csc_unsafe_options_new = g_csc_unsafe_options;
bool vs2019_available = false;
bool vs2015_available = false;
string exeDir = 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string current_file = "Current File: (none)";
string dcompiler_mars = "dmd.exe";
string dcompiler_llvm = "ldc2.exe";
string dcompiler = "dmd.exe";
string gocompiler = "go.exe";
string jscompiler = "jrunscript";
string cs_formatter = @"CodeFormatter.exe";
string csprojFileName = custom_tmp + "cs" + ".csproj";
string myDLibDirectory = @" -i -I="  + '\u0022' + "D:\\My 
Documents\\Dlib"  + '\u0022' + " ";
string Cpp64dll = @"c:\nowheretobefound";
string Cpp32dll = @"c:\nowheretobefound";
string myDocsFolder = 
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
System.Drawing.Color MyBackColor = Color.Black;
System.Drawing.Color MyForeColor = Color.Lavender;



More information about the Digitalmars-d mailing list