- 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
Well.... it might throw an exception if one of those properties doesn't exist...
Admin
Hey, the word function was spelled correctly!!
Admin
This looks like debugging code, someplace you could put a breakpoint in...
Admin
Yes - I'd definitely put this one down to "this is where we put the debug statement when something is broken".
Admin
Hey, at least it has descriptive names for the arguments... oh hang on.
Arguably even worse is that these arguments are clearly expected to be arrays yet have an additional string key called "condition". Arrays having any such non-numeric key (apart from the built-in and obviously useful "length") is a clear code smell as far as I'm concerned. And yes I know this particular code does nothing, but I have to assume since these properties exist they must be used somewhere in this codebase.
Admin
As a side effect, the function sets the global variable 'temp'.
Admin
The
let
keyword scopes the variable to the block it's contained within, so, nope.Admin
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let :
Block-scoped, not global.
https://www.w3schools.com/js/js_let.asp says much the same thing:
Admin
It takes a full-time dev just to keep it running...
It is amazing how people are willing to continue to work in crappy code bases when it's so easy to make the code less crappy.
Admin
Good idea... if programmers ran the place. I assure you that some manager there isn't going to let your plan go through.
Admin
Hah! But first you need to
Unit tests totally require changes to the code, IF that code is deeply coupled to everything and a few inner platforms and a massive collection of global state.
etc.
Which is not to say improvement cannot and should not be made. But it requires a business, not a dev shop, that recognizes that investing time and present dollars on this below-decks work for zero immediate ROI will in fact have positive ROI later. Also not to mention the interpersonal politics that every bit of that technical debt represents decisions made by people (probably now senior people) who may still be there and are not eager to have their body of work questioned or abandoned.
Admin
Oops. Just eaten by Argle.
Admin
This isn't even anciemt legacy code, as it uses the ES6
let
keyword.Admin
Smooth choice using 'let' instead of 'var' for the loop index...
Admin
Another vote for a debug trap. There's some problematic data condition this detects, put a breakpoint on it when you're hunting for what caused it this time.
Admin
Perhaps there is a race condition present elsewhere in the code and this code is just trying to slow down a process to "hopefully" avoid the race condition... Otherwise, maybe someone is getting paid by the lines of code that they write.
Admin
This article has a side effect too, I learned about the mathematical use of ℵ. Cool.
https://en.wiktionary.org/wiki/%E2%84%B5
Admin
Using debug statements for debugging. 50 years of programming have shown that good debugging utils are priceless. And yet, after 20 years of this shitshow of web dev they still don't have anything decent.
Admin
I don't think the input parameter ("varA") is an array (as access to its data is done through a field called "field"
The signature for varA seems to be something like
{ length : number; condition:boolean|any; field : Record<string,any>[] | any[]; }
Addendum 2022-06-07 04:39: That should be Record<string,any>[] | any[] [] (second array indicator got removed when by the commenting system?)
Admin
All things you propose take time. And that seems to be the problem here
Admin
Oh yes, and there are perfectly good debuggers built right into browsers. Have been for a big chunk of that 20 years (and as extensions/external tools before that).