Skip to main content

Posts

Showing posts from 2017

Some advanced things about methods, fields, delegates and members in C#

I had the chance to dig deeper into how C# handles members in general and came up with some really interesting conclusions. This post is mostly about how C# and the CLR resolves fields and methods calls with the corresponding implications. This is especially good to shut up someone if you do an interview with a know-it-all interviewer.. Actually is it pretty interesting because in C# you can actually have multiple fields with the same name in an object. But there is a small gotcha: you can't declare the duplicate fields in the same class definition. So how can you do this? Well you use inheritance. You can have a simple class that inherits from another base class declaring another field with the exact same name as field from the base class. They will look like this: In this case, what field will be accessed from these duplicate fields? It's actually pretty simple. It depends on how you reference the object. Each object has a type which can be a class, structure or some

Making a simple modular single paged website using ASP .Net MVC and knockout.js

This post will be about how to make a simple website that supports multiple modules which are displayed in a single page. By default unlike a lot of other javascript frameworks, knockout.js doesn't really support modules. But fortunately we can implement this functionality using knockout.js itself. We are also going to use bootstrap because it already has builtin support for tabs and other useful features. The structure of the website will be based on tabs. On the left of the tab header bar we will have a menu from which we can select a module to open just by clicking on it. Once we open a module, a tab header will appear up in the tab header bar with the name of the module. And down in the tab content pane, the content of the current tab will appear. Bellow we can see a sketch of the website: We will have a javascript object type which will hold the name, id and functions to load and unload a module from the module tab content area. It looks like this:

A post about generating stream reading and writing libraries from specifications

This post is about generating a file reading/writting library from some sort of specifications, in this case in the form of an xml file that details the internal binary structure of the file. Using this approach, we can define the format in an xml file and create some code generating tools to write code for libraries which read and write in that format for a given language such as C++ or python. These tools will also create some models in the respective programming language that are read and populated by the generated library. This has the advantage in case the format changes we just run the tool again with the updated format from the xml file. The code for reading the format will be updated and all that we need to do is to recompile it. It also allows people who are not familiar with programming to edit the format without writing code. I am going to use an open source project called niflib which reads and write 3d models in files for games like Elder Scrolls Skyrim. You can find

A bit about .tt templates used in Entity Framework and not only

Most developers that have used Entity Framework will surely have noticed some special files in the project that end in ".tt". These files serve as blueprints for the code that is generated from the Entity Framework mappings which are stored in an xml file ending in ".edmx". A ".tt" template is similar to the ".cshtml" files used in Asp .Net MVC but instead of rendering html content it renders C# code. By editing these files we can customize how the generated code will look and behave. For example the partial ".tt" template bellow for each column in a table in the database it generates a property that implements the INotifyPropertyChanged interface to notify subscribers that the object has changed: This is applied for each column in every table. Using this code we can bind our objects directly to a Windows Presentation Foundation interface after fetching them from the database. We can also generated backing fields for that prop

A post dedicated to Autodesk Maya and the Maya API

I wanted to write this post for a long time now. In my free time I also do 3D stuff like models and various other things. While doing these I came across Autodesk Maya and from a developer's perspective I like it a lot. It's one remarkable piece of software. Over the years it just kept growing and getting better. Today it has a huge variety of features and amazing support for developing various new components for it. I will start with the basics. Surprisingly for a program it has it's own dedicated scripting and programming language called Maya Embedded Language or MEL. In reality the entire application is just one interpreter that reads these MEL scripts to generate the user interface. As you have guessed by now, the entire user interface is written in MEL. It looks a lot like php and it has some special functions called commands which interact with Maya. With these commands we can add new menus or even edit 3D objects inside it. The partial script bellow is writte

Part 2 of writting an expermental code analyzer and sort of interpreter for C#

This is a continuation of my blog series about writing a hybrid C# code analyzer and interpreter. Compared to part one, I renamed the variable references from "TrackedVariableReference" to "EvaluatedObjectReference" and a variable is now known as an "EvalutedObject" or any subtypes derived from it. This part will focus on the simulation of the code execution. The core part is the object that stores the current execution state which is of type "CodeEvaluatorExecutionState". The most important things stored in this state object are the objects of the type "CodeEvaluatorExecutionFrame". These objects represent a method call and store all the local parameters corresponding to a method call. These parameters include the local "this" reference, the local objects created inside the method, the passed parameters from caller of the method and a special slot for a reference which contains the results of an expression. This last slot

