standards

What is the point of `void func() throw(type)`?

那年仲夏 提交于 2019-12-29 07:15:09
问题 I know this is a valid c++ program. What is the point of the throw in the function declarement? AFAIK it does nothing and isnt used for anything. #include <exception> void func() throw(std::exception) { } int main() { return 0; } 回答1: That is an exception specification, and it is almost certainly a bad idea. It states that func may throw a std::exception , and any other exception that func emits will result in a call to unexpected(). 回答2: It specifies that any std::exception can be thrown

PHP array vs [ ] in method and variable declaration

时光毁灭记忆、已成空白 提交于 2019-12-29 04:05:29
问题 I have a question about PHP syntax. When defining functions and variables, which convention should I use? I know they do the same thing in practice but I would like to know which method conforms to best practice standards. Variables public $varname = array(); or public $varname = []; Methods public function foo($bar = array()){} or public function foo($bar = []){} 回答1: PSR-2 (by PHP Framework Interoperability Group) does not mention short array syntax. But as you can see in chapter 4.3 they

Coding Style Standards for Android

馋奶兔 提交于 2019-12-29 02:21:08
问题 I would like to know if there is some standard code styling for Android(maybe a book?) (styling XML , Java programming , file naming , etc...) 回答1: There is a good description of code style rules here. If you want to enforce this rules without remembering all of them, and you are using eclipse then you can use formatting rules provided by Android team: android-formatting.xml. Just import it into eclipse using Preferences->Java->Code Style->Formatter, click Import. 回答2: There is a ton of

Is a compiler allowed to add functions to standard headers?

偶尔善良 提交于 2019-12-28 06:58:26
问题 Is a C compiler allowed to add functions to standard headers and still conform to the C standard? I read this somewhere, but I can't find any reference in the standard, except in annex J.5: The inclusion of any extension that may cause a strictly conforming program to become invalid renders an implementation nonconforming. Examples of such extensions are new keywords, extra library functions declared in standard headers , or predefined macros with names that do not begin with an underscore.

Is a compiler allowed to add functions to standard headers?

╄→гoц情女王★ 提交于 2019-12-28 06:58:11
问题 Is a C compiler allowed to add functions to standard headers and still conform to the C standard? I read this somewhere, but I can't find any reference in the standard, except in annex J.5: The inclusion of any extension that may cause a strictly conforming program to become invalid renders an implementation nonconforming. Examples of such extensions are new keywords, extra library functions declared in standard headers , or predefined macros with names that do not begin with an underscore.

C++ standard wording: Does “through all iterators in the range” imply sequentiality?

女生的网名这么多〃 提交于 2019-12-28 06:18:30
问题 This SO question sparked a discussion about std::generate and the guarantees made by the standard. In particular, can you use function objects with internal state and rely on generate(it1, it2, gen) to call gen() , store the result in *it , call gen() again, store in *(it + 1) etc., or can it start at the back, for example? The standard (n3337, §25.3.7/1) says this: Effects: The first algorithm invokes the function object gen and assigns the return value of gen through all the iterators in

is it ok to specialize std::numeric_limits<T> for user-defined number-like classes?

非 Y 不嫁゛ 提交于 2019-12-28 06:17:10
问题 The documentation of std::numeric_limits<T> says it should not be specialized for non-fundamental types. What about number-like user-defined types? If I define my own type T which represents a numeric value and overloads numeric operators, and for which the information represented by numeric_limits makes sense -- will anything break if I specialize numeric_limits for that type? 回答1: Short answer: Go ahead, nothing bad will happen. Long answer: The C++ standard extensively protects the ::std

Should a collection of constants be placed in a class or interface?

試著忘記壹切 提交于 2019-12-28 03:46:06
问题 If I have a collection of static constants that I want to declare centrally so that they can be shared among various projects should they be put in a class or interface (Java). In the past I have seen them mostly put in a class but I started thinking that since the class will not and should not be instantiated maybe they would be better in an interface, but then again the interface should not be implemented by any classes, e.g. public class ErrorCodes { public static final String ERROR_1 = "

List of standard lengths for database fields

岁酱吖の 提交于 2019-12-28 03:15:11
问题 I'm designing a database table and once again asking myself the same stupid question: How long should the firstname field be? Does anyone have a list of reasonable lengths for the most common fields , such as first name, last name, and email address? 回答1: W3C's recommendation: If designing a form or database that will accept names from people with a variety of backgrounds, you should ask yourself whether you really need to have separate fields for given name and family name. … Bear in mind

When to use each method of launching a subprocess in Ruby

ε祈祈猫儿з 提交于 2019-12-28 02:26:09
问题 1. `` The Backtick defined in Kernel 1. a) %x{} Percent X < alternate syntax for The Backtick defined in parse.y, see discussion 2. system() Kernel#system 3. fork() Kernel#fork, Process#fork 4. open() open a pipe Kernel#open 4.a. IO.popen() < behaves the same as open() open a pipe IO#popen 4.b. open("|-") fork to a pipe 4.c. IO.popen("-") < behaves the same as open("|-") fork to a pipe see discussion 5. Open3.popen3() require 'open3' stdlib Open3 6. PTY.spawn() require 'pty' stdlib PTY 7.