On i, j, … as iteration variables (but really a foray into primary sources)

code 10 January 2012 | 0 Comments

This question was recently asked on StackOverflow: I know this might seem like an absolutely silly question to ask, yet I am too curious not to ask… Why did “i” and “j” become THE variables to use as counters in most control structures? The question has generated many answers, from scholarly to spurious — but [...]

Tagged in , ,

Casting in .NET via object mutation

code 13 May 2011 | 0 Comments

In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 };   Floatsy(it);   Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!

Tagged in , , , ,

Validating email addresses with .NET regex

code 10 May 2011 | 0 Comments

I did validation in Haskell a while back, and since I recently discovered .NET’s “balancing groups” regex feature, it seems like it would be a good time to do it for .NET.

Tagged in , , , ,

So, it turns out that .NET’s Regex are more powerful t̖̱̍ͭ͊h̟ͨͨa̞̖̙̔̇n͇̝͚̤̒́ͨ̐ ̯͖̏̌̔Ị̟̮̱̥̇̐̎͂ͬ͗̒ ̪̹̱͙̘ͦ̉ͪͪͣ̉͊o͕̥̝͇͙ͪ͊ͤ̑̂̽́r͔̭̪̮̟͗̍ͨ͗͛ͣḭ̝̜͈ͫ́g̥̹̥̜̦̓̇̓i̪͕̭̞͛ͯ̓͛̔̾ͫn̘̗a̰̜ͨͪ͊l̩͑̐̐́ͥ̚l̜ͨ͋̈ẙͦ́ ̟̬̬̫͙̤ͭ̚t̳͎̱̗̲́h͔͙̰̬̊̈́͊̾o͉ͫ̌̄u͉̲̥g̏ͥ̑̅̽̇h̻͇̥̰̯ͥͯṱ̯̏̄̒͒ͫ̃.͖̟͍̘̼̼̍̐̀͊̓́…

code 10 May 2011 | 3 Comments

Today, thanks to user Lucero on StackOverflow, I learned about .NET’s “Balancing Groups” Regex feature. Basically, any time you use a named capturing group, it actually pushes the capture onto a named stack. You can then pop this stack by using the same capturing group prefixed with a hyphen, like (?< -stackToPop>). Of course, anyone [...]

Tagged in , , , , , ,