- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Visibility is something a lot of people struggle, to this day I encounter devs that have no idea what "internal protected" means even though it's around for nearly 25 year.
Admin
Two possible ways this could be very slightly useful.
One, it makes it easy to do a text search of the entire code base and find where the function is called from, if you don't trust your IDE to find all references (or if you have even worse WTFs that make it so the IDE can't find all references).
Two, it stops people from calling the function when they shouldn't. Anyone that tries to call the function will have their brain lock up as they try to figure out WTF is going on with that "password".
Admin
No, it just makes them dig out the source code for the function to find out what the [REDACTED] password is, and then they dream of consigning the [REDACTED] moronic fucknut who invented such a scheme to the appropriate murky corner of Hell.
Admin
Didn't we already see something like this here, many years ago?
Admin
That's too black and white. Perhaps this code isn't available in source, and you may overestimate the eagerness of programmers to look through a function's source code. If they do, they'll at least understand they must have a good reason to call this function. If you assume they'll look up the code, they might just as well change private into public. Or call
ProcessRequest(RequestType.Unload, Environments.All)
directly. Who can tell?Admin
Java's JMH does something like this:
https://github.com/openjdk/jmh/blob/master/jmh-core/src/main/java/org/openjdk/jmh/infra/Blackhole.java
But its developers know what they're doing and why.
Admin
in C# private is the default access level, so this alone is not really a WTF. the fact that everything has been made explicitly public when it shouldn't, might be
Admin
The Linux syscall reboot(2) requires two special magic values to be passed as parameters in order for it to work properly. This is more to prevent accidental invocation—e.g. if some code went awry and started executing Undefined Behavior, you don't want to accidentally call the wrong syscall and reboot the system.
But it's not a security control. The security control is the fact that only the root user is allowed to call the syscall in the first place.
Admin
Code review hopefully. /laughs in misery
Admin
By that logic, there’s no point making anything private, given that a sufficiently incentivised caller can access it anyway.
Forcing people to decompile a .dll to find out how to access a function should be enough of a roadblock for them to think that an alternative approach might be easier.
Admin
This reminds me of some code I saw once where the writer tried to do the "are you sure" logic in the business layer rather than in the UI.
It resulted in the UI having to call the business function twice, once with the areYouSure=false, to which the function would reply "are you sure" and then the UI would have to call it again with areYouSure=true
Admin
I would be really surprised if this even worked, because the first thing I'd expect developers to do is to copy an existing function call with parameters and all.
Admin
Many times and around the world, a group of non-X programmers are told from on high (because a VP's wife's second cousin heard that it's great) to start using X without having any understanding or someone experienced to guide them. Don't believe me? Go look at the original incarnation of MFC.
Admin
private
only helps if the "allowed" callers are all in the same class as the callee. If the method needs to be public, you're out of luck.I see this as a kind of sanity checking, like the reboot(2) example. Similar to putting a sentinel in a structure parameter. Calling it a "password" makes it seem more significant.
Admin
But surely the real WTF (or at least another one) is that code fails silently; so nobody even knows what went wrong until they fall over some other side effect,
Admin
I love that comment: "It is currently only called from Form1.Closing()", and what it reveals about the project. It's a Windows Forms project, and they didn't even bother changing the default name of the form 🤦♂️
Admin
@MaxiTB: There is no "internal protected" in C#. There is "protected internal", and "private protected".
Admin
Maybe they are like me. I have a tradition newer to rename the first form in a project out of superstitious reasons. It upsets the framework. And I genuinely see an uptick of strange behavior if I do so.
Admin
[quoate]Visibility is something a lot of people struggle, to this day I encounter devs that have no idea what "internal protected" means even though it's around for nearly 25 year.[/quote]
More like 35 years at least. But yeah, it's irritating.
Admin
Out of interest: How does C# handle a situation, where a non-nullable variable is to be initialized inside an if/else?
If
MyType
is nullable instead, it would just be initialized tonull
, but is there some way to declare the variable in the outer scope without making in nullable?Basically, I want to know if it is possible for the compiler to guarantee that the variable has been initialized or otherwise, at least at runtime to catch a programming error, where the variable is not.
In Python, this is one of the reasons I sometimes use ternaries...
In Fortran, I just have to give up, because it has no short-circuiting ternary form and too many things cannot be expressed as
anyway, since the lack of move semantics on function returns means that often "output arguments" are the only viable solution.
Admin
WAITFOR DELAY '0:0:10'
Admin
Admin
The C# compiler will recognize if there is any situation where the variable remains uninitialized before it is first accessed and will throw up an error. So in your example things will work just fine because all the paths contain an initialized. If the else was missing the init than it would throw up a compiler error.