Chelmsford gym and sports centre to get huge £2 million refurbishment
Oligarch who 'masterminded massive money laundering scheme' that saw billions in Russian money pour into Europe and the USA is arrested
Extortion crew threatened to inform Edward Snowden (?!) if victim didn't pay up
Dark web analysts at infosec software vendor Fortra have discovered an extortion crew named Ox Thief that threatened to contact Edward Snowden if a victim didn’t pay to protect its data – a warning that may be an indicator of tough times in the ransomware world for some, at least.…
The world's best holiday homes revealed - from a spectacular Scottish castle to a private island in Lancashire with its own cinema and spa
I inherited half my mum's house - will I owe tax on the 24 years her partner was allowed to live there?
New Form of Parkinson's Treatment Uses Real-Time Deep-Brain Stimulation
Read more of this story at Slashdot.
CCTV captures embarrassing moment bungling burglar fails ATM theft from quiet Essex village shop
Experts reveal the SIX foods you need to help beat prostate cancer
Nvidia Weaves Silicon Photonics Into InfiniBand And Ethernet
When it comes to networking, the rules around here at The Next Platform are simple. …
Nvidia Weaves Silicon Photonics Into InfiniBand And Ethernet was written by Timothy Prickett Morgan at The Next Platform.
CodeSOD: Spaced Out Prefix
Alex had the misfortune to work on the kind of application which has forms with gigantic piles of fields, stuffed haphazardly into objects. A single form could easily have fifty or sixty fields for the user to interact with.
That leads to C# code like this:
private static String getPrefix(AV_Suchfilter filter) { String pr = String.Empty; try { int maxLength = 0; if (filter.Angebots_id != null) { maxLength = getmaxLength(maxLength, AV_MessagesTexte.Reportliste_sf_angebotsID.Length); } if (filter.InternesKennzeichen != null) { if (filter.InternesKennzeichen.Trim() != String.Empty) { maxLength = getmaxLength(maxLength, AV_MessagesTexte.Reportliste_sf_internesKennzeichen.Length); } } if (filter.Angebotsverantwortlicher_guid != null) { maxLength = getmaxLength(maxLength, AV_MessagesTexte.Reportliste_sf_angebotsverantwortlicher.Length); } // Do this another 50 times.... // and then .... int counter = 0; while (counter < maxLength) { pr += " "; counter++; } } catch (Exception error) { ErrorForm frm = new ErrorForm(error); frm.ShowDialog(); } return pr; }The "Do this another 50 times" is doing a lot of heavy lifting in here. What really infuriates me about it, though, which we can see here, is that not all of the fields we're looking at are parameters to this function. And because the function here is static, they're not instance members either. I assume AV_MessagesTexte is basically a global of text labels, which isn't a bad way to manage such a thing, but functions should still take those globals as parameters so you can test them.
I'm kidding, of course. This function has never been tested.
Aside from a gigantic pile of string length comparisons, what does this function actually do? Well, it returns a new string which is a number of spaces exactly equal to the length of the longest string. And the way we build that output string is not only through string concatenation, but the use of a while loop where a for loop makes more sense.
Also, just… why? Why do we need a spaces-only-string the length of another string? Even if we're trying to do some sort of text layout, that seems like a bad way to do whatever it is we're doing, and also if that's the case, why is it called getPrefix? WHY IS OUR PREFIX A STRING OF SPACES THE LENGTH OF OUR FIELD? HOW IS THAT A PREFIX?
I feel like I'm going mad.
But the real star of this horrible mess, in my opinion, is the exception handling. Get an exception? Show the user a form! There's no attempt to decide if or how we could recover from this error, we just annoy the user with it.
Which isn't just unique to this function. Notice the getmaxLength function? It's really a max and it looks like this:
private static int getmaxLength(int old, int current) { int result = old; try { if (current > old) { result = current; } } catch (Exception error) { ErrorForm frm = new ErrorForm(error); frm.ShowDialog(); } return result; }What's especially delightful here is that this function couldn't possibly throw an exception. And you know what that tells me? This try/catch/form pattern is just their default error handling. They spam this everywhere, in every function, and the tech lead or architect pats themselves on the back for ensuring that the application "never crashes!" all the while annoying the users with messages they can't do anything about.
.comment { border: none; }Increased parking fees will 'kill off' Essex running club and end local events, councillor says
At 58, I'd been on every antidepressant under the sun. Then I tried an experimental drug that 'reset' my mind and FINALLY cleared my decades-long fog of sadness
Popular Essex pub reopens after £325k refurbishment with 'exciting new look'
Blake Lively and Justin Baldoni's legal saga takes another turn as his lawyer considers a settlement
Google’s broadband balloon laser comms tech floated out as independent company
Google’s attempt to provide remote area connectivity with balloons has been floated out as an independent company, a rare success for the company’s attempt to develop breakthrough technologies.…
Man with 'passion' for circus shows off intricate handmade models
School children and elderly left 'stranded' because of constant bus cancellations in Hutton
Patrick Schwarzenegger strips down for Kim Kardashian's latest SKIMS campaign with his bride-to-be
Jack the £40million lad: It's advantage Draper after win puts Briton in top ten of world tennis... and makes him an advertisers' dream
Hollywood Urges Trump To Not Let AI Companies 'Exploit' Copyrighted Works
Read more of this story at Slashdot.