zoukankan      html  css  js  c++  java
  • 嵌入式GUI FTK编程风格


    转载时请注明出处和作者联系方式
    文章出处:http://www.limodev.cn/blog
    作者联系方式:李先静 <xianjimli@gmail.com>

    命名规则

    名称要表达出对象的意义。

    1.文件名

        * 以ftk开头(demo和测试程序除外)。
        * 单词小写。
        * 多个单词用下划线分隔。

    示例:

    ftk_window.c
    ftk_window.h

    2.函数名

        * 以ftk开头(内部函数或工具函数外可以例外)。
        * 单词小写。
        * 多个单词用下划线分隔。

    示例:

    ftk_window_set_focus
    ftk_window_get_focus

    3.变量名

        * 单词小写。
        * 多个单词用下划线分隔。
        * 对象以thiz命名。

    示例:

    int fullscreen
    FtkWidget* thiz
    int update_disabled

    4.结构名/枚举名/联合名

        * 以Ftk开头(C文件内部使用的结构可以例外)。
        * 单词首字大写。
        * 多个单词连写。
        * 接口的私有信息统一用PrivInfo。

    示例:

    typedef struct _FtkPoint
    {
    int x;
    int y;
    }FtkPoint;
     
    typedef struct _PrivInfo
    {
    FtkCanvas*  canvas;
    ...
    }PrivInfo;

    7.常量(宏/枚举变量)

        * 以FTK开头(RET_系列除外)。
        * 单词大写。
        * 多个单词用下划线分隔。

    示例:

    FTK_WIDGET_NORMAL
    FTK_WIDGET_FOCUSED


    排版规则
    1.缩进

        * 以TAB键缩进。
        * TAB键的宽度设置为4。

    vim可用下面的设置:

    set ts=4
    set sw=4
    set ai
    set ci

    2.空行

        * 避免连续多个空行。
        * 函数之间要加空行。
        * return与其它语句之要加空行。
        * 变量声明与执行代码之间要加空行。
        * 逻辑块之间要加空行。

    3.空格

        * 操作符两端用加空格
        * 函数参数之间用加空格
        * 用./->等访问成员时,不要加空格。
        * 定义指针时,*与类型之间不要加空格。

    可移性

        * 避免使用编译器特有的特性。
        * 避免使用C99等新的特性。
        * 使用FTK包装的函数(如内存管理和字符串操作)
        * 平台相关的函数要抽象后使用。
        * 变量声明要在执行语句之前。
        * 对于在多个平台上运行的代码,要在多个平台编译测试。

    稳定性

        * 变量声明时即对其进行初始化。
        * 功能测试通过后,用valgrind检测内存越界和持续内存泄露。


    杂项

        * 避免使用全局变量。
        * 内部函数加static


    注释规则

        * 用简单明了的代码代替注释。
        * 注释用英文书写。
        * 注释中写背景和原因,而不是重复代码。
        * 文件头注释的格式如下(演示程序、测试程序和自动产生的代码可以例外):

    /*
    * File: 文件名
    * Author: 作者及邮件
    * Brief: 说明
    *
    * Copyright (c) 2009 - 2010 版权
    *
    * Licensed under the Academic Free License version 2.1
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
     
    /*
    * History:
    * ================================================================
    * date who what
    *
    */

  • 相关阅读:
    Java实现 LeetCode 735 行星碰撞(栈)
    Java实现 LeetCode 735 行星碰撞(栈)
    Java实现 LeetCode 887 鸡蛋掉落(动态规划,谷歌面试题,蓝桥杯真题)
    Java实现 LeetCode 887 鸡蛋掉落(动态规划,谷歌面试题,蓝桥杯真题)
    Java实现 LeetCode 887 鸡蛋掉落(动态规划,谷歌面试题,蓝桥杯真题)
    Java实现 蓝桥杯算法提高 求最大值
    Java实现 蓝桥杯算法提高 求最大值
    Java实现 蓝桥杯算法提高 求最大值
    Python eval() 函数
    Python repr() 函数
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167398.html
Copyright © 2011-2022 走看看