答:
It is not consistent with OOP philosophy that a program would be an object from an OS process point of view, as there is no way to have more than one by definition.

On top of that, a constructor isn't an entry point by any means.

It seems to me like the most reasonable choice to have main as a static function, which it actually is at the end of the day. Given the architecture of VMs such as JVM and CLR, any other choice would be unnecessarily pushing it.

Title: Why a static main method in Java and C#, rather than a constructor?

Body:
I’m Looking for a definitive answer from a primary or secondary source for why (notably) Java and C# decided to have a static method as their entry point, rather than representing an application instance by an instance of an Application class (with the entry point being an appropriate constructor).

Background and details of my prior research

This has been asked before. Unfortunately, the existing answers are merely begging the question. In particular, the following answers don’t satisfy me, as I deem them incorrect:

There would be ambiguity if the constructor were overloaded. – In fact, C# (as well as C and C++) allows different signatures for Main so the same potential ambiguity exists, and is dealt with.

A static method means no objects can be instantiated before so order of initialisation is clear. – This is just factually wrong, some objects are instantiated before (e.g. in a static constructor).

So they can be invoked by the runtime without having to instantiate a parent object. – This is no answer at all.

Just to justify further why I think this is a valid and interesting question:

Many frameworks do use classes to represent applications, and constructors as entry points. For instance, the VB.NET application framework uses a dedicated main dialog (and its constructor) as the entry point1.

Neither Java nor C# technically need a main method. Well, C# needs one to compile, but Java not even that. And in neither case is it needed for execution. So this doesn’t appear to be a technical restriction. And, as I mentioned in the first paragraph, for a mere convention it seems oddly unfitting with the general design principle of Java and C#.

To be clear, there isn’t a specific disadvantage to having a static main method, it’s just distinctly odd, which made me wonder if there was some technical rationale behind it.

I’m interested in a definitive answer from a primary or secondary source, not mere speculations.

1 Although there is a callback (Startup) which may intercept this.


问:
.NET silverlight development tools
What tools are necessary when developing efficiently with Silverlight 4? VS 2010 is a gimme, but what version? Is Pro enough? Premium? What about Expression Blend/Web/Both?

When considering VS 2010, premium comes with an MSDN subscription but it's at the high end of the budget. It makes sense if Expression comes with it though.

It's for a one man development show, making an LOB app that will integrate video/audo and mic/webcam equipment.

答: If you can afford it I would definitely recommend VS2010 Premium w/ MSDN, which therefore gives you access to Blend.  Using Silverlight from a developer perspective, I find that some things are easier to accomplish in VS2010, and some things are easier in Blend.  In fact some things are just impossible through the VS2010 designer that are trivial in Blend.  Knowing and using both definitely gives you an advantage.</p>

ContentLicense: CC BY-SA 2.5

Title: .NET silverlight development tools


问:
Should programming languages be strict or loose?
In Python and JavaScript, semi-colons are optional.

In PHP, quotes around array-keys are optional ($_GET[key] vs $_GET['key']), although if you omit them it will first look for a constant by that name. It also allows 2 different styles for blocks (colon, or brace delimited).

I'm creating a programming language now, and I'm trying to decide how strict I should make it. There are a lot of cases where extra characters aren't really necessary and can be unambiguously interpreted due to priorities, but I'm wondering if I should still enforce them or not to encourage consistency.

What do you think?

Okay, my language isn't so much a programming language as a fancy templating language. Kind of a cross between Haml and Django templates. Meant to be used with my C# web framework, and supposed to be very extensible.

答:
I would suggest that a good programming language should have strict rules, which implementations would be expected to enforce consistently, but the rules should be written in such fashion so as to be helpful.  I would further suggest that one should consider designing a language to avoid cases where the "Hamming distance" between two substantially-different programs is only one.  Obviously one can't achieve such a thing with numeric or string literals (if a programmer who meant 123 instead types 1223 or 13, the compiler can't very well know what the program meant).  On the other hand, if language were to use := for assignment and == for equality comparison, and not use a single = for any legal purpose, then would greatly reduce the possibilities both for accidental assignments which were supposed to be comparisons, and accidental do-nothing comparisons which were supposed to be assignments.

I would suggest that while there are places where it is useful for compilers to infer things, such inference is often most valuable in the simplest cases, and less valuable in the more complicated cases.  For example, allowing the replacement of:

```
  Dictionary<complicatedType1,complicatedType2> item =
    new Dictionary<complicatedType1, complicatedType2()>;
```

with

```
  var item = new Dictionary<complicatedType1, complicatedType2()>;```

does not require any complicated type inference, but makes the code vastly more readable (among other things, using the more verbose syntax only in scenarios where it's needed, e.g. because the type of the storage location doesn't precisely match the type of the expression creating it, will help call extra attention to places that may require it).

One major difficulty of attempting more sophisticated type inference is that ambiguous situations may arise; I would suggest that a good language should allow a programmer to include information to the compiler could use to either resolve such ambiguities (e.g. by regarding some typecasts as preferable to others), determine that they don't matter (e.g. because even though two possible overloads may execute different code, the programmer has indicated that they should behave identically in those cases where either could be used), or flag those (and only those) which cannot be handled in either of the above ways.

Body:
I would suggest that a good programming language should have strict rules, which implementations would be expected to enforce consistently, but the rules should be written in such fashion so as to be helpful.  I would further suggest that one should consider designing a language to avoid cases where the "Hamming distance" between two substantially-different programs is only one.  Obviously one can't achieve such a thing with numeric or string literals (if a programmer who meant 123 instead types 1223 or 13, the compiler can't very well know what the program meant).  On the other hand, if language were to use := for assignment and == for equality comparison, and not use a single = for any legal purpose, then would greatly reduce the possibilities both for accidental assignments which were supposed to be comparisons, and accidental do-nothing comparisons which were supposed to be assignments.

I would suggest that while there are places where it is useful for compilers to infer things, such inference is often most valuable in the simplest cases, and less valuable in the more complicated cases.  For example, allowing the replacement of:

  Dictionary<complicatedType1,complicatedType2> item =
    new Dictionary<complicatedType1, complicatedType2()>;

with

  var item = new Dictionary<complicatedType1, complicatedType2()>;

does not require any complicated type inference, but makes the code vastly more readable (among other things, using the more verbose syntax only in scenarios where it's needed, e.g. because the type of the storage location doesn't precisely match the type of the expression creating it, will help call extra attention to places that may require it).

One major difficulty of attempting more sophisticated type inference is that ambiguous situations may arise; I would suggest that a good language should allow a programmer to include information to the compiler could use to either resolve such ambiguities (e.g. by regarding some typecasts as preferable to others), determine that they don't matter (e.g. because even though two possible overloads may execute different code, the programmer has indicated that they should behave identically in those cases where either could be used), or flag those (and only those) which cannot be handled in either of the above ways.

ContentLicense: CC BY-SA 3.0


问:
User management data - the need for a username and password
I would have this asked on StackOverflow if it had code, but it's more on the idea/concept so I asked here.

I am working on the UI of our inventory system when I found out that when registering a user in the system, the username and password of the user is optional. I asked our supervisor why is this so. He said that in the system, there are "bins of assets" (think of boxes with toys) where we assign through the system employees to handle these bins. Employees must be registered in the system but some of them are not given access to the system, therefore there is no use giving them usernames and passwords.

But I think his argument is wrong, really wrong because every time I hear "no username no password" makes me cringe as it is most synonymous to a no-password, free-to-access account.

And so I ask:

What would be the correct database design to separate this system-user employee and non-system-user employee that does not use this no username, no password scheme?

Currently, as the description implies, we have a single table with uid, username, hashed password and other fields with additional user data.

To prove to him a point, I would like to know why storing a blank username and password for an account is totally wrong for non-system-user registered employee.

What are alternatives to having this system? I know it's best to keep in one table the registered users but I have never seen this situation where there are registered users that don't have access to a system. It's like you are given a Facebook account, profiles and all but don't have a username and password for it (or in this case, blank)

答:
It sounds like the employees who are in the system but have no username/password are a special class of employee, let's call it "bin-handling employees" from your description: "we assign through the system employees to handle these bins".

You could move these special employees to a separate "bin-handler" table. Also, move the usernames and passwords to a table just for that. That way you can still assign these employees to bins of stuff, but they are not in the same table as the table with usernames and passwords. You could then reference the main Employee table through a foreign key.

If splitting into separate tables isn't going to work for you, you could have a "can log in" field, which tells the system if that Employee is allowed to log in, or if they only exist to be assigned to bins.


答:
I would suggest 2 separate entities - employees that can be assigned to handle bins, and registered users.

You could link the registered users to their employee records.

That way you won't have spurious employees with blank username / passwords.

Title: User management data - the need for a username and password

Body:
I would have this asked on StackOverflow if it had code, but it's more on the idea/concept so I asked here.

I am working on the UI of our inventory system when I found out that when registering a user in the system, the username and password of the user is optional. I asked our supervisor why is this so. He said that in the system, there are "bins of assets" (think of boxes with toys) where we assign through the system employees to handle these bins. Employees must be registered in the system but some of them are not given access to the system, therefore there is no use giving them usernames and passwords.

But I think his argument is wrong, really wrong because every time I hear "no username no password" makes me cringe as it is most synonymous to a no-password, free-to-access account.

And so I ask:

What would be the correct database design to separate this system-user employee and non-system-user employee that does not use this no username, no password scheme?

Currently, as the description implies, we have a single table with uid, username, hashed password and other fields with additional user data.

