- Learn Type:Driven Development
- Yawar Amin Kamon Ayeva
- 200字
- 2021-07-02 14:41:23
Analyzing code for hidden errors
Let's suppose that you have the following JavaScript:
// src/Ch01/Ch01_Demo.js
function makePerson(id, name) { return {id, name}; }
A lot of things can go wrong with the preceding code; they are as follows:
- The caller can pass in nulls or undefined values as arguments
- The caller can pass in unintended types of arguments
- The caller can manipulate the returned person object any way they like, for example, they can add or remove properties
In other words, this code doesn't prevent a number of potential errors. In JavaScript, we have linters, such as ESLint (https://eslint.org/), that check for a lot of possible errors, but you have to remember to find them, enable them, and then work around their limitations. A linter can be helpful in various other ways, such as by pointing out the recommended best practices in a coding style. However, linters in JavaScript are often re-purposed to perform static type checking tasks as well; because they offer so much flexibility and need to be configured (in fact, people usually upload their preferred sets of configuration for different styles of programming), there may be large differences in what exactly gets checked across different codebases.
- Bootstrap Site Blueprints Volume II
- Python數(shù)據(jù)分析入門與實(shí)戰(zhàn)
- Developing Middleware in Java EE 8
- Learning Bayesian Models with R
- Spring Boot+Spring Cloud+Vue+Element項目實(shí)戰(zhàn):手把手教你開發(fā)權(quán)限管理系統(tǒng)
- Python Deep Learning
- Processing互動編程藝術(shù)
- 區(qū)塊鏈:以太坊DApp開發(fā)實(shí)戰(zhàn)
- Building a Recommendation Engine with Scala
- Python數(shù)據(jù)分析從0到1
- 深入理解Elasticsearch(原書第3版)
- Java并發(fā)編程:核心方法與框架
- Python實(shí)戰(zhàn)指南:手把手教你掌握300個精彩案例
- JavaScript程序設(shè)計基礎(chǔ)教程(慕課版)
- MATLAB/Simulink建模與仿真