Effective C++
基于 Effective C++ Third Edition: 55 Specific Ways to Improve Your Programs and designs 编写
让你自己习惯于 C++
将 C++ 视为语言的联邦
C++ 不是一门单独的语言,其具有各种不同风格的语言特性,以至于可能出现两个同样使用 C++ 的人会看不懂彼此的代码。一般分为四大组成部分:
C
面向对象的 C++
模板 C++
STL
因此基于使用的 C++ 的部分不用,Effective C++ 编程的规则也可能不同
倾向于 const、enum 和 inline 而不是 #define
对于变量而言,const 和 enum 限制了作用域
对于函数而言,inline 函数能够避免一些未知错误
尽可能使用 const
声明某种东西 const 可以帮助编译器检测一些使用错误,同时 const 可以适用于任何作用域中的对象,包括函数参数,返回值,甚至整个成员函数
编译器强制 bitwise const,但应该使用逻辑 const 编程
当 const 和非 const 成员函数有相同的实现时,可以让非 ...
Java 开发手册
基于 Alibaba 的 Java 开发手册编写
编程规约
命名风格
类名:UpperCamelCase,其余使用 lowerCamelCase,常量全部大写
抽象类使用 Abstract 开头,异常类使用 Exception 结尾,测试类以要测试的类的名称开始,以 Test 结尾
包名统一使用单数形式
在变量命名时,表示类型的名词放在结尾,如 nameList
设计模式应该体现出来
接口类中不要加任何修复符号
Service/DAO 层命名规约:
获取单个对象:get
获取多个对象:list,并复数结尾
获取统计值用 count
插入 insert
删除 remove
修改 update
领域模型:
数据对象:数据表名 + DO
数组传输对象:业务领域相关的名称 + DTO
展示对象:网页名称 + VO
OOP 规约
所有整型包装类对象之间值的比较,均使用 equals
BigDecimal 使用 compareTo() 方法比较
所有 POJO 类属性和 RPC 方法必须使用包装数据类型,局部变量使用基本数据类型
集合处理
Comparator ...
IntelliJ IDEA
IntelliJ IDEA 是 Java 和 Kotlin 的知名 IDE,简单而功能强大
插件推荐
Chinese (Simplified) Language Pack / 中文语言包
我判断一个外国工具是否流行的唯一依据是其是否支持中文。 ——沃兹基·硕德
CodeGlance Pro
侧边栏显示代码缩略图,类似与 VS Code 的功能
Rainbow Brackets
彩虹括号,可惜是付费的,但也有免费的版本:Rainbow Brackets Lite
Alibaba Java Coding Guidelines(XenoAmess TPM):基于 Java 开发手册,提供了一系列的代码检查和修复功能
Json Parser:验证和格式化 JSON 字符串的工具
Grep Console:给控制台输出标上颜色,过滤输出等
Atom Material Icons:IDEA 版的 Material 图标库
RestfulTool
方便查看 Restful 服务开发
C++ 入门(下)
关联型容器 Associative Containers
关联型容器通常需要键满足 <,否则可以自定义一个:
bool compareIsbn(const Sales_data &lhs, const Sales_data &rhs) { return lhs.isbn() < rhs.isbn();}multiset<Sales_data, decltype(compareIsbn)*> bookstore(compareIsbn);
关联性容器定义了三种类型:
key_type
mapped_type
value_type
set:key_type
map:pair<const key_type, mapped_type>
set 的迭代器都是 const_iterator
.lower_bound() >=,.upper_bound() >,.equal_range()
除此之外,还有键可以重复的 multiset 和 multimap
unordered_set 和 unorde ...
Makefile
介绍
Makefile 的基本规则:
target ... : prerequisites ... recipe ... ...
target:可以是一个 object file(目标文件),也可以是一个可执行文件,还可以是一个标签(label)
prerequisites:生成该 target 所依赖的文件和/或 target
recipe:该 target 要执行的命令(任意的 shell 命令)
简单来说就是指定了一个依赖关系
输入 make 命令时,是这么工作的:
make 会在当前目录下找名字叫 Makefile 或 makefile 的文件
如果找到,它会找文件中的第一个目标文件(target),并把这个文件作为最终的目标文件
如果该文件不存在,或其所依赖的后面的 .o 文件的文件修改时间要比这个文件新,则执行后面所定义的命令来生成这个文件
如果所依赖的 .o 文件也不存在,那么 make 会在当前文件中找目标为 .o 文件的依赖性,如果找到则再根据那一个规则生成 .o 文件
最后用 .o 文件生成可执行文件
在 Makefile 中可以声明变量并 ...
打倒孔家店,救出孔夫子
~~抡语~~
既来之,则安之。
既然来到了这里,那么就安葬在这里吧。
子不语怪、力、乱、神。
夫子不想说话,施展起怪力将人打的神志不清。
朝闻道,夕死可矣。
早上听到我来了,今晚你就得死。
三人行,必有我师焉。
有三个人,只要其中有一个是我,战力就相当于一个师。
父母在,不远游,游必有方。
你父母在我手里,你跑不了的,就算你跑了,我也有办法把你抓回来!
论语
我小时候认为孔子说的话很有道理,也不管究竟是不是他说过的话,一律奉为圭臬。长大后有了独立思考的能力,并了解了一些历史,觉得孔子的话根本就不对。其之所以流行,只是迎合了统治阶级的需要,是用来麻痹老百姓的。再后来读了《论语》,理性思考之下,才发现我以前对孔子有很多的误解。他的很多思想直到现在都闪烁着光芒。数千年来,他为董仲舒所用、为朱熹所用、为陈独秀所用,他从一个“山东大汉”成为了一个“文弱书生”,是时候为他正名了,打倒那些人粉饰过后的“孔家店”,救出真正的那个“孔夫子”。
以德报怨,何以报德?以直报怨,以德报德。
要断章取义 —— 节选自《不要断章取义》
孔子的这句话无疑是被曲解最严重的,以至于 ...
VS Code
VS Code 是流行的代码编辑器,可以通过插件支持各种语句的高亮、调试、编译等
设置
字体喜欢使用 JetBrains Mono,字号设为 14,并开启连字
快捷键
功能
快捷键
功能
快捷键
移动行
alt + up / down
查找文件
ctrl + p
显示相关插件的命令
ctrl + shift + p 或 F1
多行同时添加内容(光标)
ctrl + alt + up / down
光标跳到下一个单词
ctrl+ left / RIGHT
行增加/减少缩进
ctrl + [ / ]
隐藏底部控制面板
ctrl + j
显示/隐藏左侧目录栏
ctrl + b
语言支持
Markdown
Markdown All in One
几乎涵盖了大部分内容
Markdown Preview Enhanced
Markdown 预览
Unicode Latex
将 Latex 符号转化为 Unicode 符号,更容易辨认
JavaScript/TypeScript + React
原生支持(毕竟 VS Code 就是用 TypeScript 编写的,所 ...
C++ 入门(上)
基于 _C++ Primer Fifth _ 编写
不愧是 C++,这才只是入门,只到 C++ 11
开始 Getting Started
万恶之源:
#include <iostream>int main() { std::cout << "Hello, world!" << std::endl; return 0;}
文件的后缀名有很多,最常见的应该是 .cc 和 .cpp
编译器也有很多,如使用 g++ 编译:
g++ -o prog1 prog1.cc
添加支持 c++ 11 标准:-std=c++11
-Wall 生成更多警告信息
输入输出:
这里使用了 iostream 库中的标准输入流和标准输出流,该库中还有标准错误流 cerr 和 clog
<< 是输出操作符,>> 是输入操作符
endl 是一种控制符 manipulator,有结束当前行和刷新缓冲区的作用
std:: 表示使用命名空间 namespace 的函数等,用于区分
一个读入的例子:
std ...
CMU 15-445:数据库系统
关系模型与关系代数 Relation Model & Relation Algebra
**数据库管理系统 Database Management System(DBMS)**允许应用程序存储和分析数据库中的信息的软件,通常支持根据某种数据模型定义、创建、查询、更新、管理数据库
数据模型 data model 是描述数据库中的数据的概念的集合
模式 schema 是使用给定数据模型,对特定数据集合的描述
关系型数据库的发明者——Codd
关系 relation 是包括了表示实体的属性关系的无序集合
元组 tuple 是关系中属性值的集合,类似于行
主键 primary key 唯一地指定了一个 tuple
外键 foreign key
数据操作语言 Data Manipulation Languages(DML):从数据库中存取信息的方法,有程序性的(关系代数)和非程序性的
关系代数 relational algebra:
σpredicate(R)\sigma_{predicate}(R)σpredicate(R):类似于过滤器
πA1,…,An(R)\pi_{A1,\d ...
Spring Boot
Maven
Maven 可以用于管理 Java 项目的依赖
在 pom.xml 文件中指定了 Maven 坐标,其构成如下:
groupId:通常是域名反写
artifactId:通常是模块名称
version:版本号
引入依赖:在 <dependencies> 标签下,使用 <dependency> 引入标签,并定义 Maven 坐标
依赖有传递性,可以使用 <exclusion> 手动排除依赖的资源
使用 <scope> 设置其作用范围,通常使用默认的和 <test>
Maven 有 3 套独立的生命周期:
clean
default:编译、测试、打包、部署等
site:生成报告、发布站点
可以手动执行其中的若干个生命周期
请求与响应
Tomcat 是一个轻量级的 web 服务器,支持 Servlet 规范
几种请求参数:
简单参数:名字一致,也可以使用一个对象接收多个参数
GET http://localhost:8080/simpleParam?name=Tome@RequestMapping("/s ...
这一切值得吗
城市没有消亡,但这一切值得吗?
这是这款游戏引起争议的很重要的一点,人们纷纷给它贴上了“白左”的标签。的确,末日到来了,老子辛辛苦苦把这么多人救了下来,居然还这样居高临下地问我值不值得,难怪被喷得体无完肤。
但是,当我真正地深入了解这款游戏之后,才发现这完全是很多不良媒体的断章取义导致的。上述所谓的“越界”结局并不是一定会触发的,而且“越界”的条件也不是“童工”、“木屑餐”、“加班”等“自由民主”的西方“人权”口号,而是选择成为了一个独裁者或新教皇。事实上,这些被称为“越界法典”的法典并不会增加生产效率,其目的只是维护自己的统治。要知道,当不满拉满或者希望归零时失败的是玩家,是玩家被赶了出去,然后会有一个新的人被选出来成为新的领导者(就是“冬日之家”中玩家扮演的角色),所以说,玩家失败了,城市就会消亡吗?这并不一定。
不过游戏做的也不好。越界法典和普通法典没有什么不同,导致很多玩家都以为这个和科技树一样一直点到头就行了,谁知道有些法典是不能点的。如果都像“最后的秋天”中的法典一样写着令人毛骨悚然的“每天都有一个人被处死”,大概就不会有这么多人毫不犹豫地点开这个法典了。还有游戏的剧情和 ...
人类的赞歌就是勇气的赞歌
下去四个,疯了五个
早就听说过这款游戏的大名,同时也早就准备好了不当人的准备,但当我看到辛辛苦苦培养出的高级英雄就这样被全灭了的时候,还是有种想要重开的准备。当然,相比这部游戏的世界观,这还不算残酷,毕竟是克苏鲁世界。
这游戏入门的第一个标准就是要不做人,那些英雄并不是我的伙伴,只是一个个工具人而已,只有高级的建筑和饰品才是我最重要的宝贝。当然,他们也不是什么好东西,有杀人的强盗,有光明神偷十字军,还有盗墓贼等等,除了麻风以外都是无可救药的罪犯。当我要指望他们绝地反击的时候,总是 miss,或者是暴击 0 + 流血,没太大的能力还总是高傲地不愿意下低级本提携后辈。
人类的赞歌
虽然嘴上这么说,但当东征成功的麻风吟诵起诗歌来时,当圣矛刺穿邪恶的后配敌人时,当三四个角色绝望中一个人爆美德逆转了战局时,我不由得感叹——人类的赞歌就是勇气的赞歌。畏惧、自私都不是他们的错,他们以普通的人类之躯,却挺身对抗古神,这一切无不体现了他们的伟大,还有人类的伟大。面对死亡,有人大无畏地说“不洁的邪恶,我要和你同归于尽”,有人英雄般地说“饶了其他人,我已经准备好了”,还有人大喊“人人为我,我为人人”,无不让 ...