JS Programming in C# – Local Functions

Functional programs treat functions and data alike. No discrimination, if you will. That means, you can declare and use functions – assign to variables, pass to other functions etc., the same way you would play with variables.

A canonical example of a functional program would show how to pass functions as parameters to other functions (higher order functions). It would also show how one can create functions on the fly (lambdas or anonymous functions) and also assign it to a variable, which is of a predefined function type; either the compiler deduces or aligns to the calling context.

There is one important attribute of data that is mostly forgotten. It can be declared almost anywhere, particularly within functions. Local variables, remember? If we agree to treat data and functions alike then we should be able to declare a function inside another. Errrk! Why would anyone want to do that? Seems like JavaScript.

Continue reading JS Programming in C# – Local Functions

Advertisements

JS Programming in C# – Objects on the fly

Creating objects without defining types is considered a great flexibility in JavaScript. JavaScript treats objects nothing more than key-value pairs. Yeah, you can declare functions in the object but they are still part of the key-value philosophy. Bottomline: JavaScript did not start out as an object oriented language.

Typically, objects are created on the fly1 using the object literal syntax:

let obj = {
   name: "Will",
   age: 26
};

There are scenarios when creating objects on the fly is indeed a flexibility.

Continue reading JS Programming in C# – Objects on the fly

Writing sonnets in C++

Recently, I came across this post – Write a URL in a C++ program, one of those C’s tricks. If you have not already read the post, I will wait until you read and return …

waitingWaiting …

The crux of the trick is the protocol part of the URL – http:, becomes a goto label and the rest of the URL starting with // becomes a comment. Sweet 🤗

My turn My turn …

Continue reading Writing sonnets in C++

Compiler aided overloading

I was playing with xUnit.net for a pet project of mine. I wasn’t writing test cases with xUnit rather I was using the underlying xUnit engine to discover test cases and invoke calls that execute desired test cases. Forget the details of what I was doing, let us talk about it in a different post. But for now, I was consuming xUnit’s backend library.

XunitFrontController is the gateway to xUnit’s world; AFAIK. You create an instance of the controller specifying the target assembly.

var xfc = new XunitFrontController(
  AppDomainSupport.IfAvailable,
  "{full path of the assembly where the test cases reside}"
);

Continue reading Compiler aided overloading

Problem Reduction

Problem Reduction is what I call when a given problem can be expressed in terms of or solved using a solution to an alternate problem.

Take for instance, the word distance problem: Find the shortest distance between two words in a given set of words. Following is an unanimous solution, I suppose:

Continue reading Problem Reduction

JINQ

In his talk at the CppCon 2014, Bjarne Stroustrup explained, politely and brilliantly, how to write succinct expressive yet intent-ful code. The task is especially hard when there are parties interested in trolling1 rather than contributing. Like Stroustrup explains back, it is difficult to find the real meaning out of a large block of (legacy) code.

Continue reading JINQ