An inside look at a serious open source project called Blender 3D

I am writing this because some time ago I took a look inside the source code of the most popular 3D open source computer graphics software called "Blender 3D". I didn't have a blog at that time and I feel like I learned a lot just by studying the source code of this program. To start things, Blender is actually written in C mostly with some parts in C++ and some parts in Python. To make matters a bit more confusing, the parts written in C actually represent the MVC design pattern. Yes, I know. C isn't really an object oriented programming language and yet here we have an application written in C that implements the MVC design pattern. So how does it implement the MVC design pattern? The application is separated into 3 main areas. The first area contains the operator and operator types. An operator type pretty much describes any action a user can execute inside the program that alters the data in the program. The operator represents an actual instance of an opera

Some small observations about working in a team

As we approach the first official delivery of the automated laboratory system on which I have been working on for the past couple of years with my colleagues I realized some important conclusions about working in a team. I realized now that all of us from my team have kind of grown together over the past couple of years. All those challenging situations, funny moments and hard work have brought us together without us even knowing. When I first started in this team, we were all quite different and initially kind of cold to each other. Especially my boss but I think that is expected since he is in a delicate position and so I understand him. But as we worked more and more together, we kind of slowly started opening up. I realized then that it's not enough just to be colleagues in order for a team to work. You actually need to see everyone as a bit of a friend. Why you ask me? Because only then you will feel free to collaborate with other people to work together on something. I no

Why big tasks are hard to estimate properly and what to do about this.

I will begin this by stating clearly: you should never get to the point where you need estimate how long it will take a big task to be completed. You should never have big tasks in the first place. There are a lot of reasons why having big tasks is a seriously bad idea. Firstly, big tasks have big requirements and by the time the developer is halfway there he will most likely have forgotten parts of the requirements. A developer working on a big task needs to keep the requirement fresh inside his mind each day. Otherwise if he forgets some things he won't implement them at all. This is an issue even where I work. So extra time is wasted just refreshing those requirements. Secondly, big tasks tend to affect a lot of systems inside an application. Most developers don't know all the systems in the application so he might spend a lot of time figuring out how those systems work and how does his task affect those systems. A series of smaller tasks can be worked on in parallel and

A glance at the insides of the CoreCLR

So these past days I was kind of bored and also I wanted to prove to myself that I can take a serious software project and the understand it. I heard so many things about the CLR like it was some kind of alien technology that no one could understand. I saw that it as a challenge and decided to see if it's really like that. And the rumors were true in a way. The CLR is a marvel of software engineering. It is actually made out of multiple systems with one central system that glues them together. That central system is called the "Execution Engine". I think it's what controls and manages the execution of the program. It is for example responsible for stopping the execution of the program when the garbage collector starts to do it's job. Actually the garbage collector sends a command to the execution engine to stop the execution of the program. Yes, the garbage collector is another system just like the execution engine. It is actually pretty interesting to see how

Part 1 of writting an experimental code analyzer and sort of interpreter for C#

The purpose of this C# analyzer is to see all possible execution paths from any entry point inside the code. Currently the entry point can be only a method. There are multiple ways to deal with this. The approach would be to rewrite all existing code and rewrite all conditional statement so that they are true all the time. This approach has numerous disadvantages. Firstly, it will actually execute the code and any calls to external resources such as databases will be executed. Since the code has been altered, there is also no guarantee that it won't produce exceptions at runtime. And for really big code bases, it will be incredibly slow and it will require actual compilation of the modified code which may take even more time. My approach is to write a C# interpreter with some special conditions that will go through all possible execution paths. In order to go through all the execution paths, our interpreter will need to ignore all the conditional statements and jump directly

Why I am starting this blog

Lately I realized that it would be a good idea to start writing a blog about my experiences coding various stuff or analyzing the source code of various pieces of software. So I decided to start this blog because I tend to forget what I studied over the course of the years. I feel that I missed so much not writing about these things. And surprisingly no one actually knows what I really delved into. It seems that I underestimated some of the stuff I did too, things like coding a kind of weird interpreter for C# using parts of the "Roslyn" compiler. With this blog maybe people can see what I really do and how I really think. It can also serve as a diary to show my evolution in software engineering and programming. So I hope you all enjoy reading this blog!