我今天遇到了一个有趣的问题.看看这个伪代码:
void Loop()
{
static int x = 1;
printf("%d", x);
x++;
}
void main(void)
{
while(true)
{
Loop();
}
}
Run Code Online (Sandbox Code Playgroud)
即使x是静态的,为什么这段代码每次只打印"1"?在打印之前,我在每次迭代时将x重新初始化为1.但无论出于何种原因,x按预期递增.
我真的很想成为一个认真的程序员,人们钦佩黑客的类型,而不是一个甚至无法完成FizzBuzz的企业无人机.
目前我已经掌握了几种语言,我的大多数经验都是在Perl和Shell中,而且我在Ruby中略微涉足过.
但是,我不禁觉得虽然我知道一点点语言,但我不知道如何编程.
我真的不急于立即学习一种能让我找到工作的语言(虽然我很快就会这样做),而且我正在考虑使用PLT Scheme(现在称为Racket)来完成如何设计程序或计算机程序的结构和解释,本质上是计划经典之一,因为我一直听说他们教人们如何编写高质量,可用,可读的代码.
然而,即使麻省理工学院也将其入门课程从使用SICP和Scheme改为使用Python.
所以,我在这里要求许多有经验的程序员提供有关以下内容的圣人建议:
谢谢,抱歉漫无边际.
我被告知不要担心保留计数.我明白我不应该决定release或retain使用基于条件逻辑retainCount,但我不应该担心吗?我认为这些以某种方式对应于内存使用.
例如,如果我有一堆子视图UIView,我也已经放入了NSArray能够迭代它们,那么这不会使保留计数加倍,从而使应用程序的内存使用量增加一倍吗?如果是这样,如果子视图是500个UIControl实例,这是否代价高昂或微不足道?当然,这假设我需要500个实例.
和朋友一起,我们最近遇到了以下问题.有一个基类:
class A {
public:
A() : foo(10) {}
virtual int getFoo() const { return foo; }
protected:
int foo;
};
Run Code Online (Sandbox Code Playgroud)
一位朋友实现了一个源自上面的类.
class B : public A {
public:
void process() { foo = 666; }
protected:
//int foo;
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,他还在后代课程中添加了字段foo(注释行).所以下面的代码.
#include <iostream>
int main()
{
A* aaa= NULL;
if (1) {
B* bbb = new B;
bbb->process();
aaa = bbb;
}
std::cout << aaa->getFoo() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
印刷10.
这不是问题,因为这将完全重新设计,并且将来不会发生这样的事情.
我只是想知道,你知道任何(便携式)技巧或语言模式(除了明显的getter/setter;顺便说一下,他们实际上是foo …
我试图将一个项目转换为一个maven ...它的.java文件位于/ src/main/java之外的其他位置,当我运行maven install时,所有文件(.hbm,.xml)除了那些.class发生在我的罐子里.
这是pom.xml的构建部分:
<build>
<resources>
<resource>
<directory>${basedir}/src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<compilerVersion>1.5</compilerVersion>
<compilerArguments>
<encoding>UTF-8</encoding>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我的jar中缺少.class文件...并且控制台上没有显示错误消息,是否需要将它们移动到/ src/main/java包结构?
还有,这种行为可能是什么原因,一些缺少依赖性?
我做了一个改变,将它们移动到src/main/java,我在控制台上得到了一些例外,但如果我"必须"将它们添加到这个"src/main/java"结构中,我仍然感到困惑......
请给我一个关于这个的想法......
谢谢
我的MySQL语句有问题.我需要一个查询来计算用户创建的注释数量和主题数量.我的表结构是这样的:
Table 'users'
-------------
user_id
user_name
...
Table 'topics'
--------------
topic_id
topic_user_id
...
Table 'topiccomments'
---------------------
topiccomment_id
topiccomment_user_id
...
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经能够生成此查询:
SELECT
u.user_id,
u.user_name,
COUNT(t.topic_user_id) as topic_count,
COUNT(tc.topiccomment_user_id) as topiccomment_count
FROM
users as u
JOIN topiccomments as tc ON u.user_id = tc.topiccomment_user_id
JOIN topics as t ON u.user_id = t.topic_user_id
WHERE
u.user_id = t.topic_user_id AND
u.user_id = tc.topiccomment_user_id
GROUP BY
u.user_id
Run Code Online (Sandbox Code Playgroud)
执行此查询,但'topic_count'和'topiccomment_count'值完全错误,我不太明白为什么.
我希望有人可以帮助我吗?
好吧,我需要将DateTime.Now绑定到TextBlock,我使用了:
Text="{Binding Source={x:Static System:DateTime.Now},StringFormat='HH:mm:ss tt'}"
Run Code Online (Sandbox Code Playgroud)
现在,如何强制更新?它是控制加载的时间,不会更新它...
在我们的ASP.NET应用程序访问内部Web服务上运行压力测试后,我们的中间层服务器(我们托管ASMX .NET 3.5 Web服务)显示接近1GB的内存消耗.
在检查来自中间层服务器的内存转储后,我发现了Web服务运行时本身引用的1000多个Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer对象.
这与我们的自定义对象如何在Web服务层中进行序列化/反序列化有关吗?任何人都可以对此有所了解吗?
当我做了!gcroot这些1000个对象中的一些时,我得到了以下描述:(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Storage.ConfigurationChangeFileWatcher) - > 1c4bb450(System.Threading.Thread) - > 18236aa0(System.Runtime .Remoting.Contexts.Context) - > 18236914(System.AppDomain) - > 10409dc4(System.ResolveEventHandler) - > 10409494(System.Web.Compilation.BuildManager) - > 10409f30(System.Web.Compilation.MemoryBuildResultCache) - > 103d115c (System.Web.Caching.CacheMultiple) - > 103d1174(System.Object []) - > 103d2034(System.Web.Caching.CacheSingle) - > 103d2080(System.Collections.Hashtable) - > 1c24b97c(System.Collections.Hashtable + bucket []) - > 1c24b934(System.Web.Caching.CacheEntry) - > 18363994(System.Web.Services.Protocols.SoapServerType) - > 183639c4(System.Collections.Hashtable) - > 1c24aa5c(系统.Collections.Hashtable + bucket []) - > 1c24a458(System.Web.Services.Protocols.SoapServerMethod) - > 1c248ae4(Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer26)
(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Storage.ConfigurationChangeFileWatcher) - > 1c5ac4b0(System.Threading.Thread) - > 1c52b5f0(System.Runtime.Remoting.Contexts.Context) - > 1c52b464(System.AppDomain) - > 18823880 …
我目前正在使用SAXParser与SAXParserFactory,我遇到了一个问题,字符串被'&'符号切断.例如:"国家创造了我们的世界及其中的一切"成为"其中的一切".
显然,我不希望这种情况发生.在xml输入中,角色被正确转义为&.我该如何解决这个问题?
try{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader r = sp.getXMLReader();
//This handles the xml and populates the entries array
XMLHandler handler = new XMLHandler();
// register event handlers
r.setContentHandler(handler);
String url = "http://foobar.xml";
r.parse(url);
return handler.getEntries();
}
Run Code Online (Sandbox Code Playgroud)
我在我的DefaultHandler类中有这个
....
public void characters( char ch[], int start, int length ){
String value = new String( ch , start , length );
if(!value.trim().equals("")) {
if( …Run Code Online (Sandbox Code Playgroud) 我从来没有正确理解finally语句的用法.谁能告诉我两者之间的区别是什么:
try {
a;
block;
off;
statements;
} catch (Exception e) {
handle;
exception;
e;
} finally {
do;
some;
cleanup;
}
Run Code Online (Sandbox Code Playgroud)
一方面和:
try {
a;
block;
off;
statements;
} catch (Exception e) {
handle;
exception;
e;
}
do;
some;
cleanup;
Run Code Online (Sandbox Code Playgroud)
在另一