我在FlexSlider中使用HTML5视频标签.有时视频停止工作.经过大量搜索后,我收到了这个错误.
GET http://studiobooth.local/app/videos/0062mParticle12151601.mp4 412 (Precondition Failed)
Run Code Online (Sandbox Code Playgroud)
这是我的HTML5视频代码:
<video preload="none" src="http://studiobooth.local/app/videos/2.mp4" poster="http://studiobooth.local/app/videos/thumbs/2.jpg" controls="" loop="" style="max-width:100%;height:100%;"><source src="http://studiobooth.local/app/videos/2.mp4" type="video/mp4">Your browser does not support the video tag.</video>
Run Code Online (Sandbox Code Playgroud)
请帮我解决一下.
谢谢
我正在设计一个类似这样的API:
// Drop $howMany items from after $from
def dropElements[T](array: Array[T], from: Int, howMany: Int)
Run Code Online (Sandbox Code Playgroud)
预期的行为是howMany应该是非负的,如果howMany为零,它不应该做任何修改.我有两种方法来实现这个:
def dropElements[T](array: Array[T], from: Int, howMany: Int) {
assert(howMany >= 0);
if (howMany == 0) return;
assert(0 <= from && from < array.length);
....
}
Run Code Online (Sandbox Code Playgroud)
要么:
def dropElements[T](array: Array[T], from: Int, howMany: Int) {
assert(howMany >= 0);
assert(0 <= from && from < array.length);
if (howMany == 0) return;
....
}
Run Code Online (Sandbox Code Playgroud)
我赞成第二种方法(预先声明你的先决条件)与第一种方法相比,但有人指出,当howMany = 0时,第一种方法更加尊重要求.
language-agnostic scala api-design preconditions scala-collections
据我所知,在DbC方法中,前置条件和后置条件附加到函数中.
我想知道的是,这是否也适用于成员函数.
例如,假设我在每个公共函数末尾的开头使用不变量,成员函数将如下所示:
编辑:(清理我的例子)
void Charcoal::LightOnFire() {
invariant();
in_LightOnFire();
StartBurning();
m_Status = STATUS_BURNING;
m_Color = 0xCCCCCC;
return; // last return in body
out_LightOnFire();
invariant();
}
inline void Charcoal::in_LightOnFire() {
#ifndef _RELEASE_
assert (m_Status == STATUS_UNLIT);
assert (m_OnTheGrill == true);
assert (m_DousedInLighterFluid == true);
#endif
}
inline void Charcoal::out_LightOnFire() {
#ifndef _RELEASE_
assert(m_Status == STATUS_BURNING);
assert(m_Color == 0xCCCCCC);
#endif
}
// class invariant
inline void Charcoal::invariant() {
assert(m_Status == STATUS_UNLIT || m_Status == STATUS_BURNING || m_Status == STATUS_ASHY);
assert(m_Color == 0x000000 …Run Code Online (Sandbox Code Playgroud) design-by-contract invariants member-functions preconditions
我有一些开发人员经常把If If检查
例如:
Run(Order order)
{
if (order == null) return;
}
Run Code Online (Sandbox Code Playgroud)
在他们的代码中,因为他们认为如果有人传入一个null参数,他们就会保护他们的类.我想告诉他们的缺陷在他们的逻辑,因为如果有人传入null在这种情况下,最有可能的问题与消费者的代码,而是这个类的抛出异常和故障的快速,它优雅地处理的不良行为消费者并继续努力.
另一个建议是让前提条件或防护类快速失败并抛出异常.任何事情,但忽略了消费者可能有一些其他问题的事实,我帮助掩盖它.
我如何让人们欣赏你的班级不应该如此宽容的事实.如果有人没有传递好的数据,应该告诉他们.
任何好的文章或建议,以帮助我理解这一点?
我正在学习先决条件以及何时使用它们。有人告诉我,前提条件是
@pre fileName must be the name of a valid file
Run Code Online (Sandbox Code Playgroud)
不适合以下代码:
/**
Creates a new FileReader, given the name of file to read from.
@param fileName- the name of file to read from
@throw FileNotFoundException - if the named file does not exist,
is a directory rather than a regular file, or for some other reason cannot
be opened for reading.
*/
public FileReader readFile(String fileName) throws FileNotFoundException {
. . .
}//readFile
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
编辑:另一个例子
作为示例,我们假设以下内容是以“正确”的方式完成的。请注意 IllegalArgumentException 和前提条件。请注意如何明确定义行为,以及如何在设置前提条件的情况下进行 throws …
这是一个简单的问题,我认为这是一个复杂的答案.
一个非常常见的编程问题是返回某些内容的函数,或者无法进行前置条件检查.在Java中,我会使用一些IllegalArgumentException在方法开头抛出的断言函数,如下所示:
{
//method body
Assert.isNotNull(foo);
Assert.hasText(bar)
return magic(foo, bar);
}
Run Code Online (Sandbox Code Playgroud)
我喜欢这个是它是每个先决条件的oneliner.我不喜欢这个是抛出异常(因为异常~goto).
在Scala中,我使用了Either,它有点笨重,但比抛出异常更好.
有人向我建议:
putStone stone originalBoard = case attemptedSuicide of
True -> Nothing
False -> Just boardAfterMove
where {
attemptedSuicide = undefined
boardAfterMove = undefined
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢的是强调真假,这本身就没有任何意义; 的attemptedSuicide前提是藏在语法之间,所以没有明确相关的任何操作,实际执行的putStone(boardAfterMove)是没有明确的核心逻辑.要启动它不会编译,但我确信这不会破坏我的问题的有效性.
在Haskell中可以干净地完成前置条件检查的方法是什么?
是否有可能在YAML中使用Precondition我没有找到除此页面之外的任何来源http://www.liquibase.org/documentation/yaml_format.html
但我正在寻找相当于:
<changeSet id="addColumn-example">
<preConditions onFail="MARK_RAN">
<columnExists schemaName="earls"
tableName="category" columnName="display_name"/>
</preConditions>
<dropColumn columnName="display_name" schemaName="earls" tableName="category"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
所以我的自然翻译将是:
changeSet:
id: addColumn-example
author: francis
preConditions:
- columnExist:
schemaName: earls
tableName: category
columnName: display_name
changes:
- addColumn:
columns:
- column:
name: display_name
type: varchar(100)
Run Code Online (Sandbox Code Playgroud)
但是我失踪了...
为什么Google Precondition库中的check*方法采用Object而不是String?我可以看到该对象被称为String.valueOf()on.我认为这个设计是由于没有代表客户做出任何假设.但我无法考虑一个合理的情况,客户端将使用除String之外的任何东西来调用它.
我猜客户端可以传递一个实现了toString()方法的对象.但是你能给出一个关于如何使用它/你一直在使用它的真实世界的例子吗?
在我们的代码中,我们经常检查参数Preconditions:
Preconditions.checkArgument(expression, "1" + var + "3");
Run Code Online (Sandbox Code Playgroud)
但有时,这个代码经常被调用.这会对性能产生显着的负面影响吗?我们应该切换到
Preconditions.checkArgument(expression, "%s%s%s", 1, var, 3);
Run Code Online (Sandbox Code Playgroud)
?
(我希望大多数情况下条件都是正确的.假意味着错误.)
我喜欢番石榴的前提条件,但我真正需要的是另外一种方法 - 检查数字是否在范围内.像这样的Smt
//probably there should be checkStateInRange also
public static void checkArgumentInRange(double value, int min, int max) {
if (value < min || value > max) {
throw new IllegalArgumentException(String.format("%s must be in range [%s, %s]", value, min, max));
}
}
Run Code Online (Sandbox Code Playgroud)
我相信我并不孤单,这是一个很常见的情况.但这种方法不存在.有没有理由不把这些方法放进去com.google.common.base.Preconditions?
preconditions ×10
java ×4
guava ×3
api-design ×1
c# ×1
exception ×1
file ×1
gwt ×1
haskell ×1
html5-video ×1
invariants ×1
liquibase ×1
performance ×1
scala ×1
xml ×1
yaml ×1