Programming Language

Strong types for strong interfaces

How to add a type wrapper for built-in types.

Besides using phantom template parameter to avoid alias, one can also use private inheritance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class NamedType
{
public:
explicit NamedType(T const& value) : value_(value) {}
explicit NamedType(T&& value) : value_(std::move(value)) {}
T& get() { return value_; }
T const& get() const {return value_; }
private:
T value_;
};

class Width : NamedType<int> {
public:
using NamedType::NamedType;
using NamedType::get;
};

Passing strong types by reference – First attempt

This post is the sequal of the above post.

The main problem the post tryies to solve is: how to make copy of NamedType values cheap.

However, I am conservative on using reference-wrapper as the solution, because doing this has to expose the lifetime of the wrapped object to public; after all, reference-wrapper is only a point per se.

I think the real solution is to make wrapped object type clear about being value semantics or reference semantics.


Float vs Double

Using double is usually faster than using float.

Because compilers usually promote float to double for evalution, and convert back as final result.


CppCon 2015: Peter Sommerlad “Variable Templates and Compile-Time Computation with C++14”

This talk really presents some amazing magics, like generating multiplcation table on compile time…


Don’t Try Too Hard! – Exception Handling

  • Restrict exception types that may throw to control catch handlers.
  • Use RAII instead of try/catch for cleanup in the presence of exceptions.
  • Try not to change exception types.
  • Be consistent in use of exceptions.
  • Exceptions are part of a library’s interface but can be leaked more easily. Encapsulate them properly.
  • Only catch exception if you have enough information to take actions on them.

Helper Classes Deserve Some Care, Too

Know C++ compilation and linking model and internal linkage can be your friend.

There are other engineering advice but they have been talked too much and I decide to follow the DRY principle.

Operating System

Exploring Windows virtual memory management

This post should be divided into several parts to reduce information density.

Besides, this post lacks a systematic roadmap for thinking clearly.

Maybe reading Windows Internals is a better option.

Network

TCP连接状态异常记录

What does too many CLOSE_WAIT connections mean and how to solve it.


Coping with the TCP TIME-WAIT state on busy Linux servers

what is TIME_WAIT and why net.ipv4.tcp_tw_recycle evil


HTTP2 for Dummies

扫盲,就是内容太少了。

这样看起来 dummy 也太 dummy 了

Architecting

多研究些架构,少谈些框架(1) – 论微服务架构的核心概念

多研究些架构,少谈些框架(2)– 微服务和充血模型

多研究些架构,少谈些框架(3)– 微服务和事件驱动

因为没有具体经验,所以上面三篇文章干货足不足不好评判


Web Architecture 101

The basic architecture concepts I wish I knew when I was getting started as a web developer.

MISC

It all comes down to respecting levels of abstraction

One principle to rule others all: respecting levels of abstractions.

Respecting levels of abstraction means that all the code in a given piece of code (a given function, an interface, an object, an implementation) must be at the same abstraction level.

Constantly ask yourself: in terms of what am I coding here.

Over-generalization

Generalizations has a cost. Don’t generalize a function because you have a hunch that “some day in the future” the generalization might be useful.