eagleboost Blog

梦想做大侠

慎用隐式类型转换

  .Net允许用户自定义运算符operator来实现两个类型之间的转换以提高代码灵活性。自定义运算符分为显式和隐式两种。显式运算符需要在代码中明确地把目标类型写出来,隐式运算符则由编译器自动检测和推断类型再生成相应代码。   比如有下面这样一个类型,可用于根据string类型的id查找一个由泛型参数T指定的对象。 1 2 3 4 5 6 public sealed class Look...

一个AI能帮上忙的Bug

  去年底在处理项目中一个性能问题的时候碰到一个有意思的Bug。   一段代码大致如下,给定一个类型为Entity的元素以及相应的key,以及一个已排序并且可能有空位的数组array,从给定的下标index开始(该下标通过二分查找得到),先往头部遍历array,如果找到已存在的元素或者不存在但找到空位并添加成功则返回(状态为Success),否则跳出循环(状态为Break),再从下标开始往...

中英文效率比较的一个侧面

——从数字转换的效率和内存开销的角度

  中文和英文作为主流的两种语言,其实有不小的区别。可以比较的点很多,其中一种比较从信息论的角度用香农熵比较科学地给出了数学对比,即中文汉字比英文字母拥有更高的的香农熵,或者说信息容量,信息密度,因此表达同样的信息需要用到的中文字符更少。这比较符合人们的主观感受,比如同一本书的中文版往往比英文版更薄。   一个偶然的机会,我意识到可以从编写计算机程序的角度来做一个定量的比较,具体就是比较中...

ChatGPT-4

ChatGPT-4   之前对ChatGPT进行过两次测试,第一次是刚推出时进行的面试测试,纯粹从语言交流的角度来说其表现可以用惊艳来形容。第二次是用中英文数字转换为主题进行的编程测试,结论是ChatGPT并不真的会写代码。   前几天看了GPT-4 Developer Livestream,对ChatGPT又有了进一步的了解。   在视频的TaxGPT示例中,开发人员把计税的一大段规...

# 0.01粗糙版数字永生

——一ChatGPT功用乱想

0.01粗糙版数字永生   最近ChatGPT开放了API,最新的定价也出来了,据说比以前的版本便宜了挺多。于是写了几段代码试着调用一下。跟网页版类似,提出一个问题(写一段话)就会得到一个回答。然而如果只是这样的话可以说毫无意义,用网页版就得了还写代码干啥?   ChatGPT作为大语言模型,最擅长的是自然语言处理。很多人使用ChatGPT已有的知识来帮助写文章,然后自己修改,或者自己写...

浅谈Mediator/MediatR

Avoid abusing the Mediator pattern

I’ve been interviewing candidates in the past several months. The candidates are from different sources, both internal and external. In general candidates from Investment Banking industr...

避免使用枚举类型 (2) TypeSafeEnum

TypeSafeEnum

1. Benchmark Let’s create some benchmark test codes to compare traditional Enum, EnumBox/EnumParser helper class and TypeSafeEnum from 3 aspect: parsing from string, converting to strin...

避免使用枚举类型 (1) No more Enums

No more Enums

1. The problem As one of the basic data types in a lot of programming language, Enum provides Alias capability for a set of integers with limited number of values, it’s very easy to use...

M-V-VM视图交互简述

Interactions between the View and ViewModel

1. The problem Displaying dialogs/windows is a common scenario in desktop applications. Modal dialogs are used most often, like MessageBox, or more complex ones like Login Dialog that r...

Implicit boxing in System.Array.IndexOf

1. The Problem I was fixing some performance issues for our project last week, and interestingly the profiler shows boxing operation (allocation of char) happened inside a method that c...