language-features

Package accessibility for function and/or class

两盒软妹~` 提交于 2019-12-01 17:14:57
问题 In Java they have package access specifier which enables the function to be used only by classes from this same "package" (namespace) and I see good things about it. Especially when design of models are in play. Do you think that something like this could be useful in C++? Thanks. 回答1: Yes, this can be accomplished. You may restrict visibility by public, protected, private keywords, as well as source visibility. Declared visibility is commonly understood. Source visibility (if you're coming

Package accessibility for function and/or class

风流意气都作罢 提交于 2019-12-01 17:05:36
In Java they have package access specifier which enables the function to be used only by classes from this same "package" (namespace) and I see good things about it. Especially when design of models are in play. Do you think that something like this could be useful in C++? Thanks. Yes, this can be accomplished. You may restrict visibility by public, protected, private keywords, as well as source visibility. Declared visibility is commonly understood. Source visibility (if you're coming from Java) is a bit different. Java: you have one file for an object interface/implementation. Cpp: you have

Which “C# Experimental language feature” is this?

孤人 提交于 2019-12-01 15:50:37
In the example below, Resharper shows "C# Experimental language feature" tooltip on the first curly bracket. I've checked the new features of C# 6.0 but didn't come across a similar one. What is the referred experimental feature? class Class1 { { // <= C# Experimental language feature } } Note: It is an error for .Net Framework 4.5 compiler. "Invalid token '{' in class, struct, or interface member declaration" This was for Primary Constructors , a feature which has now been cut from C#6 . On November 12, 2014 Microsoft announced the release of Visual Studio 2015 on the day of Visual Studio

Why aren't op-assign operators type safe in java?

核能气质少年 提交于 2019-12-01 09:14:23
I'm not sure the question is clearly worded, but an example will be clearer. I found out that will not work in Java: int a = ...; a = 5.0; but this will: int a = ...; a += 5.0; I.e., it seems that the = operator is type safe but += isn't. Is there any deep reason for this or is it just another arbitrary decision language designers must take. To make life easier. Let's go a little further. Consider: byte b; ... ++b; The increment is really doing: b = (byte)(1 + (int)b); Even using += it doesn't get any better: b += b; is: b = (byte)((int)b+(int)b); That would make these operators useless for

Why aren't op-assign operators type safe in java?

送分小仙女□ 提交于 2019-12-01 06:43:23
问题 I'm not sure the question is clearly worded, but an example will be clearer. I found out that will not work in Java: int a = ...; a = 5.0; but this will: int a = ...; a += 5.0; I.e., it seems that the = operator is type safe but += isn't. Is there any deep reason for this or is it just another arbitrary decision language designers must take. 回答1: To make life easier. Let's go a little further. Consider: byte b; ... ++b; The increment is really doing: b = (byte)(1 + (int)b); Even using += it

Ignore NullReferenceException when reading object properties

久未见 提交于 2019-12-01 03:44:15
问题 Is there any way to direct C# to ignore NullReferenceException (or any specific exception for that matter) for a set of statements. This is useful when trying to read properties from a deserialized object that may contain many null objects in it. Having a helper method to check for null could be one way but I'm looking for something close to 'On Error Resume Next' (from VB) at a block of statement level. EDIT:Try-Catch will skip the succeeding statements on exception try { stmt 1;//

How to define a ternary operator in Scala which preserves leading tokens?

末鹿安然 提交于 2019-12-01 03:38:46
I'm writing a code generator which produces Scala output. I need to emulate a ternary operator in such a way that the tokens leading up to '?' remain intact. e.g. convert the expression c ? p : q to c something . The simple if(c) p else q fails my criteria, as it requires putting if( before c . My first attempt (still using c/p/q as above) is c match { case(true) => p; case _ => q } another option I found was: class ternary(val g: Boolean => Any) { def |: (b:Boolean) = g(b) } implicit def autoTernary (g: Boolean => Any): ternary = new ternary(g) which allows me to write: c |: { b: Boolean =>

How to define a ternary operator in Scala which preserves leading tokens?

流过昼夜 提交于 2019-12-01 00:21:08
问题 I'm writing a code generator which produces Scala output. I need to emulate a ternary operator in such a way that the tokens leading up to '?' remain intact. e.g. convert the expression c ? p : q to c something . The simple if(c) p else q fails my criteria, as it requires putting if( before c . My first attempt (still using c/p/q as above) is c match { case(true) => p; case _ => q } another option I found was: class ternary(val g: Boolean => Any) { def |: (b:Boolean) = g(b) } implicit def

Events on PHP. Is it possible?

元气小坏坏 提交于 2019-11-30 22:13:33
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. No event like C# in PHP but you can implement a Observer Pattern to attach delegate to be notified. The Prado PHP Framework is an event driven framework that may appeal to you, especially since you are coming from the land of C# and presumably ASP.NET. Take a look at the Quick Start . Specifically, take

What is the difference between Ruby and Python versions of“self”?

巧了我就是萌 提交于 2019-11-30 20:37:17
I've done some Python but have just now starting to use Ruby I could use a good explanation of the difference between "self" in these two languages. Obvious on first glance: Self is not a keyword in Python, but there is a "self-like" value no matter what you call it. Python methods receive self as an explicit argument, whereas Ruby does not. Ruby sometimes has methods explicitly defined as part of self using dot notation. Initial Googling reveals http://rubylearning.com/satishtalim/ruby_self.html http://www.ibiblio.org/g2swap/byteofpython/read/self.html webmat Python is designed to support