search
HomeDatabaseMysql Tutorial程序员编程的10个实用技巧

程序员编程的10个实用技巧

Jun 07, 2016 pm 03:30 PM
Practical Tipsprogrammerprogramming

不知道各位有没有这样的经历,当你正在给别人描述问题的时候,突然灵机一动想到了解决方案?这种情况的产生是有科学依据的。高谈阔论能让我们的大脑重新有条理地组织问题。在这种情况下,你的聊天对象就是“橡皮鸭”。团队中的每个人都应该积极主动乐意地成

不知道各位有没有这样的经历,当你正在给别人描述问题的时候,突然灵机一动想到了解决方案?这种情况的产生是有科学依据的。高谈阔论能让我们的大脑重新有条理地组织问题。在这种情况下,你的聊天对象就是“橡皮鸭”。团队中的每个人都应该积极主动乐意地成为彼此的“橡皮鸭”。有时候,如果你幸运的话,你的“橡皮鸭”搞不好还能给出有效的建议呢。

2.快速信息反馈

一旦写好代码就要尽快得到反馈。当你和我们在HubSpot一样,收到大量的Pull请求,不妨做些细微的改动,然后立马打开PR,讨论设计和代码。和你的“橡皮鸭”交流一下,请他们提点建议。要知道,迭代原型可远比纠正成品要节约成本。

有的团队结构,最初可能并不要求写代码。因为实体模型、白板设计等等,这些成本都比一下子删改上千行代码的成本要低。

3.首先搞定端至端

当我们在解决问题和完成功能时,很容易深入到细节问题的研究。这里有一个好方法,能让我们尽快搞定端至端。

例如,假设我需要在网页上设置一个功能,能在用户点击之后做一些复杂运算并把结果存储到服务器中。有些童鞋可能想着想着就先去研究这个运算方式了。我的做法是,先为用户的操作设置事件处理程序,用一些固定的值来模拟计算,然后调用API向服务器请求数据。这样一来,我们就没必要先考虑每一个具体细节,可以直接端至端地测试系统。同时,这个快速的反馈回路有助于我们更快地迭代和写代码。一开始出来的设计可能并不完美,但是通过亲眼目睹各个部件是如何组合的,我们将会对整个系统有一个更清晰的了解,做出最优的设计。

在HubSpot,在产品还没完成之前,我们就先将功能推出去了,这样我们就可以及时进行内部测试。这是对此端至端概念更进一步的深化。

4.适时离开电脑

有时候在调试时,console.logging无处不在,最好的方法就是测试代码。也有的时候,你绞尽脑汁呕心沥血地想要解决一些复杂的设计和问题而不得其法,那么你最好先暂时离开一会。虽然这听上去有点不可思议,但是有的时候,我的确是在厕所想到了问题的症结所在。我的爱人,她也是一枚软件工程师,曾告诉我,当她睡着的时候常常会有各种奇思妙想(有时闭上眼睛天马行空,有时梦里各种方案纷至沓来)。打个盹、散散步、上个厕所……都可以,总之适时离开电脑。

5.自动化

高效的开发人员会将很多繁琐的进程自动化。不过一直以来很多人都认为自动化只能节约时间,这是一个很普遍的误解。其实不仅如此,自动化最大的优点是让你的思想策马奔腾无所阻碍,朝着完成目标的方向奋勇前行。

举个例子,假设我需要经常运行一个相当复杂SQL查询,而过程真心很长,每次又都要重新输入一遍。我当然不会傻乎乎的这么做,我会使用类似于Alfred的程序保存于剪贴板中,或者自己想个办法节约一些步骤。于我而言,自动化是一种更为积极的工作态度。

6.自己动手,“丰衣足食”

当我们在设计新代码时,都希望自己能写出完美的代码,发现每一个抽象概念。但是当我们致力于设计新代码时,抽象概念却又成为了干扰因素,即便这些抽象再怎么显而易见、易于设计。我的做法是,不要立刻思考各种抽象概念,先简单机械地复制一些代码作为原型。这能让我迅速上手新项目,效果比我仅仅只是纸上谈兵要好,之后所能做的抽象发散也更广阔。不过,可不要光复制,还要清理代码,不然它们很快就会变成一笔烂摊子。

7.运动很重要

写代码其实并不能燃烧很多卡洛里,因此我们必须强迫自己动起来。可以不时地伸伸懒腰,经常性地走来走去。在HubSpot,我们有一个俱乐部,我每周会有三天在午饭前去健身。此外,我的习惯是每隔一小时左右做几个俯卧撑,拉伸肌肉,保持活力。

因为久坐我以前经常肩膀疼背疼,但是自从立式桌的出现,这些都成为了历史。如果你也有这方面的烦恼,不妨试一下这个方法,起效快、效果好。HubSpot为我们提供的电动办公桌可以在立式和坐式之间转换。当然如果放在家里,1000美元这样一顶桌子可能太奢侈了,所以我就在网上买了个二手的,只要40美元。

8.阅读前文

阅读别人的文档、技术文章和代码常常让我抓狂。为了不气得抓耳挠腮、捶胸顿足,不妨先阅读前文,以期更多的细节内容。程序中的概念很难用线性方式表达出来。阅读前文能让我们更清楚文章内容和代码在说什么。

9.一丝不苟做笔记

有些组织化程度较低的开发人员可能会对这个技巧嗤之以鼻。知道我是怎么做的吗?我会将每一天我做了什么、遇到的问题以及我是如何解决这些问题的等等,都详细地记录下来。然后当我再次碰到类似的问题时,那就再也不会只能“执手相看泪眼,竟无语凝噎”了。这些笔记成为了我无价的财富,因为我可以运用之前的经验和智慧来解决现在的问题。而且要是碰到1对1绩效考核时,我也能迅速想起自己为公司所做的贡献和自己的成就。

10.给第二天做个计划

要么是下班回家之前,要么是晚上睡觉前,我都会在笔记本中为第二天列个待办事项列表。这样,当这一天来临的时候,我的目标就很明确,知道自己要做什么,专心致志,聚精会神,朝着目标前进。知道吗,这种方法让我完成任务的速度更快质量更高,这样我就有更多的时间休息了。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),