When reviewing other developers’ code, I often see small constructs that I would never write myself, yet pause thinking for a moment, “I must remember that, it’s quite neat”.
This happened a few moments ago upon reviewing some third-party code. I encountered a small construct that appeared to be a simple piece of stock standard C# string interpolation. Documentation on string interpolation, including the reference documentation from Microsoft and Jon Skeet’s very addictive blog and books, all routinely demonstrate string interpolation as an alternative to the static String.Format(…) method. Furthermore a rote discussion on string interpolation functionality during a technical interview would most certainly result in someone at some point referring to String.Format, syntactic sugar with StringBuilder efficiency in terms of performance and GC issues, and so on.
The code excerpt below shows a simple implementation of string expression interpolation that I had never encountered before; prefix addition within the string with the side effect that the state of an in-scope variable is updated.
This approach shown below is succinct, unusual, yet obvious too. That is a very odd mixture!
This is one of my shorter blog postings but then again, what else is there to write?
— Published by Mike, 09:06:07 25 September 2017 (GMT)
By Month: November 2022, October 2022, August 2022, February 2021, January 2021, December 2020, November 2020, March 2019, September 2018, June 2018, May 2018, April 2018
Apple, C#, Databases, Faircom, General IT Rant, German, Informatics, LINQ, MongoDB, Oracle, Perl, PostgreSQL, SQL, SQL Server, Unit Testing, XML/XSLT
Leave a Reply