我有一个方法:
def foo(bar):
# ...
Run Code Online (Sandbox Code Playgroud)
有没有办法标记bar为常数?如" bar无法改变的价值"或"无法改变的对象bar".
我正在从事非个人项目,因此可以说维护程序员不会是我,否则我不需要问这个问题.
现在有一些构造(委托,lambda表达式),我想在我的代码中尝试,而不是故意使代码更难阅读,但因为它们适合于这种情况(并且更少的代码也可以输入),以及因为我是这门语言的新手,所以也可以练习使用它们.
但是,我不确定维护程序员是否会知道每个构造,因为我们很多人都不是来自ac #background,而且我不确定他是否像我一样热衷于编程或只是像常规一样对待它一天的工作.所以我的问题是:
是否应避免使用某些编程结构来提高可维护性?
如果上述问题的答案是肯定的,那么应该避免使用的构造子集是什么?
维护程序员有责任完全学习一门语言吗?
在代码中:
public interface ProductInterface {
public List<ProductVO> getProductPricing(ProductVO product, ProductVO prodPackage, String... pricingTypes) throws ServiceException;
}
Run Code Online (Sandbox Code Playgroud)
是什么
String... pricingTypes
Run Code Online (Sandbox Code Playgroud)
意思?这是什么类型的构造?
我刚刚阅读了PHP文档中的Expressions页面,并在顶部说:
定义表达式的最简单但最准确的方法是"任何有价值的东西".
这个简单的定义包括所有函数和大多数语言结构,但有一些语言结构明确声明它们不返回值.
以下是返回值的语言结构列表:
以下是有趣的少数几个不返回值,因此不是表达式:
我发现die并且exit特别感兴趣,因为它们可以在PHP中用作表达式,尽管没有返回值.以下代码行都会抛出语法错误,如预期的那样:
echo 'Hi' or echo 'Bye';
if(echo('foo'))
return return(1);
$foo['bar'] = isset($foo['bar']) ? unset($foo['bar']) : 0;
if(unset($foo['bar']))
__halt_compiler() or die;
Run Code Online (Sandbox Code Playgroud)
但是,以下PHP代码完全没有语法错误:
print 'Hi' or print 'Bye'; // Makes sense, print returns a value
if(!die() and exit) // Wait what's happening here?
quit(die(exit(quit()))); // die and exit don't have return values (does quit?)
$x = …Run Code Online (Sandbox Code Playgroud) 作为Powershell世界的新手,有时我会陷入棘手的语法.这就是为什么我试图弄清楚语言中括号的所有可能用途.
你还知道吗?你能加到这里吗?
在我这里(省略了管道中卷曲的基本用法和方法调用中的圆形):
# empty array
$myarray = @()
# empty hash
$myhash = @{}
# empty script block
$myscript = {}
# variables with special characters
${very strange variable @ stack !! overflow ??}="just an example"
# Single statement expressions
(ls -filter $home\bin\*.ps1).length
# Multi-statement expressions inside strings
"Processes: $($p = “a*”; get-process $p )"
# Multi statement array expression
@( ls c:\; ls d:\)
Run Code Online (Sandbox Code Playgroud) 我最近遇到了使用Loop Do的问题/解决方案.到目前为止,我在学习Ruby编程时很少见到这一点(我是一名没有CS经验的初学者).
# Write a function, `nearest_larger(arr, i)` which takes an array and an
# index. The function should return another index, `j`: this should
# satisfy:
#
# (a) `arr[i] < arr[j]`, AND
# (b) there is no `j2` closer to `i` than `j` where `arr[i] < arr[j]`.
#
# In case of ties (see example beow), choose the earliest (left-most)
# of the two indices. If no number in `arr` is largr than `arr[i]`,
# return `nil`.
# …Run Code Online (Sandbox Code Playgroud) 当我学习JavaScript时,我一直在浏览网页,并在Javascript中看到了许多对构造的引用,但我似乎无法找到它们是什么以及它们不是什么的完整定义,尤其是在Javascript的上下文中.
例如,在"类似问题"中,我看到的链接导致了一个包含以下代码的示例:
(function () {
})();
Run Code Online (Sandbox Code Playgroud)
据我所知,这是一个构造,但它们定义的是什么?
我需要使用常量作为类名来访问此类静态属性,即
class a {
public static $name = "Jon";
}
define("CLASSNAME", "a");
echo CLASSNAME::$name;
Run Code Online (Sandbox Code Playgroud)
这会返回错误,该类CLASSNAME不存在.有一些解决方案吗?
javascript ×2
php ×2
ruby ×2
c# ×1
constants ×1
enumeration ×1
execution ×1
expression ×1
java ×1
loops ×1
maintenance ×1
powershell ×1
python ×1
syntax ×1