易读代码的艺术之Code Should Be Easy to Understand

本文探讨了代码易读性对于软件开发的重要性和实现策略,指出易读的代码不仅有助于团队协作,还能提高代码质量,促进更好的架构设计和简化测试过程。通过实例分析,展示了如何在不同优化背景下保持代码的高可读性。
1、Code should be easy to understand. ---- 代码应该易读。
2、Code should be written to minimize the time it would take for someone else to understand it.
    ---- 代码应该被写得使其他人用最少的时间理解它。
3、We've found that these other goals don't interfere much at all. Even in the realm of highly optimized code, there are still ways to make it highly readable as well. And making your code easy to understand often leads to code that is well architected and easy to test.
---- 我们发现使代码易读与其他目标不会相互干扰,即使在需要高度优化代码的领域,也还是有方法使代码有高可读性,而且使代码易于理解也会使代码有良好的架构和易于测试。
Tasks Image gray-scaling is one of the most common image processing tasks. A simplest way to gray-scale an image is to set each pixel to the mean of the RGB channels. Gray = (R +G + B)/3 Figure 1: Grayscaling example. 1 Serial Version (45 points) PBM, PGM, and PPM files are all image file formats that hold data in regards to pixels of an image. Compared to formats like PNG, JPG, etc, these formats are very simplistic, offering no compression. These are simple formats that store the colours of pixels as bytes which can be read into your program. Thebelowimage.ppmisgivenasanexample, more detail ppm specifications can be found at https://netpbm. sourceforge.net/doc/ppm.html 50 (0 + 50 + 100) / 3 = 50 100 0 image.ppm 50 50 50 P3 3 2 255 255 0 0 0255 0 0 0255 255 255 0 255 255 255 0 0 0 P3- Magic Number (Tells the program this is a PPM file) 3- Width 2- Height 255- Colour Range (0 = Black, This Number = White) Write a C program to read the given im.ppm image (you can find it on LMO along with this document), convert RGBto grayscale, then output the grayscale image to im-gray.ppm. 3 Your program should be compiled and executed by: make ./grayscale You code will be evaluated based on the following criteria: • Correctness (15 points): you should use the exact same algorithm provided in section 1. • Performance (15 points): you should optimise your code for maximum performance and minimum memory usage. • Codingquality(10points): youshouldfollowgoodcodingpracticethat the codeshouldbeeasytounderstand and easy to maintain. • Robustness (5 points): the program should be able to handle any cases. 2 Parallel Algorithm Design (45 points) Nowthat you have a complete understanding of the task, do the following: • Identify and analyse the bottlenecks of your serial implementation using necessary profiling tools. (15 points), and • provide a design of a solution to speed up using parallel programming. You do not need to do the actual coding for the parallel implementation, provide the detailed design using 4-step Forster Method with maximum 500 words, (20 points) and • afigure to explain your design, the figure should align with the parallel design steps and should be clear and easy to understand. (10 points). 3 Submission (10 points) Please note that quality of report and correctness of the submission will also be marked (10 points in total, 5 points for the quality and length of the report, 5 points for the correctness of the submission). One of the group members must submit the following files: • grayscale.c C code of the serial implementation . • AMakefile that will compile your code, make sure the output executable names are correct. • Areport.pdf file contains all the source code and the parallel design. You should also include the Cover Page with the student ID of all group members (template can be found on LMO) in the first page of your pdf. You should compress the grayscale.c and Makefile into code.zip, submit the report.pdf and code.zip files separately as follows: |---report.pdf |---code.zip |---grayscale.c |---Makefile
10-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值