在Java和Python世界中,您查看源文件并知道所有导入的来源(即您知道在哪个文件中定义了导入的类).例如:
在Java中:
import javafoo.Bar;
public class MyClass {
private Bar myBar = new Bar();
}
Run Code Online (Sandbox Code Playgroud)
您立即看到Bar-class是从javafoo导入的.因此,Bar被宣布进入/javafoo/Bar.java
在Python中
import pythonbaz
from pythonfoo import Bar
my_bar = Bar()
my_other = pythonbaz.Other()
Run Code Online (Sandbox Code Playgroud)
很明显,Bar来自pythonfoo包,而Other显然来自pythonbaz.
在C#中(如果我错了,请纠正我):
using foo
using baz
using anothernamespace
...
public class MyClass
{
private Bar myBar = new Bar();
}
Run Code Online (Sandbox Code Playgroud)
两个问题:
1)我如何知道Bar-class的声明位置?它来自命名空间foo,或者bar,还是anothernamespace?(编辑:不使用Visual Studio)
2)在Java中,包名称对应于目录名称(或者,它是一种非常强大的约定).因此,当您看到类来自哪个包时,您就知道它在文件系统中的目录.
在C#中,似乎没有命名空间的这种约定,或者我错过了什么?那么,我如何知道要查看的目录和文件(没有Visual Studio)?(在确定该类来自哪个命名空间之后).
编辑澄清:我知道Python和/或Java允许通配符导入,但这些语言中的"文化"对它们不满(至少在Python中,在Java中我不确定).此外,在Java IDE中通常可以帮助您创建最小的导入(如下面的Mchl.)
我想开发一个小型/中型跨平台应用程序(包括GUI).
我的背景:主要是带有MVC架构的Web应用程序,包括Python(Pylons + SqlAlchemy)和Java(熟悉语言,但不太喜欢它).我也知道一些C#.到目前为止,我没有GUI编程经验(Windows Forms,Swing和QT).
我计划使用SQLite进行数据存储:它似乎是一个很好的跨平台解决方案,并且具有一些强大的功能(例如,SQL Server Compact缺少的全文搜索).
我做了一些研究,这些是我最喜欢的选择:
1)QT,Python(PyQT或PySide)和SQLAlchemy
优点:
缺点:
2).NET/Mono,Windows Forms,C#,(流畅)NHibernate,System.Data.SQLite
优点:
缺点:
3)JVM,Java + Jython,Swing,SQLAlchemy
(我在情感上偏向于这个,但为了完整性而列出)
优点:
缺点:
(我排除的选项......只是为了避免讨论这些):
- wxWidgets/wxPython(现在QT是LGPL)
- GTK/PyGTK
最终应用程序的外观对我来说非常重要.上面的技术堆栈是非常不同的(PyQT,.NET WinForms,JVM Swing),需要一些时间才能熟练,所以:
您会推荐哪种替代方案?为什么?
我想从Gradle为我的JPA类启用Eclipselink的静态编织.Eclipselink文档解释了如何在Ant任务中执行此操作:
<target name="define.task" description="New task definition for EclipseLink static weaving"/>
<taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/>
</target>
<target name="weaving" description="perform weaving" depends="define.task">
<weave source="c:\myjar.jar"
target="c:\wovenmyjar.jar"
persistenceinfo="c:\myjar-containing-persistenceinfo.jar">
<classpath>
<pathelement path="c:\myjar-dependent.jar"/>
</classpath>
</weave>
</target>
Run Code Online (Sandbox Code Playgroud)
现在我有两个问题:
1.我如何将其"翻译"为Gradle方法? 我试过这个(基于http://www.gradle.org/docs/current/userguide/ant.html#N1143F上的文档):
task eclipseWeave << {
ant.taskdef(name: "weave",
classname: "org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask",
classpath: configurations.compile.asPath)
ant.weave(source: relativePath(compileJava.destinationDir),
target: relativePath(compileJava.destinationDir),
persistenceinfo: relativePath(processResources.destinationDir) {
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是类路径似乎不起作用ant.weave(..).编织过程在消息输入后中止:
Execution failed for task ':eclipseWeave'.
> java.lang.NoClassDefFoundError: some/class/from/my/dependencies
Run Code Online (Sandbox Code Playgroud)
类路径设置适用ant.taskdef(..)于我的依赖项中的StaticWeaveAntTask.我怎样才能让它适用于ant.weave(..)自己?
2.如何将其集成到我的构建中,以便在每个compileJava步骤后自动执行?
我正在尝试使用图形聚类算法在Rust中工作.部分代码是WeightedGraph具有邻接列表表示的数据结构.核心将像这样表示(在Python中显示,以明确我正在尝试做什么):
class Edge(object):
def __init__(self, target, weight):
self.target = target
self.weight = weight
class WeightedGraph(object):
def __init__(self, initial_size):
self.adjacency_list = [[] for i in range(initial_size)]
self.size = initial_size
self.edge_count = 0
def add_edge(self, source, target, weight):
self.adjacency_list[source].append(Edge(target, weight))
self.edge_count += 1
Run Code Online (Sandbox Code Playgroud)
因此,邻接列表包含一个数组n数组:图中每个节点一个数组.内部数组保存该节点的邻居,表示为Edge(target节点号和双精度数weight).
我将整个事情翻译成Rust的尝试看起来像这样:
struct Edge {
target: uint,
weight: f64
}
struct WeightedGraph {
adjacency_list: ~Vec<~Vec<Edge>>,
size: uint,
edge_count: int
}
impl WeightedGraph {
fn new(num_nodes: uint) -> WeightedGraph { …Run Code Online (Sandbox Code Playgroud) java ×3
c# ×2
python ×2
ant ×1
eclipselink ×1
gradle ×1
graph ×1
namespaces ×1
packages ×1
rust ×1