谈谈static和util/helper类
今天先聊聊static方法的那些事儿,然后再引出static使用的“极致” util/helper类,说说它们的问题。
今天先聊聊static方法的那些事儿,然后再引出static使用的“极致” util/helper类,说说它们的问题。
事情源起于心血来潮把Hexo从v3.9.0升级到了v4.0.0,Hexo本身的升级倒是不难,它由npm管理,改下package.json,运行npm update即可。但之后发现在archives的分页显示有问题……
有这样的一个interface:
public interface Filter
{
IList<string> Filter(IList<string> responses)
}
在实现它时,如果过滤后没有结果,返回null还是new List
Hexo 4.0.0 has been released on 2019-10-14. How to upgrade it?
Unity是一个.NET Framework用于依赖注入的容器。依赖注入一般分为三个阶段:Register, Resolve和Dispose。Unity支持三种方式的Register:
那这三种方式分别用于什么场景呢?简单来说,Instance registration和Type
registration较为常见,直接通过ResolvedParameter解析依赖的对象,Factory
registration更灵活,可以通过调用方法创建对象。举个例子,如果注入对象所依赖的参数是一个List<T>
或Dictionary<T1, T2>
,而T又是自定义的类,那么就必须使用Factory
registration。本文主要介绍的就是如何解析一个自定义类的List或Dictionary。
When you use RegisterType or RegisterInstance combined with InjectionFactory in old version of Unity, the following complier warning will be displayed:
'InjectionFactory' is obsolete: 'InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.
使用Unity的InjectionFactory进行依赖注入遇到如下提示:
'InjectionFactory' is obsolete: 'InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.
在代码库里看到不少Task.ContinueWith()的代码,查了下语法,没太理解下面两种写法的区别(借用MSDN的代码):
public static async Task ContinueWithExample()
{
// Execute the antecedent.
Task<DayOfWeek> taskA = DayOfWeekAsync();
// Execute the continuation when the antecedent finishes.
await taskA.ContinueWith(antecedent => Console.WriteLine("Today is {0}.", antecedent.Result));
}
AIMD (additive-increase/multiplicative-decrease)是用于TCP拥塞控制的算法。AIMD思想虽然简单,但我认为它非常符合“simple but elegant”的哲学。尤其是在多连接拥塞控制中的公平性分析,还挺巧妙。这里主要探讨AIMD在非TCP场景下的应用,不对其原理进行深度剖析。