Yesterday, we released BenGribaudoLLC.IEnumerableHelpers.DataReaderAdapter as a NuGet package!
What does it to?
Adapts IEnumerable<T> to the IDataReader interface. Enables enumerable sequences to be used where a data reader is expected.
Great for loading data from a List<T>, LINQ expression or CSV parser into a database using SqlBulkCopy! Streams data to SqlBulkCopy, bypassing the need to first materialize the entire sequence in memory and load it into a DataTable. Continue reading
I like to expose myself to programming languages rooted in different paradigms so that I can expand my skill set, broaden my thinking and learn new ways to solve problems. Lately, I’ve been exploring the world of pure functional programming by studying Haskell.
My object-oriented mind finds the following fascinating:
naturalNumbers = [1..] -- [1,2,3,4,5,…]
This simple statement defines a list starting with 1 and increasing by 1 each step all the way to infinity. The result is not a range that can be enumerated to infinity (for example,
1..1.0/0 using Ruby’s Range class); it’s an actual list that goes to infinity. Continue reading
Pass in a query and a column name (or a column list) and receive an unpivoted result set back. Specify either the columns to unpivot or the columns to leave unpivoted (i.e. unpivot all but the specified columns). Behind the scenes, this stored proc casts value columns to a common data type of your choosing, eliminating “the type of column ‘x’ conflicts with the type of other columns specified in the UNPIVOT list” errors. It can also be used as a SQL generator, outputting the dynamically-built query’s text instead of executing it. Continue reading
Use exceptions for exceptional circumstances. Will your program still run if the exception handling code is removed? If so, you may be misusing exceptions. In effect, you may be using exceptions as a way to emulate goto statements!
(Found this today in a collection of programming thoughts I wrote back in 2005.)
Over the past 3.5 years, my blog has received 88,070 SPAM comments. Averaged out, that’s 69 unwanted messages per day. Ouch!
I’ve tried various plugins in an attempt to combat these unsolicited messages but to no avail. Continue reading
Values often need to be tracked as they change over time. Imagine we’re building a payroll system. A foundational requirement would be to store an employee’s pay rate. In all but the most basic of systems, saving this rate as a simple value is insufficient (“Joe’s wage = $20/hour”); rather, a history of the rate over time needs to be maintained (“Joe’s wage = $15/hour as of 10/15/13; Joe’s wage = $20/hour as of 2/1/14”). We do this by giving pay rate a time dimension.
What our system knows about a given moment in time and what really was at that same moment can differ. Suppose Joe’s manager signs paperwork on January 20 giving Joe a pay raise but leaves for vacation before turning in the paperwork. At close of business on January 20, the payroll system knows Joe’s rate to be one amount when, in reality, it’s a different amount. Joe has been given a raise but the system doesn’t yet know about it. Continue reading
Did you know that you can assign variables inside Ruby’s array and hash literals?
While the values used inside square bracket array literals are typically hard-coded, provided by a variable, computed from an inline expression or generated by a method, any valid Ruby statement can be used. The same is true for both keys and values used in hash literal key => value pairs. Continue reading
RSpec’s be true and be_true look deceptively similar. In fact, their naming suggests that they might be synonyms for the same assertion. Can the two clauses be used interchangeably to produce the same effect? No!
Both check trueness but from different perspectives. be true checks whether the compared-against value is true: “Does the value literally equal true?” be_true asserts that the test value evaluates to true: “Is the value truthy?” be false and be_false are the respective inverse match clauses. Continue reading
An entire day passed. The repugnant lines sat festering. Finally, their odious stench wafted strong enough to give me a start. What had I done?!
The situation started simply enough. I realized several kinds of transactions shared common logic. Despising duplication as a good programmer should, I placed this shared behavior in a base class which the various kinds of transactions would subclass. Continue reading
In interview style, here’s the conclusion of my reflections after studying Prolog for two months. If you’d like, read Part 1 first.
What did you find unique about the language?
Unification! Prolog works by trying to make terms equal one another. In most languages, the statement “Cost = 100” sets the variable “Cost” to a value of 100. In Prolog, “Cost = 100” means (in effect): “can Cost and 100 be unified?” During execution, Prolog takes into account the entire set of logical rules that have been defined to figure out if Cost and 100 are allowed to equal the same value. While possible, the need for statements manipulating variables’ values within an operation occurs far less frequently in Prolog than in the languages I’m used to. Continue reading