使开发人员能够构建包含私有数据的系统的当前做法是什么?对于那种事情,任何人都可以指出"最佳实践"指南吗?
我们在这里有一个Catch-22,开发人员需要编写与那些被认为是"私有"的系统相对应的应用程序.IT管理部门希望我们的开发人员无法访问数据(即提供模式或数据结构,而不是数据本身),而大多数开发人员(包括我自己)希望能够访问生产数据,因为没有代表性数据集可能导致错误的假设(例如,数据格式)和稍后的错误.
有没有人对这类事情有任何正式的"最佳实践"?特别是来自某些"BigCo"(例如微软,IBM)的官方公会可能会有所帮助,因为需要说服管理层.
我想知道,初始化对象时附加括号的意义是什么.例如:
var foo = function(){ ... }();
Run Code Online (Sandbox Code Playgroud)
与
var foo = (function(){ ... }());
Run Code Online (Sandbox Code Playgroud)
我假设与范围相关的东西,但我想知道是否有人可以更精确地了解具体的差异,因为他们似乎都基于每个匿名函数返回的内容初始化对象.
我想做类似以下的事情:
def add(a, b):
#some code
def subtract(a, b):
#some code
operations = [add, subtract]
operations[0]( 5,3)
operations[1](5,3)
Run Code Online (Sandbox Code Playgroud)
在python中,是否可以分配类似函数指针的东西?
如何选择样式列表框,使选择的文本颜色与默认视图不同?我在几个方面看过这个,因为ContentPresenter缺少Foreground属性.
列表框的默认控件模板提供了几个可用于调整高亮颜色的矩形.例如,对于默认样式,名为BGColor3的矩形调整其不透明度以获得高光效果.
以下是我的控件模板的大部分内容:
<Grid>
<Rectangle x:Name="BGColor2" Fill="{StaticResource HoverBrush}" Stroke="Black" StrokeThickness="1" Opacity="0"/>
<Rectangle x:Name="BGColor3" Fill="{StaticResource ListboxHighlightBrush}" StrokeThickness="0" Opacity="0"/>
<Rectangle x:Name="BGColor" Stroke="Black" StrokeThickness="0" Opacity="0.2" Fill="{TemplateBinding Background}"/>
<Border Height="20">
<ContentPresenter HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
<Rectangle Fill="Blue" Opacity="0.4" x:Name="FocusVisual" Stroke="#BF313131" Margin="1" StrokeThickness="1" StrokeDashArray="1 2" StrokeDashCap="Square" Visibility="Collapsed" />
<Rectangle x:Name="BorderRect" Stroke="Black" StrokeThickness="1" Opacity="0.3" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
在选择视觉状态,这里是要点:
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BGColor2" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.8"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
Run Code Online (Sandbox Code Playgroud)
显而易见的是BGColor2正在修改矩形(不透明度),以便所选项目具有背景.很公平.在故事板的这一部分中,无论如何都可以访问ContentPresenter或其他类似的东西并切换文本前景色?
脚注:简单地使用不同的模板与视觉状态转换不是更清晰吗?
----给出第一个答案后补充----
使用TextBlock 几乎 …
嘿大家,在下面的代码中,d的结果应该在第二个表达式之后是什么?
int d = 1;
d += d++;
Run Code Online (Sandbox Code Playgroud)
之后假设d为3,但是一元增量d ++似乎没有生效,d保持值为2.
这个bug有名字吗?是否存在支持C#等一元增量的其他编译器?
如果您使用应用,在单独的线程中编辑共享首选项是多余的吗?
我在 MainActivity 的 onCreate 方法中有以下代码块:
final MainActivity activityReference = this;
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
// if it is the first time running
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activityReference);
if(!prefs.getBoolean(MainActivity.FIRST_LOAD, false)) {
// enable a setting on first run
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(MainActivity.FIRST_LOAD, true);
editor.apply();
}
}
});
Run Code Online (Sandbox Code Playgroud)
因为 SharedPreferences.Editor 的实例正在调用 apply 方法,它应该是异步的,但在单独的线程中运行之前,我们仍然会违反严格模式。违规是 StrictModeDiskRead 违规,因此假设它们是由于获取 SharedPreferences 而不是调用 apply 导致的。此外,似乎三星设备几乎完全有这个问题。