Hour-by-hour forecast as Essex battered by heavy rain and 40mph winds
The £2million Florida mansion that Russell Brand lived with his family before returning to Britain to face the music for raping one woman and sexually assaulting three more
Delays on nearby Essex routes as obstruction brings traffic to standstill
James Jordan issues apology after facing backlash over comments claiming Strictly pro routine focused on 'two men dancing sexually with each other' on a 'family programme'
Labour IS to blame for the youth job crisis: Milburn report will say party's own policies have damaged work prospects for the young
EV public charging could cost 33% more per mile than petrol, as experts warn prices may soar next year
California Sues OpenAI Over Hugging Face, Other AI Model Loss of Control
Read more of this story at Slashdot.
Colchester primary school 'rapidly improving' after being told it's 'not good enough'
Rapist Russell Brand's behind-bars bulletins breach prison rules and will be investigated, minister says
Robert Pattinson's Twilight castmate jokes that he predicted James Bond role nearly two decades ago in resurfaced clip
How Robert Pattinson finally got the Bond role: Callum Turner and Jack Lowden failed to impress bosses but Batman star won them over with his talents, friendship with director and his ability to deal with scrutiny
The Morning Poll: Can Robert Pattinson cut it as James Bond?
James Bond's identity is FINALLY confirmed as Robert Pattinson after weeks of casting rumours - as star calls 007 role 'the honour of a lifetime'
Who will be the next Bond girl? Sydney Sweeney, Maya Jama and Kendall Jenner among stars tipped to join new film as Robert Pattinson is finally confirmed as 007
DHS Secretary Mullin shares alarming theory that AI may have sparked recent chaos at airports and banks
CodeSOD: Building a Line
There's an unofficial category of posts here that I call "Somebody told us string builders were more efficient, so we always use string builders, regardless of whether or not that actually makes sense," or STUSBWMESWAUSBROWONTAMS, for short. Probably should workshop that name some.
In any case, Adam sends us a new entry for that collection:
Public Function ReadFromFile(ByVal filename As String) As String Dim sb As StringBuilder = New StringBuilder() Dim str As String = String.Empty Using sr As StreamReader = File.OpenText(filename) str = sr.ReadToEnd() sb.Append(str & Constants.vbLf) End Using Return sb.ToString() End FunctionThis function takes a filename, opens a file, reads the entire contents of the file to a variable. It concatenates a line feed to the end of the string it just read, then appends all of that to a string builder. Finally, we return sb.ToString(), taking the single string in the string builder, appending nothing to it, and returning the result.
I'd almost, almost forgive the code if it was more like:
str = sr.ReadToEnd() sb.Append(str) sb.Append(Constants.vbLf)You're not actually gaining much from this, but it follows the broad pattern of "use a string builder" so that if you ever wanted to change the structure of the output, you're already set up to prepend/append new text in a scalable way. I'd argue that's premature abstraction, though: a simple return sr.ReadToEnd() & Constants.vbLf would do the current job.
The code that we have is a clear superstitious use of string builders. The string builder is used as a charm against poor performance, without understanding why one might use it, or how it might work; string concatenation means string builder, always and forever, "why" doesn't enter into it.