"The mastermind behind our system is the Senior Developer," wrote Daniel, "he's naturally an expert at all things code, but he especially excelled at back-end systems. After all, true geniuses always value function over form."
"The Senior Developer liked to do things a little differently, but we got over his quirks. Take, for example, this handy dandy function to ease the pains of those complicated cast operations we all hate."
public T Cast<T>(object obj) { return (T)obj; }
"Why?" Daniel added, "so we can write 'someNumber = Cast
"Of course, the real problems always camein when our super-experienced developer 'optimized' for performance. Because his concept of caching wasn't too strong, we'd often end up with code like this."
public List<OutstandingApproval> GetApprovals(List<Guid> clientList, Guid userId) { List<OutstandingApproval> approvals = new List<OutstandingApproval>(GetApprovalsDAO(clientList)); System.Web.HttpRuntime.Cache.Insert(userId + "approvals", approvals); return approvals; }
"In addition to inserting but never retrieving from cache, the code uses userId as a cache key... which is nice and all, except that the data is not at all user-specific. But the real inspiration for sending this in is in the webpage optimization. According to the Senior Developer, this tweak reduces the page size, which makes things more optimal all around."
protected override void Render(HtmlTextWriter writer) { using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter())) { base.Render(htmlwriter); string html = htmlwriter.InnerWriter.ToString(); html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}", string.Empty); html = Regex.Replace(html, @"[ \f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1"); html = html.Replace(";\n", ";"); writer.Write(html.Trim()); } }
Daniel added, "sure, we could have told him that the regex replacements aren't exactly that fast. We could have also mentioned that the caching enabled in IIS rendered this entirely pointless. But be didn't; he knew he was right, and who were we to question the Senior Developer?