InternetException

Posts

CPU bound vs I/O bound

· 158 words · ~1 min read · in .NET, interview

#async

There are two types of asynchronous operations in .NET.

  • I/O bound
  • CPU bound

For I/O bound async/await syntax should be used. TPL should not be used for this. async methods does not spawns new thread to hand le I/O work asynchronously.

For CPU bound operations TPL should be used (Task.Run). This spawns new thread. Performance testing should be done to check if overhead of new thread and context switching is not greater than actual work to be done.

Read the whole thing →

SupressFinalize in IDisposable interface

· 143 words · ~1 min read · updated · in .NET, interview

  • informs GC that object does not need to be added to finalizer queue
  • finalizer execution is not deterministic and objects can live for long time in queue - this is optimization technique
  • to make sure that object disposes of any unamanaged resources even if Dispose will be not called we need to implement finalizer

Basically finalizer execution time is not deterministic. We cannot predict when this will be called and till that time - object is existing and still taking memory space. Since we are controlling creation and disposal of those resources we can say to GC: ‘Do not worry about that! It already had been taken care of!’. So this way object will be destroyed sooner, leaving this space to be used by something else possibly.

Read the whole thing →

IDisposable interface pattern

· 218 words · ~1 min read · updated · in .NET, interview

#design patterns

Example implementation of IDisposable

public class MyResource : IDisposable
{
    public MyResource(IntPtr handle)
    {
        this.handle = handle;
    }

    public void Dispose()
    {
        Dispose(disposing: true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if(!this.disposed)
        {
            if(disposing)
            {
                component.Dispose();
            }

            CloseHandle(handle);
            handle = IntPtr.Zero;
            disposed = true;
        }
    }

    ~MyResource()
    {
        Dispose(disposing: false);
    }
}

MyResource object have pointer which is unmanaged. This is why this class should implement IDisposable interface. Implementation should be correct according to recommended pattern (see below for documentation).

There a re few points to highlight here:

Read the whole thing →

General Interview Questions

· 71 words · ~1 min read · in general, interview

Closed What is asynchronous programming? What is TDD What is BDD What is DDD Open - to consider for yourself Interesting technical problem you solved lately Interesting technical problem you solved during your career What is the process of the MR/PR change review for you What is great success you accomplished lately? What skill did you improved lately? What is your greatest failure during your career? What was your biggest mistake?

What is DDD

· 67 words · ~1 min read · in general, interview

software design approach software should be driven by business domain pieces of software should match the business domain goals: domain is primary focus complex design should base on model of the domain devs and business should continuously work on refining this model to address changes in business common language for defining a business model of the domain complex logic should be abstracted to domain Further read: https://en.wikipedia.org/wiki/Domain-driven_design

What is BDD

· 66 words · ~1 min read · in general, interview

based on TDD better collaboration between devs, QAs and business than TDD behavioral tests first, implementation second behavioral tests should be easy to understand, simple those tests should be written in specific language, possible to understood by business combines idea of unit tests naming, acceptance tests standard agile framework (As a XXX I want YY to achieve ZZ), and acceptance criteria with Gherkin Further read: https://en.wikipedia.org/wiki/Behavior-driven_development

What is TDD

· 32 words · ~1 min read · in general, interview

Test-driven development software requirements are converted to tests cases *before* actual implementation implementation is done against all those test cases opposing to first writing an implementation then tests cases Further read: https://en.wikipedia.org/wiki/Test-driven_development

What is asynchronous programming?

· 589 words · ~2 min read · updated · in general, interview

#async

  • software often waits for some I/O operation to complete (file operation, network call, database query etc.)
  • we can use this time for something productive instead to wait for data to be available or I/O operation to be completed
  • with asynchronous programming user can work in the meantime
  • not waiting for I/O operations synchronously enhances user experience

Of course this problem is much more complex. Modern software operates on much more different PC architecture than 20 years ago. Nowadays software must be asynchronous to appear more user friendly and to made better use of modern multi CPU architecture. Right now complex, professional software uses multiple processes, threads on multiple CPUs (CPU you buy is not really *single* CPU) or even utilize GPU for more complex computations (like i.e. video editing software). Before that we mostly had single threaded desktop applications that had ‘please wait’ or ’loading’ pop ups. Right now this is song of the past really and to achieve better User Interfaces that allow to edit tag of your post without changing whole post. With mobile devices on the rise and sometimes lousy cellular network those kind of designs would not be sensible or sometimes impossible to implement. Did you ever happened to reenter some chunk of data into some software because you lost it? Maybe network was down? Or you hit back button by mistake? Right now it belongs to past mostly. All of those would be hard to do with synchronous operations. Right now people are bit spoiled and they tend to leave the page/application if it appears to be slow and not every company can sell ‘one-in-the-market-necessary-for-your-work-software’ that you will be forced to use. And this is why we have asynchronous operations and this is why we have asynchronous programming model that allows us to program such operations.

Read the whole thing →

Automatic scrolling to edited text box in Xamarin Android.

· 858 words · ~4 min read · updated · in .NET, Android, C#, Xamarin

Important note: this should work well with newer version of Xamarin (2.3.3). If you cannot update for some reason this article will explain workaround.

Introduction

In previous article I explained how to detect show and hide events of software keyboard in Xamarin Android. I did it in my project because of the fact that some of text boxes was hidden by software keyboard that suppose to edit contents of those text boxes. In this article I will explain how to work around this issue in some older versions of Xamarin.

Read the whole thing →

Xamarin with TinyIoC

· 3190 words · ~15 min read · updated · in .NET, Android, C#

#XAML #dependency injection #Xamarin

Introduction

This article is builds on topics and solutions introduces in ViewFactory for Xamarin application and Xamarin Master-Detail Page articles. It shows method for easier navigation and use of services via IoC in Xamarin application. Knowledge from previous examples is not necessary, but makes this article bit easier to understand.

Read the whole thing →

Genereting proxies during runtime using Reflection.Emit

· 4156 words · ~20 min read · updated · in .NET, C#, WCF

#reflection #self-hosting #delegates #XAML

Reflection.Emit is very powerful tool. It creates IL code and since C# is converted into IL too, we have the same functionality as in C# and even more. It is very powerful and at the same time very complicated. Because of that it is worth to discuss how and for what it should be used. One idea is to create dynamic code with automatic implementations of interfaces - proxy types.

Read the whole thing →

Faster than Reflection: Delegates. Part 3.

· 6868 words · ~34 min read · updated · in .NET, C#

#delegates #reflection #generics #NuGet

This is third article in series, that explains how to create delegates for public and non-public members of public, non-public or not known in compile-time types. If you are not familiar with previous articles and looking for detailed explanation of how delegates works, how they are created and why, I strongly encourage you to read first two. If you are just looking for a way to create delegates for methods or constructors it is not necessary. Code with new features and with bug fixes is available on GitHub and as Nuget package.

Read the whole thing →