To prove to him a point, I would like to know why storing a blank username and password for an account is totally wrong for non-system-user registered employee.

What are alternatives to having this system? I know it's best to keep in one table the registered users but I have never seen this situation where there are registered users that don't have access to a system. It's like you are given a Facebook account, profiles and all but don't have a username and password for it (or in this case, blank)


答:
It may not be that important which way you do it, but having a user table and an employee table might make more sense.  At this moment you have employees that are not users, someday you may have users who are not employees.  Making them separate probably models the world a little bit better.

On the other hand, it may be that you can encapsulate your code such that making the change later will be easy.  In that case, you can just do the quickest thing now and worry about it when the time comes.


问:
Explanation on how "Tell, Don't Ask" is considered good OO
This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught.

Such as example #2:

Bad:

```<code>def check_for_overheating(system_monitor)
  if system_monitor.temperature > 100
    system_monitor.sound_alarms
  end
end
</code>```

versus good:

```<code>system_monitor.check_for_overheating

class SystemMonitor
  def check_for_overheating
    if temperature > 100
      sound_alarms
    end
  end
end
</code>```

The advice in C++ is that you should prefer free functions instead of member functions as they increase encapsulation. Both of these are identical semantically, so why prefer the choice that has access to more state?

Example 4:

Bad:

```<code>def street_name(user)
  if user.address
    user.address.street_name
  else
    'No street name on file'
  end
end
</code>```

versus good:

```<code>def street_name(user)
  user.address.street_name
end

class User
  def address
    @address || NullAddress.new
  end
end

class NullAddress
  def street_name
    'No street name on file'
  end
end
</code>```

Why is it the responsibility of User to format an unrelated error string? What if I want to do something besides print 'No street name on file' if it has no street? What if the street is named the same thing?

Could someone enlighten me on the "Tell, Don't Ask" advantages and rationale? I am not looking for which is better, but instead trying to understand the author's viewpoint.

答:
The real issue with your overheating example is that the rules for what qualifies as overheating are not easily varied for different systems.  Suppose System A is as you have it (temp>100 is overheating) but System B is more delicate (temp>93 is overheating).  Do you change your control function to check the type of system, and then apply the correct value?

```<code>if (system is a System_A and system_monitor.temp >100)
  system_monitor.sound_alarms
else if (system is a System_B and system_monitor.temp > 93)
  system_monitor.sound_alarms
end
</code>```

Or do you have each type of system define its heating capacity?

EDIT:

```<code>system.check_for_overheating

class SystemA : System
  def check_for_overheating
    if temperature > 100
      sound_alarms
    end
  end
end

class SystemB : System
  def check_for_overheating
    if temperature > 93
      sound_alarms
    end
  end
end
</code>```

The former way makes your controlling function get ugly as you start dealing with more systems.  The latter lets the control function be stable as time goes on.

Body:
The real issue with your overheating example is that the rules for what qualifies as overheating are not easily varied for different systems.  Suppose System A is as you have it (temp>100 is overheating) but System B is more delicate (temp>93 is overheating).  Do you change your control function to check the type of system, and then apply the correct value?

if (system is a System_A and system_monitor.temp >100)
  system_monitor.sound_alarms
else if (system is a System_B and system_monitor.temp > 93)
  system_monitor.sound_alarms
end

Or do you have each type of system define its heating capacity?

EDIT:

system.check_for_overheating

class SystemA : System
  def check_for_overheating
    if temperature > 100
      sound_alarms
    end
  end
end

class SystemB : System
  def check_for_overheating
    if temperature > 93
      sound_alarms
    end
  end
end

The former way makes your controlling function get ugly as you start dealing with more systems.  The latter lets the control function be stable as time goes on.


问:
If python compiles to assembly and an OS is written in it, will it compete favorably with C in benchmarks?
Ok, I have used the word python in the question, but it well could be language agnostic in that: If a language X has a well optimised compiler targeting assembly and an OS is written in that language, then will it compete favorably with C in benchmarks?

This comes from two conceptions I have (could be wrong):

Languages are defined by grammar rules (syntax-semantics); they themselves are independent of performance. Performance is a function of implementation.

C is often efficient because the most popular OS(es) are written in it - so limited wrapping and unwrapping - and it compiles to (these days) well optimized assembly code.

And, yes, before some of us pull out guns, I understand and appreciate that in certain situations some languages may outperform C, but by and large C does better than most languages in most situations.

答:
Instead of compiling to assembly, lets take a more practical approach (that do exist).

There are programs such as f2c and p2c that compile fortran and pascal to c.  The question is then "can these compilers write better code than you can?"  In p2c (for example), it is necessary to write additional code in C to handle string processing.

This translates to assembly too.  Any time there is something that the language is doing for you, under the covers, there is the likely hood that a programmer with understanding of the structures and algorithms necessary for that would write more compact (and faster) code in C.

(edit)

Lets consider a dynamic typed language that has strings and ints, a "+" operator that is thoroughly overloaded and a print command.

```<code>var foo = 3;
var bar = "a";
var qux = bar + foo;
print qux;
</code>```

The C version of this program would be:

```<code>#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
    int foo = 3;
    char *bar = "a";
    char qux[3];
    sprintf(qux,"%s%d",bar,foo);
    printf("%s",qux);
}
</code>```

(Yes, I know that isn't optimal and is a contrived example) Which compiles to the following assembly on my machine (gcc -S -O9 foo.c)

```<code>    .file   "foo.c"
    .section    .rodata.str1.1,"aMS",@progbits,1
.LC0:
    .string "a"
.LC1:
    .string "%s%d"
.LC2:
    .string "%s"
    .text
    .p2align 4,,15
.globl main
    .type   main, @function
main:
.LFB23:
    .cfi_startproc
    pushq   %rbx
    .cfi_def_cfa_offset 16
    movl    $3, %ecx
    movl    $.LC0, %edx
    movl    $.LC1, %esi
    xorl    %eax, %eax
    subq    $16, %rsp
    .cfi_def_cfa_offset 32
    movq    %rsp, %rdi
    .cfi_offset 3, -16
    call    sprintf
    movq    %rsp, %rsi
    movl    $.LC2, %edi
    xorl    %eax, %eax
    call    printf
    addq    $16, %rsp
    .cfi_def_cfa_offset 16
    popq    %rbx
    .cfi_def_cfa_offset 8
    ret
    .cfi_endproc
.LFE23:
    .size   main, .-main
    .ident  "GCC: (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]"
    .section    .comment.SUSE.OPTs,"MS",@progbits,1
    .string "Ospwg"
    .section    .note.GNU-stack,"",@progbits
</code>```

At this point, the question is what would it take to write a compiler that would be able to analyze the dynamic code and generate that assembly. While it might be possible with that extremely limited language, once you start adding more complexity to the language, a translation into something closer to the machine requires more and more code to handle the dynamic typing, or its own runtime (objective C takes this approach) - in either case, it will be slower than something written in C that doesn't need to have that overhead.

Or, the compiler has analyzed all the execution paths of the code (for the dynamic language) which I believe is equivalent to solving the halting problem.

Body:
Instead of compiling to assembly, lets take a more practical approach (that do exist).

There are programs such as f2c and p2c that compile fortran and pascal to c.  The question is then "can these compilers write better code than you can?"  In p2c (for example), it is necessary to write additional code in C to handle string processing.

This translates to assembly too.  Any time there is something that the language is doing for you, under the covers, there is the likely hood that a programmer with understanding of the structures and algorithms necessary for that would write more compact (and faster) code in C.

(edit)

Lets consider a dynamic typed language that has strings and ints, a "+" operator that is thoroughly overloaded and a print command.

var foo = 3;
var bar = "a";
var qux = bar + foo;
print qux;

The C version of this program would be:

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
    int foo = 3;
    char *bar = "a";
    char qux[3];
    sprintf(qux,"%s%d",bar,foo);
    printf("%s",qux);
}

