在《Programming abstractions in C》p111-p113中,如何将boilerplate代码改写为长尾?

2026-04-12 05:161阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计728个文字,预计阅读时间需要3分钟。

在《Programming abstractions in C》p111-p113中,如何将boilerplate代码改写为长尾?

《C语言编程抽象》学习第47天,p111-p113总结如下:

1.技术总结:模板

. boilerplate /* File: random.h Version: 1.0 Last modified on Fri Jul 22 16:44:36 1994 by eroberts ----------------------------------- */

《Programming Abstractions In C》学习第47天,p111-p113,总结如下:

在《Programming abstractions in C》p111-p113中,如何将boilerplate代码改写为长尾?

一、技术总结 1.boilerplate

/* * File: random.h * Version: 1.0 * Last modified on Fri Jul 22 16:44:36 1994 by eroberts * ----------------------------------------------------- * This interface provides several functions for generating * pseudo-random numbers. */ #ifndef _random_h #define _random_h #include "genlib.h" #include <stdlib.h> /* * Constant: RAND_MAX * ------------------ * Unfortunately, several libraries that supposedly conform to * the ANSI standard do not define RAND_MAX in <stdlib.h>. To * reduce portability problems, this interface defines RAND_MAX * to be the largest positive integer if it is undefined. */ #ifndef RAND_MAX # define RAND_MAX ((int) ((unsigned) ~0 >> 1)) #endif /* * Function: Randomize * Usage: Randomize(); * ------------------- * This function sets the random seed so that the random sequence * is unpredictable. During the debugging phase, it is best not * to call this function, so that program behavior is repeatable. */ void Randomize(void); /* * Function: RandomInteger * Usage: n = RandomInteger(low, high); * ------------------------------------ * This function returns a random integer in the range low to high, * inclusive. */ int RandomInteger(int low, int high); /* * Function: RandomReal * Usage: d = RandomReal(low, high); * --------------------------------- * This function returns a random real number in the half-open * interval [low .. high), meaning that the result is always * greater than or equal to low but strictly less than high. */ double RandomReal(double low, double high); /* * Function: RandomChance * Usage: if (RandomChance(p)) . . . * --------------------------------- * The RandomChance function returns TRUE with the probability * indicated by p, which should be a floating-point number between * 0 (meaning never) and 1 (meaning always). For example, calling * RandomChance(.30) returns TRUE 30 percent of the time. */ bool RandomChance(double p); #endif

p113,These three lines are often referred to as interface boilerplate。boilerplate这个词会在计算机相关的教材中会经常看到,英文的意思是:“text that can be copied and used in computer program,with only small changes.”(模板),之所以叫模板,是因为在每个头文件中都有这三句。这个单词不难理解,关键是通过此次的教材对这个单词有一个具体的、形象的记录,当提到这个单词,就知道具体指的是什么。

二、英语总结

1.roll a die一句里面的die是什么意思? 答:die: n.a small cube with a different number of spots on each side.(骰子),所以roll a die的就是"掷骰子"。

2.along with语法

答:along with在表示伴随、以及或连同等意思时,两者之间无先后顺序,可能在前也可能在后。这点与follow不同。示例:For each of these functions, the interface contains one-line prototype along with a comment that describe the purpose of the function from the perspective of clients.

3.up to 语法 答:原文:The line:

#ifndef _random_h

cause the compiler to skip any text up to the #endif line if the the symbol _random_h has been previously defined。

up to短语主要有两种用法:

(1)adv. used to say that sth is less than or equal to but not more than a stated value。

(2)adv. until。

都表示的是“程度”,而不是“方向”。

三、参考资料

1.编程

1)Eric S.Roberts,《Programming Abstractions in C》:book.douban.com/subject/2003414

2.英语

1)Etymology Dictionary:www.etymonline.com

2)Cambridage Dictionary:dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)

本文共计728个文字,预计阅读时间需要3分钟。

在《Programming abstractions in C》p111-p113中,如何将boilerplate代码改写为长尾?

《C语言编程抽象》学习第47天,p111-p113总结如下:

1.技术总结:模板

. boilerplate /* File: random.h Version: 1.0 Last modified on Fri Jul 22 16:44:36 1994 by eroberts ----------------------------------- */

《Programming Abstractions In C》学习第47天,p111-p113,总结如下:

在《Programming abstractions in C》p111-p113中,如何将boilerplate代码改写为长尾?

一、技术总结 1.boilerplate

/* * File: random.h * Version: 1.0 * Last modified on Fri Jul 22 16:44:36 1994 by eroberts * ----------------------------------------------------- * This interface provides several functions for generating * pseudo-random numbers. */ #ifndef _random_h #define _random_h #include "genlib.h" #include <stdlib.h> /* * Constant: RAND_MAX * ------------------ * Unfortunately, several libraries that supposedly conform to * the ANSI standard do not define RAND_MAX in <stdlib.h>. To * reduce portability problems, this interface defines RAND_MAX * to be the largest positive integer if it is undefined. */ #ifndef RAND_MAX # define RAND_MAX ((int) ((unsigned) ~0 >> 1)) #endif /* * Function: Randomize * Usage: Randomize(); * ------------------- * This function sets the random seed so that the random sequence * is unpredictable. During the debugging phase, it is best not * to call this function, so that program behavior is repeatable. */ void Randomize(void); /* * Function: RandomInteger * Usage: n = RandomInteger(low, high); * ------------------------------------ * This function returns a random integer in the range low to high, * inclusive. */ int RandomInteger(int low, int high); /* * Function: RandomReal * Usage: d = RandomReal(low, high); * --------------------------------- * This function returns a random real number in the half-open * interval [low .. high), meaning that the result is always * greater than or equal to low but strictly less than high. */ double RandomReal(double low, double high); /* * Function: RandomChance * Usage: if (RandomChance(p)) . . . * --------------------------------- * The RandomChance function returns TRUE with the probability * indicated by p, which should be a floating-point number between * 0 (meaning never) and 1 (meaning always). For example, calling * RandomChance(.30) returns TRUE 30 percent of the time. */ bool RandomChance(double p); #endif

p113,These three lines are often referred to as interface boilerplate。boilerplate这个词会在计算机相关的教材中会经常看到,英文的意思是:“text that can be copied and used in computer program,with only small changes.”(模板),之所以叫模板,是因为在每个头文件中都有这三句。这个单词不难理解,关键是通过此次的教材对这个单词有一个具体的、形象的记录,当提到这个单词,就知道具体指的是什么。

二、英语总结

1.roll a die一句里面的die是什么意思? 答:die: n.a small cube with a different number of spots on each side.(骰子),所以roll a die的就是"掷骰子"。

2.along with语法

答:along with在表示伴随、以及或连同等意思时,两者之间无先后顺序,可能在前也可能在后。这点与follow不同。示例:For each of these functions, the interface contains one-line prototype along with a comment that describe the purpose of the function from the perspective of clients.

3.up to 语法 答:原文:The line:

#ifndef _random_h

cause the compiler to skip any text up to the #endif line if the the symbol _random_h has been previously defined。

up to短语主要有两种用法:

(1)adv. used to say that sth is less than or equal to but not more than a stated value。

(2)adv. until。

都表示的是“程度”,而不是“方向”。

三、参考资料

1.编程

1)Eric S.Roberts,《Programming Abstractions in C》:book.douban.com/subject/2003414

2.英语

1)Etymology Dictionary:www.etymonline.com

2)Cambridage Dictionary:dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)