To Add Comments or Not to Add?



A really good comment is the one you managed to avoid. (c) Uncle Bob

Lately, I’ve been feeling really tired of hot discussions on if it’s necessary to add comments in the code. As a rule, there are self-confident juniors with the indisputable statement as: “Why not to comment it, it will be unreadable without the comments!” on one side. And experienced seniors are on the other side. They understand that if it’s possible to go without the comments than “You better, damn it, do it in this way!” Probably, many developers got comment cravings since they’ve been students when professors made them comment every code line, “to make the student better understand it”. Real projects shouldn’t contain a lot of comments that only spoil the code. I don’t agitate for avoiding comments at all, but if you managed to write the code that doesn’t need comments, you can consider it your small victory. I would like to refer you to some good books that helped form my position. I like and respect these authors and completely share their opinion.


Read more


Unexpected area to collect garbage in .NET



The .NET framework provides an intelligent garbage collector that saves us a trouble of manual memory management. And in 95% of cases you can forget about memory and related issues. But the remaining 5% have some specific aspects connected to unmanaged resources, too big objects, etc. And it’s better to know how the garbage is collected. Otherwise, you can get surprises.

Do you think GC is able to collect an object till its last method is complete? It appears it is. But it is necessary to run an application in release mode without debugging. In this case JIT compiler will perform optimizations that will make this situation possible. Of course, JIT compiler does it when the remaining method body doesn’t contain references to the object or its fields. It should seem a very harmless optimization. But it can lead to the problems if you work with the unmanaged resources: object compilation can be executed before the operation over the unmanaged resource is finished. And most likely it will result in the application crash.


Read more


Unobviousness in use of C# closures



C# gives us an ability to use closures. This is a powerful tool that allows anonymous methods and lambda-functions to capture unbound variables in their lexical scope. And many programmers in .NET world like using closures very much, but only few of them understand how they really work. Let’s start with a simple sample:

public void Run()
{
  int e = 1;
  Foo(x => x + e);
}

Nothing complicated happens here: we just captured a local variable e in its lambda that is passed to some Foo method. Let’s see how the compiler will expand such construction.*

public void Run()
{
  DisplayClass c = new DisplayClass();
  c.e = 1;  
  Foo(c.Action);
}
private sealed class DisplayClass
{
  public int e;
  public int Action(int x)
  {
    return x + e;
  }
}

Read more


Wrapping C# class for use in COM



Let us have a C# class that makes something useful, for example:

public class Calculator
{
    public int Sum(int a, int b)
    {
        return a + b;
    }
}

Let’s create a COM interface for this class to make it possible to use its functionality in other areas. At the end we will see how this class is used in Delphi environment.


Read more


About



Andrey Akinshin is a software developer, an author of blog posts and papers about mathematics and programming, a frequent conference speaker (100+ public talks). He is the project lead of BenchmarkDotNet (the most popular .NET library for benchmarking) and perfolizer (performance analysis toolkit); the author of Pro .NET Benchmarking (a book about good practices of performance measurements). Currently, Andrey is the performance lead in JetBrains Rider (a cross-platform .NET IDE based on the IntelliJ platform and ReSharper). He is also the program director of the DotNext conference, an ex Microsoft .NET MVP, a silver medalist of ACM ICPC. Andrey is a Ph.D. in computer science. He is involved in a research project at the Sobolev Institute of Mathematics SB RAS related to mathematical biology and bifurcation theory. Previously, he worked as a postdoctoral research fellow at the Weizmann Institute of Science.
Read more


Information partners



Jooble is a search engine specializes in job search. The company is represented in 71 countries. The search is conducted among all job portals in the country. Jooble automatically filters out duplicates, so the same job posted on different job sites will be shown as one.
Read more


Pro .NET Benchmarking



Learn how to measure application performance and analyze the results! Use this in-depth guide to correctly design benchmarks, measure key performance metrics of .NET applications, and analyze results. This book presents dozens of case studies to help you understand complicated benchmarking topics. You will avoid common pitfalls, control the accuracy of your measurements, and improve performance of your software. Author Andrey Akinshin has maintained BenchmarkDotNet (the most popular .NET library for benchmarking) for five years and covers common mistakes that developers usually make in their benchmarks. This book includes not only .NET-specific content but also essential knowledge about performance measurements which can be applied to any language or platform (common benchmarking methodology, statistics, and low-level features of modern hardware). With this book, you will learn: Be aware of the best practices for writing benchmarks and performance tests Avoid the common benchmarking pitfalls Know the hardware and software factors that affect application performance Analyze performance measurements Apress Amazon US Amazon CA Amazon UK Amazon DE Amazon FR Amazon ES Amazon JP Springer Google Books O’Reilly GoodReads ResearchGate GitHub (Examples) Content The book contains nine chapters: Chapter 1 “Introducing Benchmarking” This chapter contains some basic information about benchmarking and other performance investigations, including benchmarking goals and requirements. We will also discuss performance spaces and why it’s so important to analyze benchmark results. Chapter 2 “Common Benchmarking Pitfalls” This chapter contains 15 examples of common mistakes that developers usually make during benchmarking. Each example is pretty small (so, you can easily understand what’s going on), but all of them demonstrate important problems and explain how to resolve them. Chapter 3 “How Environment Affects Performance” This chapter explains why the environment is so important and introduces a lot of terms that will be used in subsequent chapters.
Read more