(Yes, I know that isn't optimal and is a contrived example) Which compiles to the following assembly on my machine (gcc -S -O9 foo.c)

    .file   "foo.c"
    .section    .rodata.str1.1,"aMS",@progbits,1
.LC0:
    .string "a"
.LC1:
    .string "%s%d"
.LC2:
    .string "%s"
    .text
    .p2align 4,,15
.globl main
    .type   main, @function
main:
.LFB23:
    .cfi_startproc
    pushq   %rbx
    .cfi_def_cfa_offset 16
    movl    $3, %ecx
    movl    $.LC0, %edx
    movl    $.LC1, %esi
    xorl    %eax, %eax
    subq    $16, %rsp
    .cfi_def_cfa_offset 32
    movq    %rsp, %rdi
    .cfi_offset 3, -16
    call    sprintf
    movq    %rsp, %rsi
    movl    $.LC2, %edi
    xorl    %eax, %eax
    call    printf
    addq    $16, %rsp
    .cfi_def_cfa_offset 16
    popq    %rbx
    .cfi_def_cfa_offset 8
    ret
    .cfi_endproc
.LFE23:
    .size   main, .-main
    .ident  "GCC: (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]"
    .section    .comment.SUSE.OPTs,"MS",@progbits,1
    .string "Ospwg"
    .section    .note.GNU-stack,"",@progbits

At this point, the question is what would it take to write a compiler that would be able to analyze the dynamic code and generate that assembly. While it might be possible with that extremely limited language, once you start adding more complexity to the language, a translation into something closer to the machine requires more and more code to handle the dynamic typing, or its own runtime (objective C takes this approach) - in either case, it will be slower than something written in C that doesn't need to have that overhead.

Or, the compiler has analyzed all the execution paths of the code (for the dynamic language) which I believe is equivalent to solving the halting problem.


答:
I just read an article saying that llvm is designed to have a front-end for any language (ie Python) and has a common optimizer/generator.  So you could write a front-end...  So it could be as fast.  (even faster if you believe HotSpot numbers you can get even faster)

Java is actually a pretty good example.  It's normally byte-code, but there are several ways to compile it to native code.

What you might run into is the problems with accessing devices, memory management, interupts, and such without adding some system specific additions.

I think you could take Linux as an example.  There is a bunch of code that is common across platforms.  That could probably be written in anything.  But there is also system/device specific code.  That would need a more system level language.  And yes, you could probably find a way in Python to handle that.

Title: If python compiles to assembly and an OS is written in it, will it compete favorably with C in benchmarks?

Body:
Ok, I have used the word python in the question, but it well could be language agnostic in that: If a language X has a well optimised compiler targeting assembly and an OS is written in that language, then will it compete favorably with C in benchmarks?

This comes from two conceptions I have (could be wrong):

Languages are defined by grammar rules (syntax-semantics); they themselves are independent of performance. Performance is a function of implementation.

C is often efficient because the most popular OS(es) are written in it - so limited wrapping and unwrapping - and it compiles to (these days) well optimized assembly code.

And, yes, before some of us pull out guns, I understand and appreciate that in certain situations some languages may outperform C, but by and large C does better than most languages in most situations.


答: C compiles to machine, not assembly. If python, or any other language, also compiled to the machine codes, then it would be just as fast (this also depends on how well the compiler optimizes, though).</p>


问:
My coworker created a 96 columns SQL table
Here we are in 2010, software engineers with 4 or 5 years or experience, still designing tables with 96 fracking columns.

I told him it's gonna be a nightmare.

I showed him that we have to use ordinals to interface MySQL with C#.

I explained that tables with more columns than rows are a huge smell.

Still, I get the "It's going to be simpler this way".

What should I do?

EDIT *

This table contains data from sensors.

We have sensor 1 with

Dynamic_D1X

Dynamic_D1Y

[...]

Dynamic_D6X

Dynamic_D6Y

[...]

EDIT2 *

Well, I finally left that job. It is a sign when the other programmer goes dark for months at the time, it is another sign when management does not realise this is a problem

答:
Looking at the (edited) post, it's clear that this is a badly denormalized table.  What should you do?  As I see it, you've got a few options:

Scream at your coworker to learn how to do his/her/its job.  Unlikely to be productive but will probably convince other coworkers not to mess with you.  A reputation as a screaming maniac can be useful (don't ask me how I know).

Scream at boss that coworker is an idiot.  Predict disaster, then actively work to sabotage project.  Blame everything on the database design produced by incompetent coworker.  May lead directly to...

Quit.  Best if it's your idea, but #2 may lead to involuntary resignation.  Try not to scrape knees on asphalt/concrete/gravel if hurled from window by enraged boss and/or coworkers.  (Note that prior study is IMPORTANT here.  Your chances of survival decrease markedly if bosses office is above the ground floor and you find yourself being propelled bodily out the window.  Plan ahead!!)

Drink heavily - or, move to California and light up (assuming prop. 19 (or whatever) passes).  Nothing like a few shots and a doobie to improve one's outlook on one's coworkers (or so I've heard).  (Public service announcement: KIDS!  These people are professionals!  DON'T try this at home!)

Share and enjoy.


答:
I believe this is more true when writing high-level object, but less true when going down to the deeper level e.g. class library as it's impossible to write every single method to satisfy all class consumers.

For example #2, I think it is over-simplified. If we were actually going to implement this, the SystemMonitor would end up having the code for low level hardware access and logic for high level abstraction embedded in the same class.
Unfortunately, if we are trying to separate that into two classes, we would violate the "Tell, Don't ask" itself.

The example #4 is more or less the same -- it's embedding UI logic into data tier.  Now if we are going to fix what user wants to see in case of no address, we have to fix the object in data tier, and what if two projects using this same object but need to use different text for null address?

I agree that if we can implement "Tell, Don't ask" for everything, it would be very useful -- I myself would be happy if I can just tell rather than ask (and do it myself) in real life! However, as same as in the real life, the feasibility of the solution is very limited to high level classes.

Title: Explanation on how "Tell, Don't Ask" is considered good OO

Body:
This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught.

Such as example #2:

Bad:

```<code>def check_for_overheating(system_monitor)
  if system_monitor.temperature > 100
    system_monitor.sound_alarms
  end
end
</code>```

versus good:

```<code>system_monitor.check_for_overheating

class SystemMonitor
  def check_for_overheating
    if temperature > 100
      sound_alarms
    end
  end
end
</code>```

The advice in C++ is that you should prefer free functions instead of member functions as they increase encapsulation. Both of these are identical semantically, so why prefer the choice that has access to more state?

Example 4:

Bad:

```<code>def street_name(user)
  if user.address
    user.address.street_name
  else
    'No street name on file'
  end
end
</code>```

versus good:

```<code>def street_name(user)
  user.address.street_name
end

class User
  def address
    @address || NullAddress.new
  end
end

class NullAddress
  def street_name
    'No street name on file'
  end
end
</code>```

Why is it the responsibility of User to format an unrelated error string? What if I want to do something besides print 'No street name on file' if it has no street? What if the street is named the same thing?

Could someone enlighten me on the "Tell, Don't Ask" advantages and rationale? I am not looking for which is better, but instead trying to understand the author's viewpoint.


答:
Theoretically speaking, for any idealized program there will be some set of assembly instructions that is the most efficient way to enact that program.  In theory, any language could potentially be compiled to these ideal machine instructions, given a smart enough compiler.

Practically speaking, no, there is no compiler that would turn python into machine code that is as fast as an optimized C program doing the same thing.  What's more, it's unlikely that such a compiler can be written, because python doesn't have primitives for low level things like pointers.  In order to make the code optimally fast, the compiler would have to figure out the intentions of the code before it could translate it into low level commands, which is a ridiculously hard problem.

That's not to say it can't come close.  Maybe.


答:
In general, most block-structured statically-typed languages will compile into very similar machine code (most machine architectures provide support for HLL concepts like for loops and switch statements).  The problem with Python, as others have noted, is its dynamic nature.  This means more run-time checks and a bigger run-time library, which means slower execution, there's just no way around that.  The doesn't mean it's not possible to write an OS in it, but you're never going to get the raw performance that simpler languages like C or FORTRAN can provide.

What would be interesting to see would be "systems Python", with support for pointers and possibly with some restrictions on the language's dynamic features to permit more efficient compiled forms.  I'm not familiar enough with Python to know how feasible that is, but there have been similar things done before.


答:
No, it's never going to happen. Even if you performed a perfect reduction from Python to machine code, there are still things like Python creates all objects on the heap and such which must be translated for the program to execute correctly which are slower than a C program placing some or many objects on the stack. In addition, there will be dynamic types and lookups which cannot be statically inferred, for example.

It's quite impossible.


问:
When is using DI and optionally a IoC framework a step too far?
Consider a logging system - used absolutely everywhere in your codebase.

(note - logging is just an example, don't take it too literally and point me at your favourite logging system).

```<code>public interface ILogger
{
    void LogMessage(string message);
}

// Just used for testing, do nothing
public class NullLogger : ILogger
{
    public void LogMessage(string message) { }
}

public class FileLogger : ILogger
{
    public FileLogger(string fileName){...}
    public void LogMessage(string message) {
        // Log to a file here
    }
}
</code>```

No I could make every single class have ILogger in ctor or param and use some IoC framework.

Or I could just use something like

```<code>public static class Globals
{
   public static ILogger Log = new NullLogger();
}
</code>```

Use at any point by Globals.Log.LogMessage("Hello Logging World");

And at 'Compositon Root' (main entry point of program) set Globals.Log = new FileLogger("somefile.log");

Or this could be done as a Singleton of course.

When is using DI and optionally IoC a step too far? What would you do in this case?

答:
Does your app need to work? Yes? Then use DI.

Having statics makes your code troublesome to test automatically (since tests often should be run in parallel to decrease turnover time and to help verify concurrency of your code). If you can't automatically test your code, it will be more difficult to make it work properly.

Now, an IoC container is probably overkill. Personally, I've seen them cause more trouble (integration troubles, overhead of configuration) than they solved. But having at least optional DI (that maybe defaults to a static instance even) will help you avoid many problems.

If you have a quicky throw away app that doesn't really need to work completely, then sure; hack away. Otherwise, take the time to do it right.


问:
Why is it preferred to write a commit message in present tense/imperative mood?
I often read/overhear that good commit messages should be written in present tense or to use imperative mood when describing the change eg. Fix xyz instead of Fixed xyz.

What are the advantages of doing so? Are there differences between the various VCS (I mostly read these about git but that maybe because I mainly work with git)?

答:
Another angle to consider is your commit's scope and your perspective (primarily for distributed VCS)... You can create all the local history you want, but it only becomes past tense once it's merged into the primary code branch.

In other words, the project lead needs to review it, and they apply my commit to "fix YYY".  The bug itself only becomes "fixed" once someone authorative approves it and merges it in to the project.

For centralized systems, past tense seems more accurate, at least from this perspective.


问:
What is an effective git process for managing our central code library?
Quick background: we're a small web agency (3-6 developers at any one time) developing small to medium sized Symfony 1.4 sites. We've used git for a year now, but have previously used Subversion.

For the past 6 months we've put a lot of development time into a central Symfony plugin that powers our custom CMS.  This plugin includes a number of features, helpers, base classes etc. that we use to build custom functionality. This plugin is stored in git, but branches wildly as the plugin is used in various products and is pulled from/pushed to constantly.  The repository is usually used as a submodule within a major project.

The problems we're starting to see now are a large number of Merge conflicts and backwards incompatible changes brought into the repository by developers adding custom functionality in the context of their own project.

I've read Vincent Driessen's excellent git branching model and successfully used it for projects in the past, but it doesn't seem to quite apply well to our particular situation; we have a number of projects concurrently using the same core plugin while developing new features for it.

What we need is a strategy that provides the following:

A methodology for developing major features within the code repository.

A way of migrating those features into other projects.

A way of versioning the core repository, and of tracking which version each major project uses.

A plan for migrating bug fixes back to older versions.

A cleaner history that's easier to see where changes have come from.

Any suggestions or discussion would be greatly appreciated.

答:
This sounds more like a dependency management problem rather than a versioning problem.

How about using something like composer?  You define what dependencies each project uses, and which versions (ex: 1.2.x)  of those projects are acceptable.  When you update your shared components, your dependent projects will not update automatically.  You have to explicitly tell composer to update dependencies for a given project.

When you update a project's depenencies, you can ensure everything still works before you commit the dependency update.  This gives you a chance to try things out safely.

There is a lot of resourcess in the Composer docs which should point you in the right direction.


问:
GUI advice for a responsive touchscreen
I am tasked with building a piece of software that interfaces with a MySQL database, in order to allow the user to pick songs to play and que using a touch screen, and then they are shown simultaneously on a second monitor as videos.

Questions:

To allow both displays to work, would it be best to write two pieces
   of software (one for each display or just the one)

I have never written code for a touch screen (other than mobile
   development, are there certain libraries to use, how would one go
   about it)

I plan to use VLC to play the videos, is there a language that would
   be best for that

In order to create a truly stunning GUI should I use a specific
   language

If I know all the dimensions, should I worry about fluid layouts?

Sorry for the many questions, its this is my first solo commercial piece of software so I am looking to get a solid game plan.

Also I was sure if this was best suited to SO or here, so please correct me if I was wrong.

The languages I was considering were: C#, JAVA, python.

答:
This answer is .NET specific because I'm a .NET developer. I'd use C# as my language:

You can handle multiple monitors in .NET by using the Screens.AllScreens property, then finding the screen boundaries, and then positioning your app windows as necessary. That would suit you if you wanted to use a single application across two monitors (this assumes that the touchscreen would be a second or primary monitor to whatever machine you'll be running this on. Or, you could choose to build two applications and use WCF to relay commands and information back and forth. Personally I would try and build 1 single application spanning both monitors.

See item #4 - you'll need to familiarize yourself with XAML UIElements but yes, .NET fully supports touch input.

Yes, there is a .NET interface to VLC that you can use and it works very well.

To create a stunning user interface it's less about the language and more about the presentation framework. Again I'm biased, but .NET has great options for you to present with - here's a MSDN Quickstart tutorial on touch input with .NET.

And even if you know that the dimensions are going to be for your current monitor(s) you should still try to make the display fluid. What would happen if you opt to later upgrade to a larger monitor or a new touchscreen with different screen dimensions?

And one last thing to mention: if you'd like to create a killer GUI in .NET, I'd give ExpressionBlend a serious look.

Title: GUI advice for a responsive touchscreen


问:
How to handle encryption key with a large development team?
If we have a large development team, say 100, and we would like to keep our encryption key hidden from developers who are not directly involved in the encryption module/algorithm, what are some best practices to keep this key as secret as possible while still allowing for development and debugging?</p>

答:
The Apache foundation has a pretty simple yet effective way to handle this. The encryption key (or code signing cert) lives in a separate repository only accessible by the trusted and the BuildBot. When building the bits that need the key, the bot checks it out -- or more properly just downloads it -- and includes it in the appropriate place in the solution. You get change control and security while not interrupting the modern development practice.

All that said, I would address the underlying problem of not being able to fob the encryption key off to infrastructure that dev never has to see.


问:
Continuous Professional development – the best approach
From my experience in the current working environment, one's professional development is definitely in the hands of the individual.

As I see it there are several routes to the same objective based on cost, time and availability

External Offsite training Online

Training providers (itunes U,Pluralsight etc)

Books

Specialist /user groups

Specialist web sites (Channel9, stackoverflow,dnrtv,codeplex etc)

What would you consider to be the best approach (blend) to continued learning and maintaining a professional standard of work?

答:
Read! Mainly blogs in my case

Chat! Make time to discuss and validate with your peers

Seminars and workshops, instead of (rather dry and formulaic) classroom training


问:
Rails - Does using partials slow views rendering?
I'm having performance issues on a Rails 3.1.0 application, now I've done dome changes on my queries with AR and so but views still takes too many time to render, I've divided the views, loops and so, on many partials that are rendered dynamically inside views and inside other partials.

So it's a bad practice to have a large number of partials?

Should I reduce the number of partials to improve the views rendering time?

Thanks

答: Not a rails guy, but Partial Views are likely not the problem per se. Rather, it sounds like you are doing a bit of SELECT N+1. Look at things from the DB server's perspective to make sure you aren't beating it to a pulp.</p>


问:
How to port this architecture to .net?
My team is currently locked into using a tool we dislike that takes the form of a Eclipse plugin and a .jar; the plugin gives us a button to quickly run a single file's code (via invoking the main .jar and passing to it the current file). We want to move to C#.net.  Is there any way to get Visual Studio to replicate this behavior? Obviously we could put each runnable class into its own project in our solution, but that requires checking a lot of project files into source control. Ideally we'd have a main() method in each file and could tell visual studio to run just that file for development purposes, while the finished software would be run from a single entry point using command-line parameters.</p>

<p>(I don't want to give too much information here regarding the purpose of the software, so please just accept that the current setup makes a lot of sense for what we're doing and changing it too much would be rejected by management.) </p>

答: I believe that TestDriven.Net has this feature. Simply right click on a methid and then select the TestDriven.Net "test with debugger" option http://testdriven.net/quickstart.aspx</p>

Title: How to port this architecture to .net?


问:
Need some advice on CLI design, I need to provide simple but powerful command line options
I am writing a utility that runs on RHEL5 command line. I need my command line options to be simple but powerful. I looked at the various UNIX utilities to get an idea of how simple  command line utilities have to be. Do you guys suggest any documents/links that talk about command line etiquette? I am modelling my utility on top of LVM (that's all the info I can give for now). I know it's a software engineering question, but I thought it would be appropriate to post here. Please advise....

PS: I am not asking for details about getopt or command line utility parsers.....

答:
<what> <how> <which>

<what>: what you want to do. If your software does lots of different things, you might want to use different commands or command/subcommand (e.g. git pull, git push, etc.)

<how>: modifiers on what you want to do. Typically one switches/command-taking options (e.g. -s, -s <arg>). Most often used commands deserve one character identifiers- probably all commands should get long names (e.g. --short). -v/--verbose, -d/--debug, -n/--dry-run, -o/--out, -h/--help, -V/--version... there are quite a few commands which are somewhat standardized

<which> files/stuff are you operating on. - meaning stdin (or no args) should be provided if possible.

Interesting stuff:

If your command spits output, provide an option to generate machine-readable output

Use stdout/stderr correctly

Provide shell completion hooks

Provide man pages

ContentLicense: CC BY-SA 4.0


问:
Languages and frameworks to build REST services
I'm currently in the process of developing a REST service that will be consumed by an iPhone app. Basically, the service wraps existing business logic. This business logic is written in c# and I'm writing the service in c#. From a purely curious point of view (not this project) my questions are:
What other languages and frameworks exist to build REST services?
If the technology choice was open which one would you choose and why?
Can you wrap c# assemblies using non Microsoft languages? Would you ever do it? (If the development team was able to support it)</p>

答:
For REST services today, I'd seriously consider Node.js. It may be fashionable but, it has a few aspects that make it the "right tool" for the job.

First, it is designed to do this. No general purpose genericity and add-on stuff. Its designed for high-throughput, heavy I/O data manipulation. This does mean its not good for high-performance processing, but then you'll choose another tool for that, namely C/C++ and link or connect that to the node server. (which is easy BTW)

Secondly, it uses the same language as the client - you'll be writing javascript clients to access this from a web client, so keeping the server in the same language helps development productivity. Consider libraries such as restify or express that help client and server programming and you've got a REST API system in next to no time.


问:
What parts of your coding standard contribute to quality code?
In response to This Question, I ask:   What are the best parts of your coding standard?

What are the best practices that help with code quality, reliability, maintainability, readability, etc.

Please include the language, the item from the standard, and the reason it improves your code.

答:
All Languages: Write readable code instead of comments

A comment followed by a block of code can be replaced by a method which states the intent just as well as the comment, and makes the code more modular and reusable as
well.

It makes refactoring happen more often.

It helps us write simple, readable clean code. Readable code is a joy to work with.

It tends to make methods short and sweet.

It avoids comments getting out of sync with the code

It challenges you to rewrite commented code that is hard to understand.

Compare this:

```<code>public void update() {
  // Fetch the data from somewhere
  lots of lines of;
     code;
     for;
       fetching;
     data;
  from somewhere;
  // Sort the data
  more lines of;
      code;
         which sorts;
         stuff;
      around;
  a bit and then;
  // Update the database
  lines of code;
      which uses;
         some lib;
         to update;
            using iteration;
            and logic;
      the database;
  done;
}
</code>```

With this version where comments are replaced with function calls:

```<code>public void update() {
    data = fetchData();
    sorted = sortResults(data);
    updateDatabase(sorted);
}
</code>```

Body:
All Languages: Write readable code instead of comments

A comment followed by a block of code can be replaced by a method which states the intent just as well as the comment, and makes the code more modular and reusable as
well.

It makes refactoring happen more often.

It helps us write simple, readable clean code. Readable code is a joy to work with.

It tends to make methods short and sweet.

It avoids comments getting out of sync with the code

It challenges you to rewrite commented code that is hard to understand.

Compare this:

public void update() {
  // Fetch the data from somewhere
  lots of lines of;
     code;
     for;
       fetching;
     data;
  from somewhere;
  // Sort the data
  more lines of;
      code;
         which sorts;
         stuff;
      around;
  a bit and then;
  // Update the database
  lines of code;
      which uses;
         some lib;
         to update;
            using iteration;
            and logic;
      the database;
  done;
}

With this version where comments are replaced with function calls:

public void update() {
    data = fetchData();
    sorted = sortResults(data);
    updateDatabase(sorted);
}


答:
While I don't think you have given enough information about the hardware and environment settings to get good answers, I will go for the most portable solution possible: C++ with QT.

Here are the reasons:

Extremely Cross Platform, and compiles to native code.

VLC is written in C++ with QT, making it easy to write wrappers

Multi-Touch support

Fantastic GUI, which supports photoshop and gimp exports

Multi-Monitor support

MySQL Support

Fairly easy multi-threading

Open Source

Title: GUI advice for a responsive touchscreen

Body:
I am tasked with building a piece of software that interfaces with a MySQL database, in order to allow the user to pick songs to play and que using a touch screen, and then they are shown simultaneously on a second monitor as videos.

Questions:

To allow both displays to work, would it be best to write two pieces
   of software (one for each display or just the one)

I have never written code for a touch screen (other than mobile
   development, are there certain libraries to use, how would one go
   about it)

I plan to use VLC to play the videos, is there a language that would
   be best for that

In order to create a truly stunning GUI should I use a specific
   language

If I know all the dimensions, should I worry about fluid layouts?

Sorry for the many questions, its this is my first solo commercial piece of software so I am looking to get a solid game plan.

Also I was sure if this was best suited to SO or here, so please correct me if I was wrong.

The languages I was considering were: C#, JAVA, python.


问:
Parsing excel data in Java before saving it to database
I'm working on some project where I have to make a database to store data which is currently kept in Excel files, so I have to do some changes before writing the data into the database.

I'm going to read those files using Java and write them from Java into the database. Should I use Hibernate for that job? Or how else can I connect to those Excel sheets, read data in Java, and write to the database?

答:
It's possible to query Excel sheets using SQL with ODBC. The sheets are treated like tables. You can even join the sheets like you would database tables! I'd recommend you try this option first. Google java + ODBC + excel for details.

There is apache's POI libary. http://poi.apache.org/
I'm not sure if this works on the old "binary" format or just the new XML format of newer versions of excel. But I remember someone I worked with used some sort of apache libarry to work with binary-format excel sheets a few years back.

In .NET you can use the excel interop library to get the data out of the excel sheet (as well as do anything else that you could possibly do in excel).

Once you've extracted the data from excel, you can load it into the database how you normally would.


答:
LibreOffice and OpenOffice could scale you to the moon. Headless Linux-Mac-Win.
You can get the contents of spreadsheet with about 200 lines of code.

Use the OpenOffice.org (or LibreOffice) APIs to open the spreadsheet files, access the data, perform the transformations, and then write the proper data into the new database.

As long as your are not trying to do fancy things like inserting and updating formulas it's very simple and cross platform and because it's open source you can rack as many instances as you need. It opens up xls files by converting them to oxd. In Linux you can run in headless mode and if you multi procs you can startup multi OpenOffice daemons to process multi docs at once. It's not marketed much as the "pro" solution, many instantly frown down on it. But I spent many years working on it starting from 2003 building a platform that printed millions impressions a year and 90% of the code is still running.

We started the implemention with 1.0 and as of last year they are using 3.x version. We didn't have to upgrade any code to adjust for the upgrade. You don't need any other XML API that's version-dependent you won't need to worry about comparability Open Office 3.x will open 97-2007 xls. I recommend this because I was a Platfrom R&D analyst and Java dev. for 8 years and I spent better part of three years researching this solution agents others.

Title: Parsing excel data in Java before saving it to database

Body:
I'm working on some project where I have to make a database to store data which is currently kept in Excel files, so I have to do some changes before writing the data into the database.

I'm going to read those files using Java and write them from Java into the database. Should I use Hibernate for that job? Or how else can I connect to those Excel sheets, read data in Java, and write to the database?


答:
As was mentioned a little, for centralized versioning systems, past tense seems more accurate (Ex: Fixed the looping issue). Because, it expressed the committed and completed work.

Otherwise, it would sound like TODO List (Ex: Fix the looping issues), that needs to be done in near future.

Title: Why is it preferred to write a commit message in present tense/imperative mood?

Body:
I often read/overhear that good commit messages should be written in present tense or to use imperative mood when describing the change eg. Fix xyz instead of Fixed xyz.

What are the advantages of doing so? Are there differences between the various VCS (I mostly read these about git but that maybe because I mainly work with git)?


答:
```<code>> using DI and optionally a IoC framework [is] a step too far
</code>```

if you

don't want to do automated (unit-)testing and if you

don't have separate components of the app (i.e. dlls) that should be changed (or recompiled) independently of the main app.

Title: When is using DI and optionally a IoC framework a step too far?

Body:
Consider a logging system - used absolutely everywhere in your codebase.

(note - logging is just an example, don't take it too literally and point me at your favourite logging system).

```<code>public interface ILogger
{
    void LogMessage(string message);
}

// Just used for testing, do nothing
public class NullLogger : ILogger
{
    public void LogMessage(string message) { }
}

public class FileLogger : ILogger
{
    public FileLogger(string fileName){...}
    public void LogMessage(string message) {
        // Log to a file here
    }
}
</code>```

No I could make every single class have ILogger in ctor or param and use some IoC framework.

Or I could just use something like

```<code>public static class Globals
{
   public static ILogger Log = new NullLogger();
}
</code>```

Use at any point by Globals.Log.LogMessage("Hello Logging World");

And at 'Compositon Root' (main entry point of program) set Globals.Log = new FileLogger("somefile.log");

Or this could be done as a Singleton of course.

When is using DI and optionally IoC a step too far? What would you do in this case?

Body:
> using DI and optionally a IoC framework [is] a step too far

if you

don't want to do automated (unit-)testing and if you

don't have separate components of the app (i.e. dlls) that should be changed (or recompiled) independently of the main app.


问:
General Architecture with Code Tables?
I've only worked at once place since graduating my CS degree. This is a pretty basic architecture question but i don't know any better since i've only worked at one place. Where i work we maintain a large number of code tables. For example say you have a Sales/Order system and you have an Order Status. We would maintain an order status table that would look like the following:

OrderStatus:

```<code>OrderStatusId(PK TinyInt)  OrderStatusDesc(VarChar(50))
1                         Created
2                         Submitted
3                         Processing
4                         Canceled
5                         Verified
6                         Complete
</code>```

We then create an enumeration off each code table. For example:

```<code>Public Enum TblSalesOrderStatus
      eosCreated = 1
      eosSubmitted = 2
      eosProcess = 3
      eosCanceled = 4
      eosVerified = 5
      eosComplete = 6
End Enum
</code>```

Then in our code we have code like the following:

```<code>If OrderStatus = eosCreated OrElse OrderStatus = eosSubmitted Then
    ...do some work
End if
</code>```

On every screen we create we have the id's stored in the controls (like comboboxes). I don't know something about this has always made me think its bad design. Maybe i'm wrong though. Especially when i started getting into REST design. i wanted to pass the Ids rather than descriptions. Of course this doesn't seem right since i'd be the only one i've ever seen pass those type of Ids in a REST service. So is this bad design?

Edit:

Trying to make thing a little clearer. Are Code Tables are only stored in two places: The Enum + The Database. When we need a new Id when email our database staff which creates a new code table value for us and emails us back the Id. When then put the new value into our enumerations. We never had problems with it getting out of sync but if we have needed either delete values or change them in the past (adding is easy) which has been pain because everything in the system had to be recompiled.

We have went down the route of trying to make things semi-dynamic (which doesn't work out in every case but helps in some). There are tons of examples but a simple example is we have a IsVisible flag in some of the code tables. If we ever want to obsolete or make one of the values not selectable then we set the IsVisible flag = 0. They prefer this compared to having to change code/compile/deploy. Thinking about it i think it would be preferable to have it in buisness logic and have test around it (which we don't :-( ) depending on your prospective.

答:
I don't know if this is officially "good" or "bad", but I have worked for a company where we used (and they use currently) this approach, with some differences:

we had one code table, and each row was identified (and indexed on) the ["code type", "code id"] pair;

there was a "master type" that described the code types themselves, so it was easy to add a new code type: added one row to the "master" code type, and the rows of the actual codes;

we had other columns in this table, so we could add external information to the codes, which was used by the actual code type handler.

It was not only useful for storing string values for code ids. For some types (data tables, GUI panels, forms, letters, ...) we put the actual handler Java class name into the code store record, and when referred to "table 42", we got an actual business logic object filled with data. Yes, Spring was not there at that time.

I think this is basically a good design, let us create a very modular system and quick prototyping. The only problem with this approach was that a part of the "system" was actually the content of a data table, which was not easy to keep in sync with the codes and app versions (we put code table dumps into the version control system, not a nice thing).

Therefore today I would not store this table in a database, but in a plain text file (json, xml, cfg, whatever), which is easy to diff(!!!) and can be stored, branched, etc. in the version control, directly linked to the sources, because their combination forms the actual deployment version of the application.

So in your case, I would also add this "master code store" containing all the other code types (if not exist yet) to centralize the type management, and perhaps would collect the many small tables into a single table, with a type column. With indexed queries, (or even: views that would make this change transparent to the existing codes!) there is practically no performance difference, but it is much easier to maintain one code table. Using the master type, you can even write a nice manager tool (as we did, and it felt good: the management of some low priority codes was delegated to the client administrators).

Also, the combo boxes don't have to "know" the actual code table, only the type id in the common table. Practically, one combo class is enough, adding a new type means using the same combo box with the new id (the int/enum conversion does not belong to the GUI element, but the control logic listening to the combo).

I would even consider to programmatically generate the enum source codes from the table. This is a repetitive task, and I think it is quite easy to make mistakes here, but not that hard to automatize. It would somehow "protect" the content of the code table as well: "touch it only if you are ready to explain why other coders have to refactor their code to use the modified enums..." :-)

About passing the ids: you are absolutely right!

Your business logic has to know that you have the value enum blahBlah in field AAA - this has a meaning in your context (the fact that field AAA uses code type 42 is also out of scope for your business logic, that is an external configuration info). The combo box is responsible for knowing that id 2 in type 42 should be displayed as "Blah blah blah", and when the user selects the string "Yippiee hoo!" it is id 6 in type 42, and should NOT know that id 6 means enum yippieeHoo for your business logic! A totally different set of responsibilities - and I have not yet mentioned language versions, what makes this even more evident ;-)

Title: General Architecture with Code Tables?


问:
Lock-free IPC in Linux for multi-core processors
I'm trying to find a way to write an application with lock-free IPC on Linux, in C, with multi-core processors.

Let's assume I have process 1 and process 2 that write to a FIFO or shared memory. Then process 3 and process 4 will read from that shared memory or FIFO.

Is this possible with a lock-free algorithm?

Your guidance is highly appreciated.

答: Inter process communication cannot be lock-free. Only inter-thread. As far as I am aware.


问:
What should be the next thing after being accepted as a contributor to an Open Source Project?
So this is the first time I am trying to work with an Open Source Project.

I created a Code Plex Account browsed for a project that I thought I might become a part of.

I sent a request to join the project.The project head accepted my request.

I have already downloaded the source code of the project.

Can some one just suggest what should I be doing next?

Since I have never worked with Open Source Projects the best thing I think for me would be to go through the code and just study it and understand how it works.

Apart from that I want to know what things many of you do when you are accepted as a contributor.

Also the project I choose to work includes ASP.NET MVC and a javascript library Raphael.js which I have no prior experience with.

So should I also start looking at it also?

Any suggestions are welcome.

答:
Get to know the code and get a overview of it. Take a look at everything, but don't spend too much time. You don't have to understand every little detail at first.

The first things I would do are bug fixes and requests. You can get to know the code pretty good by doing so.

After you did a few things, you can do bigger tasks. Why did you join the project? Where there any specific things YOU wanted to change?


答:
Thanks for willing to contribute to the open source world, but please don't ask to be a contributor if you don't know yet how to contribute.

I'm the owner of a library source code that have been written ten years ago in .NET. Despite that it is still used by thousands of companies worldwide, so I was in hope to get contributors to help with bug fixes and refactoring.

Over the last year I have accepted up to 10 new contributors request. Only one contributed so far.

His request message was a bit different. It was something like:

I have been using your library for a while now, and I'm aware of a few bugs I would like to address and I also want to extend module XXX in order to YYY because of ZZZ.

The other requests looked like (the following is an actual one):

Hi, I'm a professional .NET consultant from XXX. I'd like to give my contribute to the project.

So my advice would be to pick a project that you actually use and know how to improve it before. If you don't know what to improve first, be sure to check the source code to see if it would be actually possible for you to add value in it.

Title: What should be the next thing after being accepted as a contributor to an Open Source Project?

Body:
So this is the first time I am trying to work with an Open Source Project.

I created a Code Plex Account browsed for a project that I thought I might become a part of.

I sent a request to join the project.The project head accepted my request.

I have already downloaded the source code of the project.

Can some one just suggest what should I be doing next?

Since I have never worked with Open Source Projects the best thing I think for me would be to go through the code and just study it and understand how it works.

Apart from that I want to know what things many of you do when you are accepted as a contributor.

Also the project I choose to work includes ASP.NET MVC and a javascript library Raphael.js which I have no prior experience with.

So should I also start looking at it also?

Any suggestions are welcome.


问:
Is HTTPS enough to avoid replay attacks?
I am exposing a few REST methods on a server for an mobile app.

I would like to avoid that users can sniff how HTTP methods are built (from the mobile app) and then send them again to the server. Example :

The mobile app send a request

The user uses a proxy and can check what's going on on the network

The user sees and save the request that the mobile just sent

=> Now I don't want the user to be able to send over manually that request

Is it enough to secure the server over HTTPS?

答:
HTTPS simply means that the data being transported is encrypted so that only the client and server can decrypt it (in an ideal world, not talking about MITM attacks etc).

As such, nothing in the protocol will stop replay attacks from happening.

You will need to build in some sort of replay attack avoidance mechanism (something like expiring tokens, or tokens that invalidate after the process has finished) to ensure that your application is not vulnerable to replay attacks. This mechanism can be used with normal HTTP.


问:
What are good source control check-in strategies for large tasks?
The general rule is to keep check-ins small and check-in often. But sometimes the task requires large changes to the underlying framework. Then checking in before compeleting the task will break the project until you check in the finished work.

So what strategies do people use to reduce the risk of losing work, or deciding something you are doing is the wrong approach, then changing your mind after removing the code and trying another approach?

When I can, I'll check-in half done work commented out, or if it compiles and nothing is using new files I'll check them in. The larger the change the more likely I am to branch the project and then merge back when I have everything working again. Another option if the source control system allows is shelf sets, which are basically small branches. So when I finish for the day or come to a decision point, I'll shelve my changes, and then if something catastrophic happens, or I want to come back to that point, I can.

答:
In out team we use subversion, and we normally commit small changes directly to the trunk.  For larger tasks, the developer working on it typically creates a private branch, which is merged into the trunk once it is done.  Then the private branch is deleted.  Naturally, while the private branch exist its owner should check into it often.

We try to avoid having long-lived branches and trunk-to-branch merges, because that requires careful bookkeeping.  Instead we have relatively short-lived branches that are only merged back to the trunk once, and get deleted soon after.

And we have a rule that nothing can be committed or merged to the trunk until at least one other person looks through the changes and approves them.


问:
What limitations does the JVM impose on tail-call optimization
Clojure does not perform tail call optimization on its own: when you have a tail recursive function and you want to have it optimized, you have to use the special form recur. Similarly, if you have two mutually recursive functions, you can optimize them only by using trampoline.

The Scala compiler is able to perform TCO for a recursive function, but not for two mutually recursive functions.

Whenever I have read about these limitations, they were always ascribed to some limitation intrinsic to the JVM model. I know pretty much nothing about compilers, but this puzzles me a bit. Let me take the example from Programming Scala. Here the function

```<code>def approximate(guess: Double): Double =
  if (isGoodEnough(guess)) guess
  else approximate(improve(guess))
</code>```

is translated into

```<code>0: aload_0
1: astore_3
2: aload_0
3: dload_1
4: invokevirtual #24; //Method isGoodEnough:(D)Z
7: ifeq
10: dload_1
11: dreturn
12: aload_0
13: dload_1
14: invokevirtual #27; //Method improve:(D)D
17: dstore_1
18: goto 2
</code>```

So, at the bytecode level, one just needs goto. In this case, in fact, the hard work is done by the compiler.

What facility of the underlying virtual machine would allow the compiler to handle TCO more easily?

As a side note, I would not expect actual machines to be much smarter than the JVM. Still, many languages that compile to native code, such as Haskell, do not seem to have issues with optimizing tail calls (well, Haskell can have sometimes due to laziness, but that is another issue).

答:
Now, I don't know much about Clojure and little about Scala, but I'll give it a shot.

First off, we need to differentiate between tail-CALLs and tail-RECURSION. Tail recursion is indeed rather easy to transform into a loop. With tail calls, it's much harder to impossible in the general case. You need to know what is being called, but with polymorphism and/or first-class functions, you rarely know that, so the compiler cannot know how to replace the call. Only at runtime you know the target code and can jump there without allocating another stack frame. For instance, the following fragment has a tail call and does not need any stack space when properly optimized (including TCO), yet it cannot be eliminated when compiling for the JVM:

```<code>function forward(obj: Callable<int, int>, arg: int) =
    let arg1 <- arg + 1 in obj.call(arg1)
</code>```

While it's just a tad inefficient here, there are whole programming styles (such as Continuation Passing Style or CPS) which have tons of tail calls and rarely ever return. Doing that without full TCO means you can only run tiny bits of code before running out of stack space.

What facility of the underlying virtual machine would allow the compiler to handle TCO more easily?

A tail call instruction, such as in the Lua 5.1 VM. Your example does not get much simpler. Mine becomes something like this:

```<code>push arg
push 1
add
load obj
tailcall Callable.call
// implicit return; stack frame was recycled
</code>```

As a sidenote, I would not expect actual machines to be much smarter than the JVM.

You're right, they aren't. In fact, they are less smart and thus don't even know (much) about things like stack frames. That's precisely why one can pull tricks like re-using stack space and jumping to code without pushing a return address.

Body:
Now, I don't know much about Clojure and little about Scala, but I'll give it a shot.

First off, we need to differentiate between tail-CALLs and tail-RECURSION. Tail recursion is indeed rather easy to transform into a loop. With tail calls, it's much harder to impossible in the general case. You need to know what is being called, but with polymorphism and/or first-class functions, you rarely know that, so the compiler cannot know how to replace the call. Only at runtime you know the target code and can jump there without allocating another stack frame. For instance, the following fragment has a tail call and does not need any stack space when properly optimized (including TCO), yet it cannot be eliminated when compiling for the JVM:

function forward(obj: Callable<int, int>, arg: int) =
    let arg1 <- arg + 1 in obj.call(arg1)

While it's just a tad inefficient here, there are whole programming styles (such as Continuation Passing Style or CPS) which have tons of tail calls and rarely ever return. Doing that without full TCO means you can only run tiny bits of code before running out of stack space.

What facility of the underlying virtual machine would allow the compiler to handle TCO more easily?

A tail call instruction, such as in the Lua 5.1 VM. Your example does not get much simpler. Mine becomes something like this:

push arg
push 1
add
load obj
tailcall Callable.call
// implicit return; stack frame was recycled

As a sidenote, I would not expect actual machines to be much smarter than the JVM.

You're right, they aren't. In fact, they are less smart and thus don't even know (much) about things like stack frames. That's precisely why one can pull tricks like re-using stack space and jumping to code without pushing a return address.


答:
I have seen reference to using ring buffers, and controlled access the location pointers to eliminate or reduce the need for locks.  It does not eliminate the need for waits though, and should only work then a ring buffer has one writer and one reader.  In your case you would need at least two buffers.

The mechanism as I understand it is:

writer waits until there is an open slot (last + 1 != current)

writer writes entry in ring buffer.

writer updates last entry pointer.

reader waits until there is an available entry in the ring buffer (last != current).

reader processes entry.

reader increments current pointer.

Depending on the wait time used this can either add latency for new items in an empty queue, or burn a lot of CPU cycles in the wait loop.  The order of updating the pointer and strict separation of write access is critical for this to work.  The writer is only allowed to write the ring buffer entry before incrementing the pointer to make it available to the reader.

Title: Lock-free IPC in Linux for multi-core processors

Body:
I'm trying to find a way to write an application with lock-free IPC on Linux, in C, with multi-core processors.

Let's assume I have process 1 and process 2 that write to a FIFO or shared memory. Then process 3 and process 4 will read from that shared memory or FIFO.

Is this possible with a lock-free algorithm?

Your guidance is highly appreciated.


答:
However you learn, you should always think about works for you. What works for me may not work for you, and vice versa. Here's what works for me:

Always learn from more than one source.

Always put into practice what you're learning whilst you're learning (if that isn't possible then as soon as you can afterwards).

Try not to learn about something in isolation. Sometimes you can't avoid it, but try to understand the context in which things are done and alternative approaches. In particular try to understand the consequences (good and bad) of doing something a certain way.

Here are the sources of information that I find valuable in order of usefulness to me.

Books. For me these work really well, you're presented with a coherent (hopefully!) block of knowledge. They're easy to use, cross-reference and if you're not intending to read it cover to cover you can often pick up extra knowledge by page flicking (something I find missing from electronic resources where I find that sometimes I fall into the trap of going looking for the answer I'm expecting).

Colleagues. Probably the best way to learn about something is to work with someone who knows the topic well and is willing to share that knowledge. It can also be useful to learn with someone else who also doesn't know much - but beware of jointly coming to the wrong conclusions and developing bad practices.

Online Resources. Books can never keep up with the speed of development and discussion in the world of software development. If you want to keep up to date you need to read blogs, mailing lists and so on. You'll also got detail on topics that either aren't mainstream enough or are too narrow to have had a book out yet.

Real-world Meetups. These are things like conferences and user groups. I think these are often nice introductions to new topics and good for confirming what you already think/know about - but don't expect really in depth coverage unless the event is extremely focussed. Where the real value for me is that you often get a lot more honesty than you get from books and blogs, especially during the Q&A part.

Formal Courses. A lot of people sneer at formal courses - I suspect that's because they've not been to really good ones. Formal courses are really good when you need to get up to speed with something really new really quickly. Providing the person delivering the course knows their stuff you will also get a good feel for the thinking behind something not just the technical part.

Self-taught people (and all good programmers will be mostly self taught as soon as they're more than a couple of years out of the last course they did) tend to pick up bad habits without realising it because what they're doing has worked in the context that they're in. That knowledge tends to not hold up when put into a different context. Sometimes it doesn't matter, you just recalibrate what you've learnt, but sometimes it does.

Sadly good courses are rarely cheap and often aren't associated with any sort of certification - so picking a good course is both hard and (financially) dangerous so you could end up doing a rubbish course and having paid through the nose for it. Still, I recommend that people do a formal course every now and then to supplement self development.

Title: Continuous Professional development – the best approach

Body:
From my experience in the current working environment, one's professional development is definitely in the hands of the individual.

As I see it there are several routes to the same objective based on cost, time and availability

External Offsite training Online

Training providers (itunes U,Pluralsight etc)

Books

Specialist /user groups

Specialist web sites (Channel9, stackoverflow,dnrtv,codeplex etc)

What would you consider to be the best approach (blend) to continued learning and maintaining a professional standard of work?


问:
How to utilize Xcode project & target to manage products?
At first, hopefully following terms project and product won't be confused.

Traditionally, we used to have a code base, which usually was a main project. For our products, we created one project for each product, and these projects surly depended on main project (code base). When product was released, we created release branch for archive and maintenance.

Now I'm developing iOS applications, and I noticed there were specific terms for Xcode, project and target, which were similar to project and product. At first look, it's more easier to share configuration between products, to simplify product releases by taking advantage of target and target dependencies. Compared with traditional way, on the other hand, it's more difficult to manage source code, to branch, etc, if number of products goes really large.

In practice, is anyone efficiently using this Xcode built-in structure to manage code and products?

I'm quite new at iOS & Xcode and looking for good advice, thanks.

答:
It sounds like you're talking about using Xcode to build a Software Product Line kind of a configuration. I've done something like this before with respect to white-labelling a product - so there were no code changes between products, just different resources.

My approach would be to define a different target for each product - whether they're in the same project or not is up to you. Xcode handles dependencies across different projects quite well, so you could easily define multiple projects that state their dependencies, and use xcconfig files[*] to maintain configuration details that must be the same across all targets. It's easiest to do that from a version control perspective, to reduce the chance that people working on different products will need to edit the same project file.

Put the code that goes into all products into its own (static library) target, and include that target as a dependency of the other targets. Similarly if there are resources that are shared across all projects, create a "bundle" target that includes those shared resources.

[*] An xcconfig file is a plain text file containing Xcode build settings. If more than one of your projects contains targets that should use the same build settings, you can base those targets all on the same .xcconfig file so the settings are defined in the same place.


问:
Best practices: Ajax and server side scripting with stored procedures
I need to rebuild an old huge website and probably to port everyting to ASP.NET and jQuery and I would like to ask for some suggestion and tips. Actually the website uses:

Ajax (client site with prototype.js)

ASP (vb script server side)

SQL Server 2005

IIS 7 as web server

This website uses hundred of stored procedures and the requests are made by an ajax call and only 1 ASP page that contain an huge select case

Shortly an example:

JAVASCRIPT + PROTOTYPE:

```<code>var data = {
    action:     'NEWS',
    callback:   'doNews',
    param1:     $('text_example').value,
    ......:     ..........};
AjaxGet(data); // perform a call using another function + prototype
</code>```

SERVER SIDE ASP:

```<code><% ......
select case request("Action")
case "NEWS"
    With cmmDB
        .ActiveConnection = Conn
        .CommandText = "sp_NEWS_TO_CALL_for_example"
        .CommandType = adCmdStoredProc

        Set par0DB = .CreateParameter("Param1", adVarchar, adParamInput,6)
        Set par1DB = .CreateParameter(".....", adInteger, adParamInput)
        ' ........ ' can be more parameters

        .Parameters.Append par0DB
        .Parameters.Append par1DB

        par0DB.Value = request("Param1")
        par1DB.Value = request(".....")

        set rs=cmmDB.execute

        RecodsetToJSON rs, jsa ' create JSON response using a sub
    End With
.... %>
</code>```

So as you can see I have an ASP page that has a lot of CASE and this page answers to all the ajax request in the site.

My question are:

Instead of having many CASES is it possible to create dynamic vb code that parses the ajax request and creates dynamically the call to the desired SP (also implementing the parameters passed by JS)?

What is the best approach to handle situations like this, by using the advantages of .Net + protoype or jQuery?

How the big sites handle situation like this? Do they do it by creating 1 page for request?

Thanks in advance for suggestion, direction and tips.

答:
Your best bet is to totally forget the stored procedures, and build a standards complient .net  app.  I say it that way because I am not familiar with .NET, but it is an excellent web framework and is designed around what is loosely known as a MVC structure.

In MVC you separate your logic in three distinct components.  The view which handles display like HTML/CSS.  The AJAX blurs this a bit, but AJAX requests themselves should also follow an MVC structure.  The controller is where requests are sent.  A controller should handle a distinct request (i.e. page request).  This is where your current site is using a single point of entry which is very complex.  The MVC framework will have a router component that routes the requests to the respective controller.  The last part is the model or database. This will be classes that map to your database.  The queries will be either embedded as methods in the model or in the controller or a mix of both (rails uses a blend of both).

You would only put something in a stored procedure if it is especially complex (which can often still be done in the model), or it needs to do special handling in the db like triggers etc.  I have written some extremely complex web apps and have used stored procedures in only one of them, and in that case it was to implement some legacy data security method.

You have a lot of work ahead of you since the database was probably not designed around this style.  Don't be afraid to build views to fix some cases where the database doesn't map cleanly to your models.  If you can pull it off redesigning the database may be needed with a migration over to the new model.  That will depend on your cutover plan and if you have other systems that access the database.  The reverse view could help you with that as well.  In that case you build your new tables and make a view for the legacy apps.

Sorry I was so long winded.


问:
Good resources and tools for modern, heavy JavaScript development?
I am interested in doing some projects that involve heavy use of JavaScript. Namely HTML5 based canvas games, potentially using node.js as well. I am interested in learning modern best practices, tools and resources for JavaScript.

JavaScript is tough to research because you end up wading through a lot of really outdated material, hailing from the times that "JavaScript" was a four letter word.

If you are heavily involved in JavaScript programming...

What text editor or IDE do you use?

What unit testing framework do you use?

Do you use Selenium, or something else?

What other tools do you use?

What communities exist that discuss recent advents in JavaScript?

What books do you read/refer to?

What blogs do you read?

答:
I can recommend the JavasScript Weekly newsletter. It's

A free, once–weekly e-mail round-up of JavaScript news and articles.

I haven't read John Resig's books, but I have heard and read good feedback. His new book Secrets of the JavaScript Ninja will be published soon.

Pro JavaScript Techniques

Secrets of the JavaScript Ninja


问:
What's your favourite quote about programming?
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!

答:
If Java had true garbage collection, most programs would delete themselves upon execution.

    — Robert Sewell

LastEditorDisplayName: Roger Pate


问:
.NET silverlight development tools
What tools are necessary when developing efficiently with Silverlight 4? VS 2010 is a gimme, but what version? Is Pro enough? Premium? What about Expression Blend/Web/Both?

When considering VS 2010, premium comes with an MSDN subscription but it's at the high end of the budget. It makes sense if Expression comes with it though.

It's for a one man development show, making an LOB app that will integrate video/audo and mic/webcam equipment.

答:
You can actually develop Silverlight applications with the Web Express edition of Visual Studio so the Pro version would work to.

I'd also recommend getting Expression Blend - if only to get access to the options for copying and modifying style templates.

Title: .NET silverlight development tools


问:
What is meant by dynamic code evaluation?
The following is from  the preface of Jon Resig's new book : Secrets of JavaScript Ninjas

The portions of this book that cover features that are relatively un-changing, such as code evaluation, with statements, and timers are continually being used in interesting ways. There are now a number of active programming languages that are built on top of, or compiled to, JavaScript: Such as CoffeeScript or Processing.js. These languages require complex language parsing, code evaluation, and scope manipulation in order to work effectively. While dynamic code evaluation has been maligned due to its complexity and potential for security issues, without it we would not have had the CoffeeScript programming language – which has gone on to influence the upcoming ECMAScript specification itself.

I’m personally making use of all of these features, even today, in my work at Khan Academy. Dynamic code evaluation in the browser is such a powerful feature: You can build in-browser programming environments and do crazy things like inject code into a live runtime. This can result in an extremely compelling way to learn computer programming and provide all sorts of capabilities that wouldn’t be possible in a traditional learning environment.

What is actually "Dynamic code Evaluation" ?  What are its benefits ? Please illustrate with a nicely contrived example .

答:
Dynamic code Evaluation means "executing code within code" -- the first 'code' is represented by strings in the second 'code'.

Non-compiled languages provide some way of executing code from within a program. All the steps (parsing, intermediate code generation, optimization, etc.) are executed on the fly for the dynamically processed code.

Dynamic code Evaluation comes in handy specially when you can not write code without some variables that are only available on run-time. See an example in this question.

Another advantage is debugging. You can write custom debuggers that can execute code at a specific break point while the program is on the go.


问:
Handling Indirection and keeping layers of method calls, objects, and even xml files straight
How do you keep everything straight as you trace deeply into a piece of software through multiple method calls, object constructors, object factories, and even spring wiring.  I find that 4 or 5 method calls are easy to keep in my head, but once you are going to 8 or 9 calls deep it gets hard to keep track of everything.  Are there strategies for keeping everything straight?

In particular, I might be looking for how to do task x, but then as I trace down (or up) I lose track of that goal, or I find multiple layers need changes, but then I lose track of which changes as I trace all the way down.  Or I have tentative plans that I find out are not valid but then during the tracing I forget that the plan is invalid and try to consider the same plan all over again killing time....

Is there software that might be able to help out?  grep and even eclipse can help me to do the actual tracing from a call to the definition but I'm more worried about keeping track of everything including the de-facto plan for what has to change (which might vary as you go down/up and realize the prior plan was poor).

In the past I have dealt with a few big methods that you trace and pretty much can figure out what is going on within a few calls.  But now there are dozens of really tiny methods, many just a single call to another method/constructor and it is hard to keep track of them all.

答:
After talking with other people at work and digging around on my own, I have found that naming makes or breaks the approach of many small methods, and some trust that your co-worker is not crazy.  The principle of least surprise is very important.

With more objects is more places to introduce code and side effects.  If you want to surprise someone, more classes mean more constructors (possibly static initialization blocks and other similar structures as well) and more instance variables.  If you want to hide code and obfuscate it, more objects certainly helps.  While each individual method and even object might be simple, the grand sum of them tends to be more complex.  Additionally if you have something like Spring that can also introduce additional logic/side effects which have to do with the code it is even worse......

Naming too.  One problem I found is often a method says DoesX, but in reality the method does x, y, z, a, b, c.  So I have difficulty reasoning what any code does.  In a few giant methods, you would look at the methods and see a bunch of code doing unexpected things which your eyes would notice and be like WTF.  You would probably spot the code for y, z, a, b, c.  In reading split objects you would read code that says DoesX and first assume it does X.  Then later when you still do not understand what is going on and start reading everything you eventually come to DoesX and see oh it is doing y,z,a,b,c.  But if the methods are named correctly, then things work better because often you can understand what is going on without even reading the methods.  If DoesX just does X, then you can get away without reading it unless X is broken.

I have noticed that though we use Java, and through Spring wiring any object can really be wired up to an interface, they tend to just jump between classes using eclipse navigation.  If there is an interface, they tend to use eclipse to show all implementations (generally just 1) and then jump to it.  In reality Spring could wire up an implementation from some other library, or do something you do not expect (which in very few places does happen) but in general they just rely on things to be done the expected way.  I even found an Open Implementation extension to let me click on a method on an interface and auto jump to the implementing class's version.  Still a few places are a mess and do not work as expected.  But those are generally considered bad code and candidates for a rewrite.  Also there are some design techniques that are common knowledge around the company, so recognizing these techniques also aids understanding.  They are not documented anywhere, but after being like WTF and reading it, then I see the same technique again and instantly recognize it.  Again...someone could do some unexpected stuff to mess with you.

Martin Vejmelka sort of mentioned unit tests as a way of knowing the code is performing well.  I interviewed at a place which used unit tests like this, as ways to assert what code was doing.  When debugging their technique was to think what assertions must be wrong for the behavior to occur, then to create unit tests with the expected behavior that fail, then to go fix them.  In my current place they have unit tests but they do not cover all the code, and they also suffer from huge amounts of indirection making reading the unit tests as challenging as reading the code, and sometimes even harder.


问:
Practices for navigating and changing "long" code files?
Many a times I have to deal with code files which are quite long - about 5 screen pages at the minimum. Almost always there is something towards the top/bottom that I need to refer when I'm at the bottom/top (respectively). It's a mammoth overhead to constantly scroll back-n-forth between the file parts.

It's a cognitive overload to just remember each and everything throughout the file and it's quite necessary to be able to refer to parts of the file.

Yes, the Outline view in some editors like Eclipse/NetBeans helps, but sometimes they will work well only for parts recognizable by that parser. Sometimes outline views don't show up e.g. when coding in CoffeeScript or JavaScript using closures/namespaced functions etc. The fallback is then just manual scroll overhead.

So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

Yes, I can shorten the files, but specifically javascript libraries like Backbone.js etc. are all as one file since you really can't split them into multiple file due to lack of Java-like packages. So under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files? I work a lot on Eclipse/Netbeans and Aptana and sometimes Vi (but seldom in production environments). It'd be great to be able to split a window into two and see the same file on one side and code in the other. Not doable with Eclipse/NB/Aptana IMO. Vi, yes but can't use it all the time.

PS: As of now, I split the file among multiple editors e.g. Eclipse and Aptana. It'd be great to have it at one place, but is that the best that we can do? :)

UPDATE - Seems Eclipse has way for doing this and can be found here

答:
So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files?

Open the file in several different editor windows (or different editors) - have each section of interest in a different window. If you, like many developers, have two or more monitors, you can put each window on a different monitor for reference.

I don't know about Eclipse/NB/Apatana, but Visual Studio has a split bar - this allows you to see several different portions of a file in one window. Perhaps your editor of choice has this feature as well.