Why [Programming Language X] Is Unambiguously Better than [Programming Language Y]

转载神文一篇如下:

Recently I have seen a lot of people wondering about the difference between [X] and [Y]. After all, they point out, both are [paradigm] languages that target [platform] and encourage the [style] style of programming while leaving you enough flexibility to [write shitty code].

Having written [simple program that’s often asked about in phone screens] in both languages, I think I’m pretty qualified to weigh in. I like to think about it in the following way: imagine [toy problem that you might give to a 5th grader who is just learning to program]. A [Y] implementation of it might look like this:

[really poorly engineered Y code]

Whereas in [X] you could accomplish the same thing with just

[slickly written X code that shows off syntactic sugar]

It’s pretty clear that the second is easier to understand and less error-prone.

Now consider type systems. [Religious assertion about the relative merits and demerits of static and dynamic typing.] Sure, [Y] gives you [the benefit of Y’s type system or lack thereof] but is this worth [the detriment of Y’s type system or lack thereof]? Obviously not!

Additionally, consider build tools. While [Y] uses [tool that I have never bothered to understand], [X] uses the far superior [tool that I marginally understand]. That’s reason enough to switch!

Finally, think about the development process. [X] has the amazing [X-specific IDE that’s still in pre-alpha], and it also integrates well with [text-editor that’s like 50 years old and whose key-bindings are based on Klingon] and [IDE that everyone uses but that everyone hates]. Sure, you can use [Y] with some of these, but it’s a much more laborious and painful process.

In conclusion, while there is room for polyglotism on the [platform] platform, we would all be well served if you [Y] developers would either crawl into a hole somewhere or else switch to [X] and compete with us for the handful of [X] jobs. Wait, never mind, [Y] is awesome!

python技巧:逆序循环

Python可以很简单实现C语言中for(i = len; i>=0; –i)的逆序循环,而且有不止一种写法:

第一种,for i in range(len, -1, -1) ,简单易懂

第二种,for i in range(0, len+1)[::-1],利用list的[start:end:step]排序功能,当然在大数组下性能堪忧

C++中的局部类与嵌套类

局部类指在函数内部定义的类,自然局部类不能含有static成员,所有函数定义也必须在定义体内完成。基本不会使用。

嵌套类指在类内部定义类,该类名只能在外围类中使用,嵌套类中的函数成员可以在定义体外定义(但是需要使用限定符以使用类名),嵌套类中申明的成员不是外围类对象的成员,反之亦然。

因此分析访问关系时,完全可以当做非嵌套类处理,即嵌套类无法访问外围类的私有成员,也不能对外围类中定义的私有嵌套类创建对象,嵌套类可以访问static private成员,嵌套类中申明的友元也不能访问外围类中的私有成员。

PHP魔术函数集锦

1。construct()
实例化对象时被调用,
construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用。

2。__destruct()

当删除一个对象或对象操作终止时被调用。

3。call()
对象调用某个方法,
若方法存在,则直接调用;
若不存在,则会去调用
call函数。

4。get()
读取一个对象的属性时,
若属性存在,则直接返回属性值;
若不存在,则会调用
get函数。

5。set()
设置一个对象的属性时,
若属性存在,则直接赋值;
若不存在,则会调用
set函数。

6。__toString()

打印一个对象的时被调用。如echo $obj;或print $obj;

7。__clone()

克隆对象时被调用。如:$t=new Test();$t1=clone $t;

8。__sleep()

serialize之前被调用。若对象比较大,想删减一点东东再序列化,可考虑一下此函数。

9。__wakeup()

unserialize时被调用,做些对象的初始化工作。

10。__isset()
检测一个对象的属性是否存在时被调用。如:isset($c->name)。

11。__unset()
unset一个对象的属性时被调用。如:unset($c->name)。

12。set_state()
调用var_export时,被调用。用
set_state的返回值做为var_export的返回值。

13。__autoload()
实例化一个对象时,如果对应的类不存在,则该方法被调用。

魔术常量

1。LINE
返回文件中的当前行号。

2。FILE
返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,FILE 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。

3。FUNCTION
返回函数名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。

4。CLASS
返回类的名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该类被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。

5。METHOD
返回类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。

PHP合并数组元素的两种方法与区别



array_merge():
如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。(数字键名会被重新分配,总会变成从零开始的。。)

对于使用“+”合并数组:
如果数组中有相同的字符串键名(不管是不是数字),则会把最先出现的值作为最终结果返回,而把后面的数组拥有相同键名的那些值“抛弃”掉。

参考:php里面合并数组array_merge和加号有什么不同

本站总访问量