混合两种或多种语言(例如Java和C ++)时组织源代码库 [英] Organizing the source code base when mixing two or more languages (like Java and C++)

查看:123
本文介绍了混合两种或多种语言(例如Java和C ++)时组织源代码库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我不得不将C ++文件引入Java项目时遇到了一个问题.最初需要测量Java进程的CPU使用率,因此决定了使用JNI调用以C语言编写的本机库(Unix计算机上的共享库)的方法.问题是找到合适的位置将C文件放置在仅包含Java文件的源存储库中(顺便说一下Clearcase).

I ran into a problem a few days ago when I had to introduce C++ files into a Java project. It started with a need to measure the CPU usage of the Java process and it was decided that the way to go was to use JNI to call out to a native library (a shared library on a Unix machine) written in C. The problem was to find an appropriate place to put the C files in the source repository (incidentally Clearcase) which consists of only Java files.

我想到了几种选择:

(a)创建一个单独的目录,用于将C文件(特别是一个.h文件和一个.c文件)放在源库的顶部,例如:

(a) Create a separate directory for putting the C files (specifically, one .h file and one .c file) at the top of the source base like:

/vobs/myproduct/javasrc /vobs/myproduct/cppsrc

/vobs/myproduct/javasrc /vobs/myproduct/cppsrc

我不喜欢这样,因为我只有两个C文件,在这样的语言级别拆分源库似乎很奇怪.如果该项目的大部分内容或多或少都是用C ++和Java编写的,那就可以了.

I didn't like this because I have only two C files and it seemed very odd to split the source base at the language level like this. Had substantial portions of the project been written more or less equally in C++ and Java, this could be okay.

(b)将C文件放入使用它的Java包中.

(b) Put the C files into the Java package that uses it.

我在/vobs/myproduct/com/mycompany/myproduct/util/中有调用Java类,并且C文件也放在其中.

I have the calling Java classes in /vobs/myproduct/com/mycompany/myproduct/util/ and the C files also go in there.

我也不喜欢这样做,因为我认为C文件不属于Java包.

I didn't like this either because I think the C files just don't belong in the Java package.

有人以前解决过这样的问题吗?通常,在组织混合两种或多种语言的代码库时,遵循什么好的策略?

Has anybody solved a problem like this before? Generally, what's a good strategy to follow when organizing codebase that mixes two or more languages?

更新:我没有计划在项目中使用任何C或C ++,也许有一些Jython,但您永远不知道我的客户何时需要只能使用C才能解决的功能,或者只能使用C来解决的功能

Update: I don't have any plan to use any C or C++ in my project, some Jython perhaps, but you never know when my customers need a feature that can be solved only by using C or best solved by using C.

推荐答案

我不喜欢这样,因为我只有两个C文件,并且在这样的语言级别拆分源库似乎很奇怪"

为什么看起来很奇怪?考虑这个项目:

Why does it seem odd? Consider this project:


  project1\src\java
  project1\src\cpp
  project1\src\python

或者,如果您决定将其拆分为模块:

Or, if you decide to split things up into modules:


  project1\module1\src\java
  project1\module1\src\cpp
  project1\module2\src\java
  project1\module2\src\python

我认为这是个人喜好的问题,但是上述结构相当普遍,而且一旦您习惯了,我认为它的效果会很好.

I guess it's a matter of personal taste, but the above structure is fairly common, and I think it works quite well once you get used to it.

这篇关于混合两种或多种语言(例如Java和C ++)时组织源代码库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