> 2021年09月02日信息消化 > > 原发布地址:[Digest | 产品构建模式, clean code规则吗, 7个开发者工具, 海森堡不确定性原理](https://whatcode.cc/blog/type/5/id/161) ### The batch *Ready, Aim, Fire* vs *Ready, Fire, Aim* Origin: [The Batch September 1, 2021](https://info.deeplearning.ai/the-batch-teslas-dancing-robot-adapting-to-climate-change-asking-language-models-nicely-machine-unlearning-1?) Building AI products and businesses requires making tough choices about what to build and how to go about it. I’ve heard of two styles: - Ready, Aim, Fire: Plan carefully and carry out due diligence. Commit and execute only when you have a high degree of confidence in a direction. - Ready, Fire, Aim: Jump into development and start executing. This allows you to discover problems quickly and pivot along the way if necessary. 构建人工智能产品和业务需要对构建什么以及如何去做做出艰难的选择。我听说有两种风格。 - 准备、瞄准、发射。仔细计划并进行尽职调查。只有当你对某个方向有高度的信心时,才承诺并执行。 - 准备好,发射,瞄准:跳入开发并开始执行。这使你能够迅速发现问题,并在必要时沿途进行调整。 Say you’ve built a customer-service chatbot for retailers, and you think it could help restaurants, too. Should you take time to study the restaurant market before starting development, moving slowly but cutting the risk of wasting time and resources? Or jump in right away, moving quickly and accepting a higher risk of pivoting or failing? 假设你已经为零售商建立了一个客户服务聊天机器人,你认为它也可以帮助餐馆。你是否应该在开始开发之前花时间研究餐厅市场,缓慢前进但减少浪费时间和资源的风险?还是立即投入,快速行动,接受更高的转机或失败的风险? Both approaches have their advocates, but I think the best choice depends on the situation. Ready, Aim, Fire tends to be superior when the cost of execution is high and a study can shed light on how useful or valuable a project could be. For example, if your team can brainstorm a few other use cases (restaurants, airlines, telcos, and so on) and evaluate these cases to identify the most promising one, it may be worth taking the extra time before committing to a direction. 这两种方法都有其拥护者,但我认为最好的选择取决于实际情况。 当执行的成本很高,并且研究可以阐明一个项目的有用性或价值时,"准备、瞄准、发射 "往往更有优势。例如,如果你的团队能够集思广益,提出一些其他的用例(餐馆、航空公司、电信公司等等),并对这些用例进行评估,以确定最有希望的一个用例,那么在承诺一个方向之前,可能值得花额外的时间。 Ready, Fire, Aim tends to be better if you can execute at low cost and, in doing so, determine whether the direction is feasible and discover tweaks that will make it work. For example, if you can build a prototype quickly to figure out if users want the product, and if canceling or pivoting after a small amount of work is acceptable, then it makes sense to consider jumping in quickly. (When taking a shot is inexpensive, it also makes sense to take many shots. In this case, the process is actually Ready, Fire, Aim, Fire, Aim, Fire, Aim, Fire.) 如果你能以较低的成本执行,并在执行过程中确定该方向是否可行,并发现能使其发挥作用的调整,那么准备、发射、瞄准往往会更好。例如,如果你能快速建立一个原型,以弄清用户是否需要这个产品,如果在做了少量工作后取消或转向是可以接受的,那么考虑快速跳入就有意义了。(当拍摄的成本很低时,多次拍摄也是有意义的。在这种情况下,这个过程实际上是准备、开火、瞄准、开火、瞄准、开火、瞄准、开火)。) After agreeing upon a product direction, when it comes to building a machine learning model that’s part of the product, I have a bias toward Ready, Fire, Aim. Building models is an [iterative process](https://read.deeplearning.ai/the-batch/iteration-in-ai-development/?utm_campaign=The Batch&utm_source=hs_email&utm_medium=email&_hsenc=p2ANqtz-_cWpVXuBuvnZfTMZehw2GNORZSx1LXGAX3xmIvk9Tx9y0omCweoPpDQkRVP2mLEuii979o). For many applications, the cost of training and conducting error analysis is not prohibitive. Furthermore, it is very difficult to carry out a study that will shed light on the appropriate model, data, and hyperparameters. So it makes sense to build an end-to-end system quickly and revise it until it works well. 在商定了产品方向后,当涉及到建立作为产品一部分的机器学习模型时,我偏向于 "准备、发射、瞄准"。构建模型是一个[迭代过程](https://read.deeplearning.ai/the-batch/iteration-in-ai-development/?utm_campaign=The Batch&utm_source=hs_email&utm_medium=email&_hsenc=p2ANqtz-_cWpVXuBuvnZfTMZehw2GNORZSx1LXGAX3xmIvk9Tx9y0omCweoPpDQkRVP2mLEuii979o) 。对于许多应用来说,训练和进行错误分析的成本并不高。此外,开展一项研究,阐明适当的模型、数据和超参数是非常困难的。因此,快速建立一个端到端的系统,并对其进行修改,直到它运行良好,是有意义的。 But when committing to a direction means making a costly investment or entering a [one-way door](https://www.inc.com/jeff-haden/amazon-founder-jeff-bezos-this-is-how-successful-people-make-such-smart-decisions.html?utm_campaign=The Batch&utm_source=hs_email&utm_medium=email&_hsenc=p2ANqtz-_cWpVXuBuvnZfTMZehw2GNORZSx1LXGAX3xmIvk9Tx9y0omCweoPpDQkRVP2mLEuii979o) (meaning a decision that’s hard to reverse), it’s often worth spending more time in advance to make sure it really is a good idea. 但是,当承诺一个方向意味着进行昂贵的投资或进入一个[单行门](https://www.inc.com/jeff-haden/amazon-founder-jeff-bezos-this-is-how-successful-people-make-such-smart-decisions.html)(意味着一个难以逆转的决定),往往值得提前花更多时间来确保它确实是一个好主意。 ### Learn these 9 rules to start writing clean code immediately origin: [Learn these 9 rules to start writing clean code immediately](https://levelup.gitconnected.com/learn-these-9-rules-to-start-writing-clean-code-immediately-a7ee40fe1e1b) ``` Comment by Jason Warner Based on your feedback, most people miss the point of this article. Calisthenics are practices to work on your skills. These "rules" are not hard and fast, but there are real benefits to learning to think differently about your code. I actually practice quite a few of these and they have changed the readability and quality of my code. I disagree with some of them too, but that won't stop me from spinning up a few test projects to see if there is a benefit to me. I appreciate you taking the time to share something with the community. ``` **Jeff Bay**, originally coined the term **Object Calisthenics** in **The ThoughtWorks Anthology** book as a group of exercises to Object-Oriented programming. ##### 1. Only one level of indentation per method. This will make a method more readable as you will need to extract out pieces of code for example for loops or conditionals and put a meaningful name to those methods which are going to be called in this method. ![img](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/uPic/1*sgju3IKGVb50qqH-ZV-9zQ.png) ###### Benefits - Single responsibility - Better naming - Shorter methods - Reusable methods ##### 2. Don’t use the else keyword The “else” keyword will add complexity to the code and create non linear flow (adding more use cases) ###### Ways to avoid using the else keyword - Use default values - Early return - Extract code - Use polymorphism - State pattern - Strategy pattern ###### Benefits - Avoid code duplication - Lower complexity - Readability ```text Comment by Emanuel de Souza This is a very bad piece of advice for people that don’t understand what it means. I had long arguments with engineers that said that but instead wrote another if condition with the negation of the original one. It should be rephrased as “decrease code complexity by eliminating excessive logical branches”. The fact you use several else if/else branches is because your code is doing too much and needs to be broken down in order to achieve single responsibility. In cases it is all part of a single workflow there are design patterns that helps achieving that as Command and Chain of Responsibility. 对于那些不理解其含义的人来说,这是一个非常糟糕的建议。我曾经和那些这样说的工程师争论了很久,但他们却用原来的条件的否定来写另一个if条件。它应该被重新表述为 "通过消除过多的逻辑分支来降低代码的复杂性"。你使用了几个else if/else分支,是因为你的代码做得太多了,需要分解,以实现单一的责任。如果这些都是单一工作流程的一部分,有一些设计模式可以帮助实现这一目标,如命令和责任链。 ``` ##### 3. Wrap primitive types By wrapping primitive types into classes we can encapsulate the type and have control from a single place in case we need to refactor or change the primitive type, later on, it also helps to make it more readable by giving a hint of what exactly a method parameter is receiving. ###### Benefits - Encapsulation - Type hinting - Attracts similar behavior ##### 4. One dot per line This applies the Demeter law: *Only talk to your friends* So things like `object.getProperty().getSubProperty().doSomething()` is probably a really bad idea!, you just know too much of the implementation details. ###### Benefits - Encapsulation - Open/Close Principle ##### 5. Do not abbreviate If you are abbreviating the method may be doing more than it should (violating the single responsibility principle), so think again. Ever found a weird abbreviated method name or variable that could mean 5 different things without having the right context?, then don’t be the one making these abbreviations! ###### Benefits - Single Responsibility principle - Avoid confusion - Avoid code duplication ##### 6. Keep classes small - 15–20 lines per method - 50 lines per class - 10 classes per package After all, if your class is specialized in a single thing, it will probably be small right? ###### Benefits - Single Responsibility principle - Smaller modules - Coherent code ##### 7. No more than 2 instance variables per class A single class should handle only one state and two at most, so having more than 2 instance vars might be violating SRP. This might sound like a hard one to do, I’m sure you had seen a class that takes in 18 inputs in the constructor right? Well!, maybe you could group those into an object?, or maybe you might need to re-think if the design of that class is the best one, or if it is just doing too many things. ###### Benefits - High cohesion - Encapsulation - Fewer dependencies ##### 8. First class collections This is similar to rule #3 but applied to collections. Inside your class, you will still define a primitive collection type, but this way you could easily refactor as needed in the future and change the primitive collection type in a single place if needed. 这类似于规则3,但适用于集合。 在你的类里面,你仍然会定义一个原始的集合类型,但是这样你可以在将来根据需要轻松地进行重构,并在需要时在一个地方改变原始的集合类型。 ###### Benefits - Wrap primitive collections - Behavior or related collections have a home - Encapsulation ##### 9. Do not use getters and setters Don’t make decisions outside of the class, let the class do its job, follows the *Tell don’t ask principle* ##### Benefits - Open/close principle ### 7 Amazing Developer Tools That You’re Not Using Yet origin: [7 Amazing Developer Tools That You’re Not Using Yet](https://blog.devgenius.io/7-amazing-developer-tools-that-youre-not-using-yet-79bbbbcf80b) #### 1.Bundlephobia Bundialphobia is a web application that lets you determine how much an **NPM package** will add to your total bundle size. If you’re working with a modern front-end framework, you’ll want to keep the bundle size as small as possible and try to optimize the initial page load for new users. **URL:**[**https://bundlephobia.com/**](https://bundlephobia.com/) ##### 2.Cloudcraft Cloudcraft is a web application that will help you design and budget your cloud infrastructure called Cloudcraft. It is currently only available for AWS, but I use GCP mostly but still find it useful. It provides a very intuitive drag and drop interface that allows you to connect different cloud infrastructure services together. Not only is this great for planning, but it is also great for budgeting once you set up your installation. You can go to the Budget tab, and it will give you an estimated breakdown of your total expenditure. And because all the major clouds have the same price model, the actual results will translate very well to Azure and GCP. **URL:**[**https://www.cloudcraft.co/**](https://www.cloudcraft.co/) ##### 3.Fontflipper This app is built using angular and firebase, and its sole purpose is to help you choose fonts for your designs. There are hundreds if not thousands of free fonts on Google. But it’s really tedious to go through and try to figure out the perfect one for your design. 这个应用程序是用angular和firebase构建的,其唯一目的是帮助你为你的设计选择字体。谷歌上有数百甚至数千种免费字体。但是,翻阅并试图找出适合你的设计的完美字体真的很乏味。 Font flipper allows you to bring in your own graphics and then experiment with different fonts. And what I really like about it is that it’s really focused and simple UI that doesn’t distract you in any way. But the coolest feature is how you actually select the don’t, and it’s done with a tinder-style UI where you swipe left for things you don’t like and right things you do like, and once you decide on a few fonts that you like, you can just go download them directly from google fonts. **URL:**[**https://fontflipper.com/upload**](https://fontflipper.com/upload) ##### 4.Figma ##### 5.Insomnia The power of graph QL combined with insomnia just gives you an awesome overall developer experience. ##### 6.VisBug It’s a tool that allows you to interact visually with your website. All kinds of different stuff we can do here. But basically, we can measure elements we can move things around, change their style. And you can do everything live in the browser without having to write a single line of CSS. This is extremely powerful because you can get things to a state that you actually like, and then instead of rewriting all the CSS, you can just copy and paste it from the inspector. And another thing I really like is that you can search for a specific type of element. For example, if you want to find all the links on the page, we can just search for them. **URL:**[**https://chrome.google.com/webstore/detail/visbug/cdockenadnadldjbbgcallicgledbeoc?hl=en**](https://chrome.google.com/webstore/detail/visbug/cdockenadnadldjbbgcallicgledbeoc?hl=en) ##### 7.Flare This is another design tool but one specifically for creating 2D vector animations. It’s similar to Figma in the sense that you can use it to draw graphics. But you’ll see down here at the bottom we also have keyframes to control the motion of the graphics over time. And flare is part of the open design movement, which means you can see the work of all kinds of other designers directly on the site and learn exactly how they build their animations. And flare is part of the open design movement, which means you can see the work of all kinds of other designs directly on the site and learn exactly how they build their animations. But a big part of the reason I’m really excited about a flare is that these graphics can be exported to work in a flutter. That means that implementing beautiful, high-performance animations in a native mobile app is easier than ever before. **URL:** [**https://flare.rive.app/**](https://flare.rive.app/) ### The Heisenberg Uncertainty Principle is Pure Mathematics origin :[The Heisenberg Uncertainty Principle is Pure Mathematics](https://www.cantorsparadise.com/heisenbergs-uncertainty-principle-is-pure-mathematics-e14c840659e1) Oftentimes I hear people stating that **Heisenberg’s uncertainty principle** is about observers interacting with electrons through photons and thereby affecting the momenta of the photons. 我经常听到有人说,**海森堡的不确定性原理**是关于观察者通过光子与电子相互作用,从而影响光子的动量。 It might be true that an observer has to affect the momentum (or some quantum state) of an electron in order to observe it but that is **not** the reason behind the uncertainty principle! 观察者必须影响电子的动量(或某些量子状态)才能观察到它,这可能是真的,但这并不是不确定性原理背后的原因!这一点是很重要的。 Before jumping headfirst into this topic, let us define Heisenberg’s uncertainty principle so we are all on the same page. 在一头扎进这个话题之前,让我们先定义一下海森堡的不确定性原理,这样我们就能在同一起跑线上了。 > In quantum mechanics, the uncertainty principle (also known as Heisenberg’s uncertainty principle) is any of a variety of mathematical inequalities asserting a fundamental limit to the accuracy with which the values for certain pairs of physical quantities of a particle, such as position and momentum can be predicted from initial conditions. > > 在量子力学中,不确定性原理(也称为海森堡的不确定性原理)是各种数学不等式中的任何一个,它主张对粒子的某些物理量对的精确性有一个基本限制,如位置和动量可以从初始条件预测。 > > — Wikipedia A common way of phrasing this is that at any given point in time, you cannot accurately measure both a particle’s momentum and its position. This uncertainty doesn’t depend on bad equipment or that it might be difficult to do so. No matter how good we get, we can never know both of these values… First of all, there exist multiple uncertainty principles, many of which take effect in our macroscopic world. In fact, you encounter these all the time even if you are not aware of them. Secondly, the underlying cause behind Heisenberg’s uncertainty principle has nothing to do with quantum physics, but rather mathematics. The real reason behind all these equivalent principles is a certain mathematical fact that all waves (conjugate variables) have to obey - including matter (we will get into this a little later). Music, radar technology, energy and light also have “uncertainty principles” that have to be obeyed and as we will see soon, the underlying laws that imply this have nothing to do with physics. 一种常见的表述方式是,在任何给定的时间点上,你无法同时准确测量一个粒子的动量和位置。 这种不确定性并不取决于糟糕的设备或可能难以做到这一点。无论我们做得多好,我们都不可能知道这两个值...... 首先,存在着多种不确定性原理,其中许多在我们的宏观世界中生效。事实上,你无时无刻不在遇到这些,即使你没有意识到它们。 其次,海森堡的不确定性原理背后的根本原因与量子物理学无关,而是与数学有关。 所有这些等效原理背后的真正原因是某个数学事实,所有的波(共轭变量)都必须服从--包括物质(我们稍后会讨论这个问题)。 音乐、雷达技术、能量和光也有必须遵守的 "不确定性原则",正如我们很快会看到的,暗示这一点的基本规律与物理学无关。 ##### Waves In the end, it all comes down to something pretty simple. All types of signals or functions, no matter how complicated, are really superpositions of sine waves. That is pure waves that have a well-defined constant wavelength and amplitude. 最后,这一切都归结为非常简单的事情。所有类型的信号或函数,无论多么复杂,实际上都是正弦波的叠加。那是具有明确定义的恒定波长和振幅的纯正波。 A superposition simply means that all the waves interact and the sum of all the waves (called interference) is then the superposition that makes up the more complicated signal. 叠加只是意味着所有的波相互作用,然后所有的波的总和(称为干涉)就是构成更复杂信号的叠加。 That is, we can break up a function into its simpler constituent components (pure waves) that make it up. This is almost what we do when we calculate Fourier coefficients for Fourier series except that this process is not only true for periodic functions. 也就是说,我们可以把一个函数分解成构成它的更简单的组成成分(纯波)。这几乎就是我们在计算傅里叶级数的傅里叶系数时所做的事情,只不过这个过程不仅仅是对周期性函数而言的。 This effect is well-known from music, where a guitar for example carries overtones along with the sound in the background interfering with the main wave (the frequency of the string that was plucked). Thus the sound from a guitar (and any other musical instrument including your voice) is made up of pure sine waves with different frequencies and amplitudes. 这种效果在音乐中是众所周知的,例如吉他在背景中带着泛音,与主波(被拨动的弦的频率)相互干扰。因此,吉他的声音(和任何其他乐器,包括你的声音)是由不同频率和振幅的纯正弦波组成的。 When we describe such a complicated signal, we can choose between two equivalent ways of representing it. Two different units so to speak. 当我们描述这样一个复杂的信号时,我们可以选择两种相等的方式来表示它。可以说是两个不同的单位。 We could choose to describe how all the waves giving rise to our interference pattern are interacting simultaneously using a time axis or we could choose to describe it by the frequencies of the pure waves that constitute it. 我们可以选择用时间轴来描述产生我们的干涉模式的所有波是如何同时互动的,或者我们可以选择用构成它的纯波的频率来描述它。 The fact that we can describe it in two equivalent ways is called a dual relationship. It would certainly be nice if we had a mathematical tool to describe this dual relationship between the signal in time and the signal in frequencies. And as you might have guessed, we do. ##### The Fourier Transform The tool to describe this dual relationship that I touched upon above, is called **the Fourier transform**. It is, without doubt, one of the most powerful and used tools in all of mathematics. Before giving you some properties, we need to understand something general about such a transform. The Fourier transform is an integral transform (that is an operator) that takes a function and returns another function. As an operator on a function space, we can think of it as a piece of pure mathematics, however, it has a nice physical interpretation that usually goes along with it and it can be used in both contexts. Today, we will think of it mostly in terms of physics. But of course, it is always pure mathematics under the hood. In the following, we will always assume that the integrals converge. Let *f: ℝ → ℂ* be an integrable function. The Fourier transform of *f* is given by the following integral: ![img](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/uPic/1*PABsQYjrMXM0Q6cTCDzcRA.png) If *f* represents say a sound wave as a function of time, then the Fourier transform represents the frequencies that make up this sound wave, and thus *f* is a function of frequency. Below is a GIF showing how a sound wave (a **unit pulse** in this case) is made up of many pure sine waves giving rise to the **sinc function** i.e. sin(πs)/πs. ![img](https://miro.medium.com/max/640/1*ww6y2-OzmWfB5M_igMwuog.gif) It is very important to understand that a signal always have these two equivalent ways of being expressed. They are equivalent because given one of them the other is uniquely determined and we have a formula for calculating it. It is simply a matter of how we want to describe or represent that signal. The unique inverse Fourier transform is given by: ![img](https://miro.medium.com/max/499/1*lB0vyyokvuEbZgUMDmdLyw.png) #### Properties of the Fourier transform The study of this subject is a several course endeavor and we can only hope to scratch the surface in this article. However, we can’t mention the Fourier transform without stating and proving some of its amazing properties. The start of this journey is about translation or shifting. Suppose *h(t) = f(t + a)*. By a change of variable we have: #### Misc - [How to Slow the Decline of Your Eyesight](https://medium.com/predict/how-to-slow-the-decline-of-your-eyesight-97ac815957e) - The science is clear: being outside is good for your eyes. Not getting enough daylight, scientists argue, deprives your eyes of violet light that is critical to their functioning, putting you at higher risk of becoming shortsighted. Spending more time outdoors, even in the presence of cloud covers, helps you sustain better eyesight. - eye ergonomics - **Stay at arm’s length** - Take care of glare: try a matte filter for your screen. - Lighten up: Adjusting your environmental lighting can reduce eye strain. Also, try increasing the contrast on your monitor.