language-features

Is java.lang.Math.PI equal to GCC's M_PI?

北城余情 提交于 2019-12-10 13:32:17
问题 I am coding several reference algorithms in both Java and C/C++. Some of these algorithms use π. I would like for the two implementations of each algorithm to produce identical results, without rounding differently. One way to do this that has worked consistently so far is to use a custom-defined pi constant which is exactly the same in both languages, such as 3.14159. However, it strikes me as silly to define pi when there are already high-precision constants defined in both the Java and GCC

Create a “forCount” control structure in Swift

风流意气都作罢 提交于 2019-12-10 12:55:23
问题 In many projects this control structure is ideal for readability: forCount( 40 ) { // this block is run 40 times } You can do exactly that in objective-C. Given that Swift has a very different approach to macros than objective-c, is there a way to create such a forCount(40) control structure in Swift projects? Some similar concepts in Swift: for _ in 1...40 { // this block is run 40 times } Using an ingenious extension to Int ... 40.times { // this block is run 40 times } 回答1: There are no

How does the C++ runtime determine the type of a thrown exception?

扶醉桌前 提交于 2019-12-10 03:11:07
问题 If I do the following, how does the runtime determine the type of the thrown exception? Does it use RTTI for that? try { dostuff(); // throws something } catch(int e) { // .. } catch (const char * e) { // .. } catch (const myexceptiontype * e) { // .. } catch (myexceptiontype e) // is this the same as the previous handler? { // .. } See also: How is the C++ exception handling runtime implemented? 回答1: Unlike the concerns asked in that other questions, the answer to this question can be

Call/Return feature of classic C++(C with Classes), what modern languages have it?

自古美人都是妖i 提交于 2019-12-10 02:44:51
问题 On page 57 of The Design and Evolution of C++, Dr. Stroustrup talks about a feature that was initially part of C with Classes, but it isn't part of modern C++(standard C++). The feature is called call/return . This is an example: class myclass { call() { /* do something before each call to a function. */ } return() { /* do something else after each call to a function. */ } ... }; I find this feature very interesting. Does any modern language have this particular feature? 回答1: The modern C++

Programming Language Properties that facilitate refactoring?

混江龙づ霸主 提交于 2019-12-09 17:09:06
问题 What are common traits/properties of programming languages that facilitate (simplify) the development of widely automated source code analysis and re-engineering (transformation) tools? I am mostly thinking in terms of programming language features that make it easier to develop static analysis and refactoring tools (i.e. compare Java vs. C++, the former of which has better support for refactoring). In other words, a programming language that would be explicitly designed to provide support

Scala equivalent to Haskell's where-clauses?

空扰寡人 提交于 2019-12-09 08:05:51
问题 Is it possible to use something similar to where-clauses in Scala? Maybe there is some trick I didn't think of? Edit: Thanks for all your answers, they are very much appreciated. To sum up: Local vars, vals and defs can be used to achieve almost the same thing. For lazy evaluation, one can use lazy val (with implicit caching) or function definitions. Ensuring functional purity is left to the programmer. Now just one question remains: Is there a way of putting the value or function definitions

Events on PHP. Is it possible?

一个人想着一个人 提交于 2019-12-09 01:00:06
问题 I'm coming from the C# world and has just started doing a little PHP coding, so I was wondering if it is possible to use events on PHP, or if it is planned to include this feature in a future release. If you have a way to simulate it, different than this, it would be very appreciated, thanks. 回答1: No event like C# in PHP but you can implement a Observer Pattern to attach delegate to be notified. 回答2: The Prado PHP Framework is an event driven framework that may appeal to you, especially since

What does “this” mean when used as a prefix for method parameters?

不打扰是莪最后的温柔 提交于 2019-12-08 22:11:48
问题 I'm sure the answer is something obvious, and I'm kind of embarrassed that I don't really know the answer already, but consider the following code sample I picked up while reading "Professional ASP.NET MVC 1.0": public static class ControllerHelpers { public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> errors) { foreach (RuleViolation issue in errors) modelState.AddModelError(issue.PropertyName, issue.ErrorMessage); } } I understand what this

Does Perl language aim at producing fast programs at runtime?

岁酱吖の 提交于 2019-12-08 20:46:13
问题 I recently had a friend tell me "see perl was never designed to be fast" Is that true? The relevant piece of information I can find is this from Wikipedia: The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). But it doesn't directly talk about speed. I think that with all the text processing that it needs to do, speed of execution really matters for a language like Perl. And with all the weird syntax, elegance was never an

Is there any current proposal I can follow about adding proper locale support to JavaScript?

故事扮演 提交于 2019-12-07 16:38:40
问题 Even though all major operating systems and programming languages/APIs have had locale support for at least a couple of decades, it seems that JavaScript still does not! With JavaScript becoming more and more of a full application programming language both in the browser and on the server, the lack of real locale support is becoming a real problem. Are there any proposals to add locale support as it exists in other languages to the EcmaScript standard? As part of the "harmony" project or