标签: coding-style

为什么所有用户定义的标识符都以大写字母开头?

在我知道的所有Ada源代码中,包括标准库(抱歉,我不知道在网上找到它)或小游戏实现,所有非保留字都以大写字母开头.(最后,堆栈,索引,...)
因为所有保留的关键字都被编辑器突出显示,我猜/希望它不是用于区分用户定义的标识符.

在Python,C++或Java中,大写通常用于某些事物(通常是类标识符和常量),以允许它们被人类读者快速识别.(案例提供有关意义的信息)

为什么"官方"Ada代码以不同方式执行此操作?为什么不使用类型,模块之类的大写字母?

是因为通过信件案件的信息被认为是一件坏事吗?
如果是这样,为什么?

coding-style ada

1
推荐指数
1
解决办法
122
查看次数

如何在字符串中使用符号?

此行不会在Visual C++中编译

printf("x=%"PRIszu")\n",
Run Code Online (Sandbox Code Playgroud)

即使符号已定义:

#define PRIszu    "Iu"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

错误C3688无效的文字后缀'PRIszu'; 文字运算符或模板'运算符'"PRIszu'未找到

那么如何修复此打印行以使用定义的符号?

c c++ coding-style visual-c++

1
推荐指数
1
解决办法
422
查看次数

在Haskell中使用3-arg中缀运算符的真实示例?(比如$ ||.)

我在包中找到了一堆运算符$||parallel:

-- Strategic function application

{-
These are very handy when writing pipeline parallelism asa sequence of
@$@, @$|@ and @$||@'s. There is no need of naming intermediate values
in this case. The separation of algorithm from strategy is achieved by
allowing strategies only as second arguments to @$|@ and @$||@.
-}

-- | Sequential function application. The argument is evaluated using
--   the given strategy before it is given to the function.
($|) :: (a …
Run Code Online (Sandbox Code Playgroud)

parallel-processing haskell coding-style infix-operator

1
推荐指数
1
解决办法
609
查看次数

何时在Python中使用_作为变量?

我最近发现我可以_用作变量.

是否有一个特定的协议何时将其用作变量名?应该__用吗?

来自deeplearning.netTheano库的示例,_在定义theano.scan()操作时有一种趋势...

values, _ = theano.scan(power_of_2,
                        outputs_info = T.constant(1.),
                        non_sequences = max_value,
                        n_steps = 1024)
Run Code Online (Sandbox Code Playgroud)

python variables coding-style naming-conventions

1
推荐指数
1
解决办法
139
查看次数

Android中的编码风格:何时应该使用样式而不是内联属性?

我不确定在Android中开发界面的最佳方法是什么.通过将内联属性移动到样式文件来清理布局文件是否更好?据我所知,在HTML中最好在HTML中使用类和ID,并在style.css文件中使用它们.安卓怎么样?

android coding-style android-layout

1
推荐指数
1
解决办法
1266
查看次数

收紧Ruby代码,制作小方法

我有一个由RuboCop报告的方法太长:每个方法只允许七行.这是令人讨厌的方法:

def on(definition, visit = false, &block)
  if @active.is_a?(definition)
    block.call @active if block
    return @active
  end

  @active = definition.new
  @active.load if visit

  block.call @active if block

  @active
end
Run Code Online (Sandbox Code Playgroud)

我打算将顶级if条件转换为保护条款,但我不知道该怎么做.

我尝试将第7行和第8行合并到此:

@active = definition.new().load if visit
Run Code Online (Sandbox Code Playgroud)

但这绝对不起作用.

我不能让RuboCop违规行为有效,也不能改变容差.

ruby coding-style rubocop

1
推荐指数
1
解决办法
92
查看次数

"不得使用输入/输出库<stdio.h>."

我正在阅读JSF AV C++编码标准,规则22说:

AV规则22(MISRA规则124,修订)

<stdio.h> 不应使用输入/输出库.

有没有理由不使用<stdio.h>

我知道这些规则适用于C++,我们可以使用<iostream>......但是有什么问题<stdio.h>

c++ coding-style

1
推荐指数
2
解决办法
1941
查看次数

Python编码风格-多个return语句

对于同一任务,我编写了两个不同的函数。我想知道哪个更优雅。

任务是检查pydot对象是否包含请求的节点,如果是,则返回节点和图形对象。如果该节点不存在,则需要创建该节点。

为了获得节点的名称,我使用pydot对象get_nodes()函数。但是,如果尚未引入任何节点,则此函数将返回一个空列表。因此,在遍历值之前,我进行了一个空列表检查。

第一个变体(“ variant1”)很容易理解。在进行长度检查(这是由于所必需的)之后node.get_name(),它循环到节点名称,一旦找到要搜索的节点,就返回该节点和图形。如果没有,它将调用一个函数来创建节点并更新图形。尽管此功能易于理解,但恕我直言,它并不美观。它包含两个“ return”语句:

def variant1(node_name, graph):

    if len(graph.get_nodes()) > 0:

        for node in graph.get_nodes():
            if node_name == node.get_name():
                return node, graph

    return create_node(node_name, graph)
Run Code Online (Sandbox Code Playgroud)

第二种变体要复杂得多。一旦在图中找到该节点,它就会断开并直接跳到最后一行(“返回节点,图”)。此变体只有一个return语句。

def variant2(node_name, graph):

    if len(graph.get_nodes()) > 0:

        for node in graph.get_nodes():
            if node_name == node.get_name():
                break

        else:
            # the node doesnt exist. create it and update the graph
            node, graph = create_node(node_name, graph)

    else:
        # create the first node in the graph
        node, graph …
Run Code Online (Sandbox Code Playgroud)

python coding-style pydot

1
推荐指数
1
解决办法
1万
查看次数

flatMap功能签名(输入 - >输出)是否建议进行任何展平?

flatMap 签名:

 /* applies a transformation of the monad "content" by composing
  * this monad with an operation resulting in another monad instance 
  * of the same type
  */
  def flatMap(f: A => M[B]): M[B]
Run Code Online (Sandbox Code Playgroud)

无论如何要通过它的签名(输入到输出)(除了名称flat)来理解它的扁平化结构?或者我必须阅读其实现以了解这一点?是不是很好的编码实践意味着我可以通过函数的签名(甚至没有函数名输入输出)来理解它的作用是什么?如果是这样,flatMap这个基本的编程实践如何?还是违反了它?

functional-programming coding-style scala code-cleanup

1
推荐指数
1
解决办法
242
查看次数

C#SqlCommand命名约定

我很擅长使用C#和ASP.NET,我很好奇是否有一个约定在SQL数据库上运行多个查询时命名SqlCommands.例如,我创建了我的SqlConnection,我希望调用一个函数,两个存储过程,并创建一个常规的简单查询.目前,我正在使用:

SqlCommand function = new SqlCommand();
SqlCommand command = new SqlCommand();
SqlCommand proc1 = new SqlCommand();
SqlCommand proc2 = new SqlCommand();
Run Code Online (Sandbox Code Playgroud)

对于这些不同的命令是否有更多的接受命名约定,或者我应该使用单个命令,因为我在后面的代码块中使用CommandText和CommandType调用?

c# sql asp.net coding-style naming-conventions

1
推荐指数
1
解决办法
800
查看次数