Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Heliarco4024yFor extra points, since this changes the timing of built in object disposal, make logic which depends on this feature
-
Heliarco4024y@MadMadMadMrMim it very much does!
C# Actually has tons of ways you can subtly punish good coding practice like you wouldn't believe it. Such as raw pointers etc. but somehow people look at you funny when you use them :( -
And now what you are all amased by this, go read this if you want to REALLY make things impossible to track :
https://medium.com/@trapdoorlabs/... -
Does C# have a concept of a stack vs heap?
In C++ scoping is useful if you want to allocate an object on the stack, but when it leaves the scope it is destroyed. -
@NoToJavaScript
Technically your casing is off and you’re just overriding the String class inside then namespace creating ambiguity
string s1 will fix that -
@MadMadMadMrMim
"string" is just a keyword. Not a class definition. Which always target System.String.
But there are cases you don't want System.String.
Yes.
But not String.Empty. And you can relocate the String "overide" in another part of the project.
You can redifine String.IsNullOrEmpty. And just watch the whole project burn haha -
I use narrow scoping in C (but not pointless empty scope levels) because it doesn't just clarify that some stuff is only used very locally - it also can gain speed because the compiler knows that it can discard the variable after the scope.
You can get like 1% of speed-up in tight loops just by narrow scoping. Yes, I write code with such small performance gains in mind because shit adds up. -
@Fast-Nop
Can't talk about C, but in C#
if (condition)
DoStuf();
and
if (condition)
{
DoStuf();
}
Doesn't change anything.
But there is a "new" (well, couple of years now) syntax for using.
using (var j = new service()) {
code
}
code1
Will dispose j before code1 part 9Well, it also depends on plenty of factors, but usually it does).
new syntax is
using var j = new service();
code;
code1;
j will not be disposed until code1 run.
But you won 1 encapsulation level and code is more clear. At the price of disposing your ressource later.
I take this aproach everytime. -
@NoToJavaScript point is just spelling out system.string would solve part of your problem there lol
-
@NoToJavaScript Yeah it hits in only when you declare (stack) variables in the small scope instead of a larger one, basically because the compiler can reason better about register allocation for that part, and because it won't pointlessly push the value back into memory.
-
Geoxion9024y@Demolishun It has! But all classes and arrays are heap allocated. You can opt out of that by using structs and stackalloc arrays.
Primitives are also on the stack.
C# calls this reference types and value types.
String is the only exception. It's heap allocated, but acts as a value type. -
iiii90884yYou can do the same in C++ actually. Scopes are pretty useful for automated memory management
-
iiii90884y@Demolishun even with heap allocated items using smart pointers with scopes can guarantee cleanup before the end of function execution.
-
@iiii Though I wouldn't scope heap allocation or object instantiation to tight loops.
Related Rants
-
AndSoWeCode5A lot of the people are complaining about working in inhumane conditions. I want to debunk some bullshit that ...
-
straboniec3Uncle Bob says: Software Craftsmanship is not about glory and rockstar status. It’s not about being the ov...
-
cha-m-ra15I just hate it when clients with no knowledge of developing says I'm looking for "more professional" FUCK YO...
In C# you can open as many scopes wherever you want at whatever time you please. Nested within themselves, doesn't matter.
Use this to fuck with the other developers on your team. Fence off their evil code behind a thousand curly braces!
Or maybe jazz up your indentation, give the code a nice and bouncy flow!
rant
my coworkers love me
top tip
professionalism