- Feature Articles
- CodeSOD
- Error'd
-
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
She loves it when I get access to section G.
Ok I'll see myself out
Admin
Yeah, if that fall-through pattern is a correct implementation of a business rule, it should fscking well be commented as such.
But what really grinds my gears is that that long test is repeated ad nauseam instead of being centralized.
Admin
Notice the beautiful inconsistency: to provide access to SectionA there must be an entry other than NoAccess, while for all the others missing value gives the access to the corresponding section.
Admin
And also the mysterious use of
else return UiItem.Unknown;
when that is not in the enum definition forUiItem
which should be an error.Admin
TRWTF, however, is that the random-generator used on this site to go to a "random" article, has the same quality as the submissions posted here.
Admin
Yeah, someone failed hard at De Morgan's Law on this one.
Admin
So if currentAccess is empty we always get UiItem.sectionB?
Admin
10 years in chroot jail for this violation.
Admin
Wow! Messy.
It seems section A is special and sections B-G is not as special.
For section A/highest level, you need to have access (an entry in the currentAccess-map/table/array, whatever it is) and it cannot be NoAccess.
For sections B to G you have automatic access unless you have been denied access (NoAccess again).
Which of course will cause all kinds of funky security incidents, but maybe it makes sense for this app. E.g. section A is admin access, B-G is different parts of the public site?
Anyway, messy!
Admin
Why am I seeing this differently? To me it looks like we have a set of key-value pairs that define access and this is trying to pick the first item that the user has access to, perhaps to set up a default on the screen as this is UI code. Effectively an unrolled loop but where's the errant behavior?
But there's another problem: reCAPTCHA thinks a motorcycle is a bicycle!
Admin
Oh boy this looks so similar to our Fortran code...
It is basically object orientation done backwards. But the one code had been started in the 90s, and back then Fortran didn't have polymorphic types, so it gets a pass to some degree. Also, I was just learning the alphabet when the first version of the software was written, so I'll give them a pass for getting ad-hoc object orientation wrong.
Regardless, it can be quite a pain to work with. Conditionals and switch-case (i.e. select case in Fortran) everywhere.
Admin
F90 does have generic interfaces giving polymorphism akin to C++ templates with everything explicitly specialized, but it doesn't look like that would help with that style of object discrimination.
Admin
As far as I know, Fortran has only overloading of names, in that it allows defining multiple subroutines/functions/method that are are called through the same name. By trying out right now I learnt, that they can after all also be defined in different modules.
But that's not the same as templates or Java generics, because it requires manually implementing them for each type. It can be somewhat automated with macros, but that's still hardly a replacement for proper language support; For a start, being based on a custom workaround also means that it won't have TOOLING support.
A natively supported alternative is to use
CLASS(*), ALLOCATABLE
for storing the data. But for some reason, a simplehas 128 byte in Intel Fortran (24 in GFortran), so that's not actually all that attractive. There's also the problem, that there is no concise way to get the data out of that again, unless you define something like
but that shifts the type check to the runtime.
Best I could come up with was to store the payload data via the
TRANSFER
intrinsic, but who knows what kind of breakage that introduces with regard to finalizer behavior, such as automatically deallocatingallocatable
fields of items that go out of scope.