标签: coding-style

空检查编码标准

关于空检查的编码标准我有疑问.我想知道它们之间的区别

if(a!=null)
Run Code Online (Sandbox Code Playgroud)

if(null!=a)
Run Code Online (Sandbox Code Playgroud)

哪一个更好,哪一个使用,为什么?

java syntax null android coding-style

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

在我的pojo字段中使用"public"修饰符而不是"private"是否有任何风险?

在我的所有JSF项目中,我使用Pojo
As 的标准定义Plain Old Java Object来定义private字段的修饰符

例如

public class Pojo {

    // My private fields
    private String field1;
    private String field2;

    // setters AND getters
    // ----------------------------
    public String getField1() {
        return field1;
    }
    public void setField1(String field1) {
        this.field1 = field1;
    }
    public String getField2() {
        return field2;
    }
    public void setField2(String field2) {
        this.field2 = field2;
    }
    // ---------------------------- 
}
Run Code Online (Sandbox Code Playgroud)

是否有任何冒险去使用public的,而不是修改private我的Pojo领域
对于示例

public class Pojo …
Run Code Online (Sandbox Code Playgroud)

java coding-style pojo

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

什么可能是使用`int x = x;`表达式(C语言)?

我有一个用C语言编写的库.在代码中,我发现了几行代码int x = x;.我需要用/ Zw标志重写所有这些代码以进行编译.在某些意味着的地方int x = some_struct->x;,但在另一些情况下,我不明白它是什么.在某些地方,它首先使用x变量.所以在哪些情况下可以使用这种int x = x;表达方式.

void oc_enc_tokenize_dc_frag_list(oc_enc_ctx *_enc,int _pli,
    const ptrdiff_t *_coded_fragis,ptrdiff_t _ncoded_fragis,
    int _prev_ndct_tokens1,int _prev_eob_run1){
    const ogg_int16_t *frag_dc;
    ptrdiff_t          fragii;
    unsigned char     *dct_tokens0;
    unsigned char     *dct_tokens1;
    ogg_uint16_t      *extra_bits0;
    ogg_uint16_t      *extra_bits1;
    ptrdiff_t          ti0;
    ptrdiff_t          ti1r;
    ptrdiff_t          ti1w;
    int                eob_run0;
    int                eob_run1;
    int                neobs1;
    int                token;
    int                eb;
    int                token1=token1;
    int                eb1=eb1;
    /*Return immediately if there are no coded fragments; otherwise we'd flush
       any trailing EOB run into the …
Run Code Online (Sandbox Code Playgroud)

c syntax coding-style

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

在字符串中的所有字符之间插入字符的更简洁方法

我想在字符串的每个可能索引处插入一个字符,包括在第一个元素之前和最后一个元素之后.现在我正在做:

      result = []
      result << c + str
      result << str + c
      for i in 0..str.length-2 do
        result << (str[0..i] + c + str[i+1..-1])
      end
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以做到这一点,没有2个特殊情况,并有一个从0到0的循环 str.length - 2

编辑

使用' - '和'hello'输出示例:

["-hello", "h-ello", "he-llo", "hel-lo", "hell-o", "hello-"]
Run Code Online (Sandbox Code Playgroud)

ruby coding-style

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

Matlab - 是否可以跟踪代码从开始到最终版本的变化?

有没有一种方法可以自动跟踪自代码开始(概念)以来的每一个变化?

version-control matlab coding-style

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

我可以改进这个AngularJS/AJAX javascript片段吗?

我有以下一般代码.

MyClass.prototype.doSomething = function () {

    $.ajax({
        url: turl,
        dataType: 'jsonp',
        success: function (_this) { //closure
            return function (data) {
                _this._angular_scope.$apply(function () {

                    _this.property = // extract stuff from 'data'
                    _this.analyzeContent() // do more stuff with it
                })
            }
        }(this)
    })
}
Run Code Online (Sandbox Code Playgroud)

基本上,这只是一个普通的AJAX调用.有个...

(1)关闭"this",以便成功函数可以访问我的对象及其状态

(2)在里面,我返回一个对数据执行某些操作的函数,但是......

(3)我想要的一切,成功确实被AngularJS被捕获,所以这个功能解析数据,进一步,在$应用调用它包装的行为.

这有效,但我不禁想知道是否有更好的方法来实现这一目标.由于嵌套函数的数量,我每次看到它时都要考虑我正在做什么,这是正确的.

这没关系,还是有更好的推荐风格?

javascript ajax design-patterns coding-style angularjs

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

程序是否真的每次都创建了内部对象?

为什么我问这个问题,因为我总是担心这种风格的代码

def callsomething(x):
    if x in (3,4,5,6):
        #do something
Run Code Online (Sandbox Code Playgroud)

如果函数调用的东西经常被调用,那么(3,4,5,6)是否浪费了太多的空间和时间?在某些语言如C中,它可能被推入数据段,如常量,但在python中,我不知道它是如何工作的,所以我倾向于编写这样的代码

checktypes = (3,4,5,6)#cache it
def callsomething(x):
    global checktypes
    if x in checktypes:
        #do something
Run Code Online (Sandbox Code Playgroud)

但经过测试我发现这种方式使程序变慢,在更复杂的情况下,代码将是这样的:

types = (3,4,5,6)
def callsomething(x):
    global types
    for t in types:
        t += x
        #do something
Run Code Online (Sandbox Code Playgroud)

仍然比这慢

def callsomething(x):
    for t in (3+x,4+x,5+x,6+x):
        #do something
Run Code Online (Sandbox Code Playgroud)

在这种情况下,程序必须创建(3 + x,4 + x,5 + x,6 + x),对吧?但它仍然比第一个版本更快,但不是太多了.

我知道python中的全局var访问会减慢程序,但它与创建结构的比较有多大?

python coding-style python-3.x

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

如何在java编码中添加另一个圆圈

所以今天我正在制作一个节目,因为我还是初学者,我还在学习,但我想知道如何添加另一个圈子,例如我有两个单位,红色和蓝色,我添加了随机选择随机选择x和y位置,但是当我点击开始它只显示一个红色的圆圈,蓝色的那个甚至没有,我知道我没有做过一些编码,但这是我的程序,请帮助谢谢: )

所以,哦:)提前谢谢.

java swing coding-style awt paint

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

'public static'和'static public'之间的区别

在Java中,我发现一些开发人员写道:

public static functionName() {}
Run Code Online (Sandbox Code Playgroud)

但其他人写道:

static public functionName() {}
Run Code Online (Sandbox Code Playgroud)

这两者有什么区别?

java coding-style modifiers

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

java中的编程约定

关于java中所谓的编程约定的一个方面,我有一个简单的问题.

简单地说 - 如果我将一个方法中的局部变量传递给另一个(辅助)方法 - 我应该将其名称保持为100%还是尝试稍微重命名?

看一下这个例子 - 我应该将helpermethods签名中的变量totalAmount重命名为类似的东西(例如total_amount或theTotalAmount)吗?

private void myMethod() {

   int totalAmount = 0;
   // calculations where totalAmount is involved.

   myHelperMethod(totalAmount); // send totalAmount to a another method.

}

private void myHelperMethod(int totalAmount) {

    // use totalAmount here .....
}
Run Code Online (Sandbox Code Playgroud)

java coding-style

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