我怎样学习编写高效和维护的C code? [英] How do I learn to write efficient and maintainable C code?

查看:117
本文介绍了我怎样学习编写高效和维护的C code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与编程电流的经验是有限的黑客一些shell脚本和一些装配过去在一起。但是,我学会了C code的基本语法上大学。

My current experience with programming is limited to hacking together some shell scripts and some assembly in the past. However, I learned the basic syntax of C code in college.

我想学习如何编写高效的C code,我的困惑是否开始与K&安培; R或C语言程序设计:现代观点。我也应该学习一些算法的书籍旁边,这样我最终不会从一开始就写低效code吧?

I want to learn how to write efficient C code, I an confused whether to start with K&R or C Programming: A Modern Approach. Also should I study some algorithm books alongside so that I don't end up writing inefficient code right from the beginning?

推荐答案

不要太担心的有效的code在这个阶段。关注自己更具有清晰可读code。

Don't worry too much about efficient code at this stage. Concern yourself more with clear and readable code.

作为一项规则,保持功能小,执行一个任务。如果花费太多的句子来形容函数做什么,它可能需要分解成更小的功能。

As a rule, keep functions small, performing one task. If it takes too many sentences to describe what one function does, it probably needs breaking down into smaller functions.

使用描述性的变量名,而不仅仅是X和n等。

Use descriptive variable names, rather than just x and n etc.

写你会喜欢开发,而不是节目开始无聊的练习,这本书告诉你这样做。然而,这样做遵循本书的建议和指导方针。

Start by writing programs you will enjoy developing, rather than "boring exercises that the book tells you to do." However, do follow the book's advice and guidelines.

每个人都有自己的风格,不要担心,如果你的风格不完全匹配下一个人的。

Everybody has their own style, don't worry if your style doesn't quite match the next person's.

首先,尽情享受吧!如果你发现学习的一件事有点无聊,转移到别的东西,总有加载学习。

Above all, enjoy it! If you find learning one thing a bit boring, move on to something else, there's always loads to learn.

编辑:另外,不要尝试运行你能走之前 - 我想特别一)指针和b)动态内存分配。有没有必要,直到你舒适的使用其中任何一个在这个早期阶段。

Additionally, don't try to run before you can walk - I'm specifically thinking a) pointers and b) dynamic memory allocation. There's no need to use either of them at this early stage until you're comfortable.

这篇关于我怎样学习编写高效和维护的C code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