• 开源镜像
  • 开源沙龙
  • 媛宝
  • 猿帅
  • 注册
  • 登录
  • 息壤开源生活方式平台
  • 加入我们

开源日报

  • 开源日报第638期:《植物大战僵尸 PythonPlantsVsZombies》

    13 12 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《植物大战僵尸 PythonPlantsVsZombies》
    今日推荐英文原文:《The Mid-Life Crisis of Every Developer》

    今日推荐开源项目:《植物大战僵尸 PythonPlantsVsZombies》传送门:GitHub链接
    推荐理由:说到塔防的话就不能不提家喻户晓的植物大战僵尸啊,火力分配,地形利用,射程射角的计算和即刻道具的使用等等要素将这个游戏的可玩性大幅提高。这个项目使用 Python 将这个塔防游戏重新复现了一遍,尽管暂时没有把所有要素都复现出来——目前只实现了部分植物和僵尸以及白天黑夜关卡而已。

    今日推荐英文原文:《The Mid-Life Crisis of Every Developer》作者:Mahdhi Rezvi
    原文链接:https://medium.com/better-programming/the-mid-life-crisis-of-every-developer-b92c3b102d80
    推荐理由:别忘了你要解决的问题可能有一半都不是直接来自于软件

    The Mid-Life Crisis of Every Developer

    No one said being a developer is easy

    As developers, our daily lives are a battle against machines. We do our best to perform efficiently, but at times the problems get ahold of us. Here are the issues every developer will face at least once in their lifetime.

    Understanding How the Program Works

    This is an issue every newbie developer faces. You should always understand that most of the time, it’s never the program’s fault. The program simply follows what it’s commanded to do. This concept is called GIGO (Garbage In, Garbage Out). If you find a library or a code snippet not performing its job, it’s most likely because the programmer wrote it that way. To get a better idea of GIGO, please watch the video(https://youtu.be/cDA3_5982h8).

    Debugging

    Imagine a scenario where you come home and receive an email from Quality Assurance with a list of bugs to work through. Trust me, that email will ruin your day. But the good news is that bugs are common in programming. In fact, even the best-written code can have them. And they can be fixed.

    In order to solve this problem, you should
    • Reproduce the error — The best way for you to fix a bug is to find its root cause and fix it.
    • Get help — If you can’t reproduce it, get help. The tester who found the bug may be able to reproduce it for you.

    Communication

    Every developer eventually becomes a part of a team. Poor communication is one of the major issues a developer will face in their lifetime. At its worst, it can cause conflicts within the team and the workplace. The blame for poor communication falls on you because it’s in your power to control. If you don’t try to build good communications with your team, you are ultimately responsible for the problem.

    The only way to solve this problem is to improve your communication skills.
    • Be proactive — Communicating only when you need something is not going to help you at all. You should be able to mingle with your colleagues and not be scared to ask them questions, especially about any workplace-related issues. You can get accustomed to the workplace culture faster if you open up to other people. And if you are a shy person, well, your lack of self-confidence is something that you will have to work on.
    • Be confident and consistent — There will be times where you are not clear in what you want to say, and this can cause problems. Don’t feel bad at times like that. Accept your mistake and learn from it. Work until you are able to freely express yourself.

    Time Management

    “Time is the most valuable thing a man can spend.” — Theophrastus

    Photo by Icons8 Team on Unsplash

    Time management is a crucial skill in every job role. You always have 24 hours per day — not more, not less. It’s up to you to utilize them to the fullest. As a developer, there will be times where you will not be able to keep up to your time estimation for a task.

    Estimates are important in software development. They can be a basis for price quotes and project schedules. Schedule delays cause problems and may compromise trust.

    As a new programmer, you might be tempted to put in more time than you need for a task, with the assumption that doing so might impress your boss and be good for the project. But doing this can come back to bite you. It can put you way behind schedule and behind your team, which makes you look bad.

    To stay ahead of your time estimations,
    • Break down tasks — The best way to make tasks more manageable is to break them down into smaller microtasks. Breaking down your heavy workload will keep things from overwhelming.
    • Time yourself accordingly — If a task takes around 20 minutes, give it around 30 minutes, with some additional time for any disturbances that might occur.

    Conclusion

    Whenever you face a problem, always keep in mind that you are heading in the correct path. Think of your life as a game. The better you play, the harder the level will be. The challenges you face are not insurmountable. Keep these tips in mind and take comfort in the fact that you aren’t the only one; your colleagues have faced these problems at some point, too.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第637期:《渲染库pixijs》

    12 12 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《渲染库pixijs》
    今日推荐英文原文:《Why do we contribute to open source software?》

    今日推荐开源项目:《渲染库pixijs》传送门:GitHub链接
    推荐理由:Pixi 是一个超快的2D渲染引擎,具有强大的图片渲染能力和场景图技术。它会帮助你用 JavaScript 或者其他 HTML5 技术来显示媒体,创建动画或管理交互式图像,从而制作一个游戏或应用。最重要的的是,Pixi 没有妨碍你的编程方式,你可以自己选择使用多少它的功能,可以遵循你自己的编码风格,或让 Pixi 与其他有用的框架无缝集成。

    Pixi的API比老旧的Adobe Flash API更精致,并且它是通用的:它不是一个游戏引擎,它给了你所有的自由去做任何你想做的事,甚至用它可以写成你自己的游戏引擎。


    今日推荐英文原文:《Why do we contribute to open source software?》作者:Gordon Haff
    原文链接:
    推荐理由:程序员们为什么要加入各种开源项目并且为此投入时间、精力甚至是金钱呢?我想每一个参与者都有自己的理由。组织作为一个整体为开源软件项目做出贡献有多种原因,包括我们也是如此啊,知道自己为什么要去做,才能做得更好。

    Why do we contribute to open source software?

    Dive into the research supporting the open source ecosystem and developers’ motivations for participating.

    (Image credits : TeroVesalainen via Pixabay CC0)

    What motivates you to contribute to open source?

    Organizations as a whole contribute to open source software projects for a variety of reasons.

    (Screenshot from original)

    One of the most important is that the open source development model is such an effective way to collaborate with other companies on projects of mutual interest. But they also want to better understand the technologies they use. They also want to influence direction.

    The specific rationale will vary by organization but it usually boils down to the simple fact that working in open source benefits their business.

    But why do individuals contribute to open source? They mostly see some kind of personal benefit too, but what specifically motivates them?

    The types of motivation

    When we talk about motivations, one common way to do so is in terms of incentive theory. This theory began to emerge during the 1940s and 1950s, building on the earlier drive-reduction theories established by psychologists such as Clark Hull and Kenneth Spence. Incentive theory was originally based on the idea that motivation is largely fueled by the prospect of an external reward or incentive.

    Money is a classic extrinsic motivator. So is winning an award, getting a grade, or obtaining a certification that is likely to lead to a better job.

    However, in the 1970s, researchers began to also consider intrinsic motivations, which do not require an apparent reward other than the activity itself. Self-determination theory, developed by Edward Deci and Richard Ryan, would later evolve from studies comparing intrinsic and extrinsic motives, and from a growing understanding of the dominant role intrinsic motivations can play in behavior.

    While intrinsic motivations can come from a number of different sources, the most straightforward one is the simple enjoyment of a particular activity. You play in a softball league after work because you like playing softball. You enjoy the exercise, the camaraderie, the game itself.

    Researchers have also proposed a further distinction between this enjoyment-based intrinsic motivation and obligation/community-based intrinsic motivation, which is more about adherence to social or community norms. Maybe you don’t really like having the relatives over for Thanksgiving but you do it anyway because you know you should.

    Today’s psychology literature also includes the idea of internalized extrinsic motivations. These are extrinsic motivations such as gaining skills to enhance career opportunities—but they’ve been internalized so that the motivation comes from within rather than the desire for whatever carrot is being dangled by someone else.

    What motivates open source developers?

    In 2012, four researchers at ETH Zurich surveyed the prior ten years of study into open source software contribution. Among their results, they were able to group study findings into the following three categories: extrinsic motivation, intrinsic motivation, and internalized extrinsic motivation—as well as some common sub-groupings within those broader categories.

    No surprise that money showed up as an extrinsic motivator. During the period studied, there were fewer large projects associated with successful commercially-supported products than is the case today. Even so, most of the open source projects the researchers examined had a significant number of contributors whose companies had paid them to work on open source.

    Career obviously goes hand in hand with pay, but is open source software any different from proprietary software development in this regard? There’s some evidence that it is.

    Lerner and Tirole first suggested in 2002 that “individual developers would be motivated by career concerns when developing open source software. By publishing software that was free for all to inspect, they could signal their talent to potential employers and thus increase their value in the labor market.”

    More recently, there’s been significant empirical evidence that there are career advantages to developing code and making it available for others to see and work with. It has become almost an expectation in some industry segments for job applicants to have public GitHub code repositories, which are effectively part of their resume.

    It’s reasonable to ask whether this trend has gone too far. After all, many highly qualified developers work on proprietary code. But it’s clear that, fair or not, at least some career prospects can come specifically from being an open source developer.

    Among intrinsic motivators, ideology and altruism often seem closely related.

    Free software was primarily an ideological statement at first, even if user control also had an important practical side; several researchers have found support for ideological motives in developer surveys.

    Altruism can also be a developer motive, though research on this is mixed. One paper identified the “desire to give a present to the programmer community” as a crucial pattern in open source software. But other studies have qualified the importance of altruism as a motive, especially among programmers getting a paycheck. Other work found that altruism could be a motivator but only among developers who were otherwise satisfied.

    There’s also the motivational power of fun and enjoyment, a classic intrinsic motivator. This should come as no surprise to anyone who hangs around open source developers. Almost all of them like working on open source projects. One large 2007 study determined that fun accounted for 28 percent of the effort (in terms of number of hours) dedicated to projects. One implication of this research is that activities developers typically enjoy less–tech support often tops this list–may require alternative forms of motivation.

    Much of the research into reputation as an internalized extrinsic motivator has focused specifically on peer recognition. Your reputation among your peers can be a source of your own pride, but it also signals your talent to community insiders and potential employers. The suggestion that reputation could be an important motivator in contributing to open source goes back at least as far as 1998, in Eric Raymond’s essay “Homesteading the Noosphere.” However, since then, a variety of surveys have supported the idea that peer reputation is a driver for participation.

    Another motivator in this category is what researchers call “own-use value” but is more recognizably described as something like “scratch your own itch”–develop something that you want for yourself and in the process, create something valuable to others. The initial motivation essentially comes from a selfish need but that can evolve into more of an internalized desire to contribute.

    It’s unsurprising research would identify own-use value as a good motivator. Certainly, the folk wisdom is that many developers get into open source by developing something they themselves need—such as when Linus Torvalds wrote Git because Linux needed an appropriate distributed version control system.

    As we’ve seen, contributors to open source software have a variety of different motivations but there are a few general threads worth highlighting in closing.

    Motivators can actually be counterproductive when a single motivator is relied upon too heavily. One study reported that developers scratching their own itch worked “eclectically,” fixing bugs that annoyed them and then quitting until the next time.

    In particular, don’t expect non-extrinsic motivators to carry too much of the load. Fun isn’t a good motivator if the task is not actually fun. Altruism motivates some but it also doesn’t pay their bills.

    That said, developers do contribute for reasons that aren’t purely about money or other extrinsic reasons. Learning, peer reputation, and recognition are important to many (and not just in open source development.) Organizations should not neglect the role these can play in motivating developers and should implement incentive programs around them, such as peer reward systems.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第636期:《 用Python实现所有的算法:All Algorithms implemented in Python 》

    11 12 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《 用Python实现所有的算法:All Algorithms implemented in Python 》
    今日推荐英文原文:《 The current state of blockchain and where it’s going 》

    今日推荐开源项目:《 用Python实现所有的算法:All Algorithms implemented in Python 》传送门:GitHub链接
    推荐理由:Python在设计上坚持了清晰划一的风格,这使得Python成为一门易读、易维护,并且被大量用户所欢迎的、用途广泛的语言。而算法又是软件实现其功能中关键的一环。当算法遇上当今最流行的编程语言又会擦出什么样的火花呢,让我们拭目以待。
    今日推荐英文原文:《 The current state of blockchain and where it’s going 》作者:axel simon
    原文链接:https://opensource.com/article/19/12/blockchain-evolution
    推荐理由:区块链技术是一项具有潜力的新技术,作为互联网人,我们需要时刻关注区块链技术的不断发展。

    The current state of blockchain and where it’s going

    Take a look at the ecosystem and the projects trying to solve some of the limitations of blockchain technology.

    In an earlier post, Blockchain evolution: A quick guide and why open source is at the heart of it, I discussed the first generations of blockchains: the public Bitcoin and cryptocurrency blockchains, followed by the Ethereum blockchain capable of executing programs (“smart contracts”), leading to permissioned versions of code-executing blockchains (e.g., Hyperledger Fabric, Quorum).

    Let’s step back into the blockchain jungle and take a look at the current state of the ecosystem and the projects trying to solve some of the limitations of blockchain technology: speed and throughput, cross-blockchain information and value exchange, governance, and identity and account management.

    Speeding things up

    One of the oft-heard gripes about current blockchain technologies is their limited speed, often measured by the number of transactions per second (TPS) that they can manage. This issue strongly limits their use in systems that need to process massive amounts of events. For instance, it has often been said (correctly) that Bitcoin can’t handle more than seven transactions per second, and Ethereum can’t do much more. Possibly the simplest way of defining the next generation of blockchains is with novel ways to try to solve the scalability problems that current generations of blockchains constantly battle. (Permissionless ones especially. I will return to what separates permissionless and permissioned chains below.)

    The most obvious option—and one of the most fiercely debated one in the Bitcoin community—is “simply” to make the blocks of transactions bigger so that they can handle more transactions per block, and thus per second. Opposing interests in Bitcoin have made this solution very hard to implement (a clear problem with the “governance by code” model I mentioned in my previous article, which I will return to in a future article), but it nonetheless remains a relatively straightforward option for blockchain projects in general. Increasing the frequency at which blocks are created is another one.

    I also mentioned another way to handle more transactions per second in the first article: changing the constraints of the problem. Going from a permissionless network—one that anyone can join and participate in—to a permissioned one—where joining requires permission—changes the constraints and offers the option of reconsidering the security requirements. When you know everyone in a consortium—and have legal ties to them—you can choose to use consensus mechanisms, which don’t assume everything should be verified at all times and thus speed things up. Furthermore, permissioned blockchain frameworks, such as Hyperledger Fabric, will typically offer the option to choose the number of transactions contained in a block and their frequency. Whether it’s the number of transactions per block or the number of blocks generated that increases, the end result will be an increase in TPS.

    This is how permissioned systems can reach tens of thousands of TPS, numbers far beyond the major permissionless networks. It is also unsurprising, then, that Facebook’s recently announced Libra cryptocurrency plans to use a permissioned model (although its “blockchainness” is debated) to handle a high number of transactions, in line with its stated goals.

    Holding out for consensus

    However, private, permissioned ledgers will not be suited to all use cases. There need to be improvements in general to permissionless networks’ capacity to manage more events at a time. This leads us to where the most ambitious work might be happening: consensus mechanisms.

    Getting all participants to come to a consensus on the “truth” of all the transactions (i.e., the changes) that happen on the network and on their order is one of the great difficulties of distributed systems. As a type of distributed system, blockchains inevitably contend with it, too.

    Bitcoin’s solution is to organize a race every 10 minutes to solve a computational puzzle and let the winner settle what transactions happened in the last time period and in which order, which everyone else can then easily verify and agree on. By virtue of the kind of puzzle used, the winner is essentially random, but the problem with this “Nakamoto-style proof of work” is that the puzzles used in this race also require horrendously high computational resources to solve (by design), and the work of everyone but the winner is thrown away after each round.

    While it is secure, proof of work is also energy-consuming and slow. What we need are better consensus mechanisms that will allow participants of blockchain networks to come to agreement more efficiently, making it possible for the whole system to process more events per second.

    Ethereum, notably, is working on numerous innovations to solve these limitations. First of all, it plans to let go of proof of work to move to a proof of stake consensus mechanism, often referred to as the Casper protocol. It uses economic incentives and disincentives to get the nodes to secure the network and make cheating (very) costly.

    Another problem a blockchain that can execute smart contracts must contend with is how the execution of code is guaranteed to be correct and what impact this has on the processing capacity of the overall network. Currently, Ethereum requires each validating node to execute the code to verify that the results offered by other nodes are correct. This poses scalability issues, as the greater the success of the Ethereum “world computer,” the more code validators need to check: all the nodes need to agree on the order and the validity of each line of code executed and will inevitably be held back by the slowest node.

    One of the options to alleviate this issue is sharding, a solution where only part of the network executes the code and returns results the rest of the network can verify.

    Pushing this idea further, ZEXE, a project by the team behind Zcash, deals with this situation by making it possible to submit the result of the execution of code along with a cryptographic proof that the result is correct. Other nodes can then take this proof and check it very quickly without redoing the computation. This, combined with bounties for proving results wrong, creates a system where code can be executed by a single node and checked by many, and it makes for a clever way of speeding up the execution of distributed applications (dapps).

    Consensus in distributed systems is not exactly a new research field, but as blockchains have become popular, there has been renewed interest in consensus research. I could mention many more (Tendermint, Ouroboros, and Algorand come to mind), but I’ll offer one other interesting approach regarding consensus: consensus agility. For instance, Hyperledger Sawtooth can change consensus on the fly, “putting all blockchain configuration on the chain itself.” This makes it possible to start a network using a given consensus mechanism and switch to a different, more adapted one when the network and its users have changed, say going from a small-scale deployment to a large consortium.

    This is starting to shed light on an important aspect of the evolution of blockchains: modularity. While the first projects were very tightly integrated, over time, efforts have been made to separate the different layers: networking, consensus, application, and even information storage.

    Layer 2 solutions: Generation 2.5?

    Solutions baked directly into the blockchain—such as the ones above—are considered to be layer 1. Solutions built on top of a blockchain are called layer 2 solutions.

    These layer 2 solutions, such as the Lightning Network for Bitcoin or Raiden for Ethereum, are designed to speed up the overall system by offloading transactions to a secondary network. It’s designed to achieve much higher throughput while still connecting to the main blockchain and maintaining its important characteristics: distributed, permissionless, and trust-minimizing. While similar to some degree to sidechains (connecting another system to the main chain, an idea I will return to in the next article), they don’t use the idea of a secondary chain. Instead, they build overlay networks that rely on the underlying chain for security and accountability but can exchange information much, much faster and in a peer-to-peer manner.

    Layer 2 solutions are essentially built for cryptocurrencies and create payment tunnels anchored to the underlying cryptocurrency’s blockchain, where the amounts exchanged between two parties are eventually settled. By taking most transactions off-chain and alleviating how much needs to happen on the main chain and offloading most transactions to the second layer, they help speed up the entire system.

    Conclusion

    Speed is the great limiter on the potential of permissionless blockchains. There is a great deal of work going on to explore solutions to this challenge while maintaining the integrity of the chain. Recent research on consensus is leading to new approaches which offer less environmentally unfriendly guarantees on accuracy.

    Open source software is constantly evolving, and as an open source ecosystem, blockchains are a prime example of this reality: Many projects are experimenting with various solutions to shared problems, and these solutions are being studied, refined, and improved by the rest of the community.

    The next installment of this series will examine how current generations of blockchain technologies are trying not just to make individual blockchains more efficient but also capable of working together.


    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
  • 开源日报第635期:《破碎 ParticleEffectsButtons》

    10 12 月, 2019
    开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
    今日推荐开源项目:《破碎 ParticleEffectsButtons》
    今日推荐英文原文:《Want to Be a Good Programmer? Learn How To Write》

    今日推荐开源项目:《破碎 ParticleEffectsButtons》传送门:GitHub链接
    推荐理由:为了把页面弄得华丽到花里胡哨,应对不同场景使用不同动画就显得很有必要。这个项目为按钮的显示和消失加入了相当好看的粒子效果,甚至还为消失的速率提供了不同的曲线,在切换按钮显示状态时就显得相当华丽,而且不仅适用于无框架页面,对于主流的 Vue 等这些框架也有相应的库推出,足够满足各种框架下使用的需求。
    今日推荐英文原文:《Want to Be a Good Programmer? Learn How To Write》作者:Robert Quinlivan
    原文链接:https://medium.com/better-programming/want-to-be-a-good-programmer-learn-how-to-write-a1223fe1395d
    推荐理由:写代码时试着同时为机器和人类而写,忽视任何一方都可能为工作带来麻烦

    Want to Be a Good Programmer? Learn How To Write

    Being able to read and write automatically gives you a leg up in becoming a better programmer

    Whether you have decades of experience with programming languages or you’re just starting to learn, if you’re reading this article, then you already have some experience in another language: the English language.

    I’m going to argue that being able to read and write automatically gives you a leg up in becoming a good programmer.

    Having a solid grasp of communicating via written language teaches you an important skill in programming that has nothing to do with computer science per se and everything to do with expressing ideas.

    We Spend More Time Reading Code Than Writing It

    Code is not written for computers. Please write that down and underline it, and whisper it to yourself before you go to bed each night: Code is not written for computers.

    Yes, the code you write will eventually (after going through a compiler, a byte code virtual machine, an interpreter, or all of the above) turn into instructions that a computer executes.

    But that’s not the only reader the code has.

    When a computer reads your program, it pulls a model of your code into its memory and CPU registers.

    When a human being reads your code, they construct a model in their mind from the structure of your code.

    Someone who has never seen your system and knows nothing about it will often skip the documentation and go straight to the code. That’s because code is still the best abstraction we have for describing how software works.

    Think of a program as simultaneously two things:
    • A valid set of instructions for a computer to accomplish a task.
    • A structured essay for your code’s future maintainers on the topic of how this system works.

    A Major Cost in Software Is Maintenance Cost

    Programs are not static things. They are malleable. They are soft. They change with new product requirements, new technology, to implement improvements, and, of course, to fix bugs.

    We rarely get to write detailed blueprints of our programs before we design them. On the contrary, in software engineering, the design is very often a result of development rather than the other way around.

    And this design process never really ends. Long after the initial development of software, we will still be making changes. Ninety-nine percent of the time, the code we write will be modified in some way in the future. We call this the maintenance of a software system.

    Your system could be a complex production system with hundreds of developers contributing dozens of commits a day via source control. Or it may just be a script that we wrote for our own use that we have to change years later.

    In either case, there is some modification process that will take place, some of it predictable, and some of it not. The ease with which you or your team can implement changes is the maintenance cost of the system.

    And it is often a major cost. Clunky old systems written decades earlier can seriously derail a project if changes in that old system require a large investment of developer time. Dependencies on complex, poorly maintained legacy systems can force us to reimplement data models and commit to expensive rewrites, just to get around thorny code.

    Maintenance cost, in short, is a problem.

    Programming Like a Writer

    I know what you’re thinking. Isn’t this why we have documentation? We write docs for classes. We have inline documentation UIs like Javadoc and Sphinx. Sometimes we even have a dedicated department of people who specialize in technical documentation. Doesn’t that make our code more maintainable?

    Yes, it helps. But it’s a drop in the bucket.

    Structuring code in an intelligible and readable way goes way beyond documentation. Documenting every class and function in your project doesn’t automatically imbue your code with intelligibility.

    If you write a program with zero consideration for design patterns and slap some comments on your classes, you haven’t written readable code.

    But I’m not going to give you a list of design patterns to follow. You can look those up for your language of choice.

    Instead, I want you to think about what makes a piece of writing in English readable. Good writing tends to have these qualities:
    1. It doesn’t use difficult dictionary words. It uses a simpler word whenever given the choice.
    2. It is geared toward its reader. A technical document aimed at a general audience will take care to define jargon or avoid it altogether. A horror novel will follow the conventions of that genre to satisfy fans.
    3. It says a lot in as few words as possible.
    4. It stays on topic. If it starts to wander off into another, related topic, it might make a reference to another chapter or a footnote where that topic is covered in proper detail. It doesn’t just prattle on in run-on sentences.
    5. It is expressive. Its structure suggests the broader meaning of the piece. It has a broader point.
    All of these rules have the same goal in mind: for the reader to understand the subject matter. Good writing gets out of the way and lets the reader focus on what is being communicated.

    By analogy, we can say the same thing about a well-written program:
    1. It doesn’t use special or unknown library functions and API calls that the average programmer is not familiar with when there is a simpler alternative.
    2. It avoids patterns that the maintainers of the project won’t be familiar with or will find overly challenging. (For example, trying to port C++ patterns into Java.)
    3. It is terse and to the point. No fancy syntax or tricks.
    4. Through the use of modularity and abstraction, it keeps modules small and focused on doing one thing and one thing only. It follows the UNIX design philosophy of small, composable pieces.
    5. It is expressive. Its patterns suggest the actual purpose of the system, and its structure is predictable. Once you learn how the program is structured, you also have learned how the system works.

    What Does ‘Readable’ Mean?

    The concept of readability is often brought up when talking about how expressive or intelligible our code is. What do we mean by readable?

    For me, readability implies that:
    • A person of average experience can pick up the project and figure out how it works just by reading the code.
    • I myself can explain the structure of modules in my code and what each component’s purpose is in the broader program. I like to do this in the form of data flow through the system. (E.g., a call starts over here, hits this class, then it ends up over here.)
    • The structure of the code suggests where and how a given change would be made.
    Readability is all about lowering the barrier to entry for working on the code. The easier it is to read, the easier it is to make changes. That addresses our problem with maintenance cost.

    Why Do We Ignore Readability?

    We have a tendency to be overly focused on the basic functionality of our code. Churning through difficult algorithm questions has become a staple of the interview process, and résumés emphasize more algorithmic or data-oriented project work.

    Certainly, our code needs to function, and algorithmic problems are challenging to solve. But just making code work is hardly good enough. It is a bare minimum requirement. Code also needs to be readable.

    The cost of maintaining a complex system is often brushed aside as an annoying reality that we would prefer to forget about. But we do so at our peril. Unreadable code leads to rusty holes in our system which can, over time, slow the whole machine to a grinding halt. We need to be careful to patch up those holes but also design our own code to avoid leaks.

    It also follows that we should place more emphasis on the skill of reading code and improving its quality by rewriting sections of it. An interesting interview question might be to provide a working program and ask a candidate to refactor it, step by step, to improve its readability.

    Readability Comes From Revision

    To iron out all the problems in this article, I spent time trimming and restructuring it. I also had a copy editor look over it before it went to press.

    We should do the same with our code. When you program, make sure you are doing your own personal due diligence to find the correct design patterns for the problem you’re solving. Make sure that you have a rigorous code review process to not only catch defects, but also identify readability improvements we can make in working code.

    Conclusion

    There is a lot of overlap in the skills of reading and writing in English, and reading and writing in code.

    Learning how to read and write effectively allows us to communicate our ideas broadly by choosing the best phrasing and structure for our words, given our audience’s needs.

    That skill of expression translates well to the art of programming, and it’s something that all programmers should take care to cultivate.

    The daily work of a programmer isn’t all about number-crunching and algorithmic analysis. It’s largely about solving a problem in a way that allows other programmers to contribute to the code you produce. That means we have to take care to produce code that is easy to understand and cheap to maintain.

    And maintainable code, my friends, is readable code.
    下载开源日报APP:https://opensourcedaily.org/2579/
    加入我们:https://opensourcedaily.org/about/join/
    关注我们:https://opensourcedaily.org/about/love/
←上一页
1 … 99 100 101 102 103 … 262
下一页→

Proudly powered by WordPress