What can `__init__` do that `__new__` cannot?

Note about difference between __new__ and __init__ Before explaining missing functionality let’s get back to definition of __new__ and __init__: __new__ is the first step of instance creation. It’s called first, and is responsible for returning a new instance of your class. However, __init__ doesn’t return anything; it’s only responsible for initializing the instance after … Read more

Odd use of curly braces in C

Assuming that MyRecorder is a struct, this sets every member to their respective representation of zero (0 for integers, NULL for pointers etc.). Actually this also works on all other datatypes like int, double, pointers, arrays, nested structures, …, everything you can imagine (thanks to pmg for pointing this out!) UPDATE: A quote extracted from … Read more

Is un-initialized integer always default to 0 in c?

External and static variables are initialized to zero by default, this is guaranteed. Automatic and register variables that do not have en explicit initializer will have an indeterminate value (either an unspecified value or a trap representation). From The Standard: C89 6.5.7: If an object that has static storage duration is not initialized explicitly, it … Read more

What is the best way of reading configuration parameters from configuration file in Java?

I am thinking it will impact performance. I doubt that this will be true. Assuming that the application reads the configuration file just once at startup, the time taken to read the file is probably irrelevant to your application’s overall performance. Indeed, the longer the application runs, the less important startup time will be. Standard … Read more

Array initialization in Perl

If I understand you, perhaps you don’t need an array of zeroes; rather, you need a hash. The hash keys will be the values in the other array and the hash values will be the number of times the value exists in the other array: use strict; use warnings; my @other_array = (0,0,0,1,2,2,3,3,3,4); my %tallies; … Read more

Is a member initializer list part of the declaration or the definition of a constructor?

Just to clarify something that came up in some of the other answers… There is no requirement that the initializer list be in either the source (.cpp) or header (.h) file. In fact, the compiler does not distinguish between the two types of files. The important distinction is between the contructor’s declaration and it’s definition. … Read more

Omitting Sizes while Initializing C/C++ Multidimensional Arrays

The following is from section A8.7 of “The C Programming Language” by K&R, 2nd edition, pages 219,220: An aggregate is a structure or array. If an aggregate contains members of aggregate type, the initialization rules apply recursively. Braces may be elided in the initialization as follows: if the initializer for an aggregate’s member that is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)