答:
UML is a very strong option for representing programs graphically.  Grady Booch and a team of others wrote a great book called Object-Oriented Analysis and Design with Applications that introduces OOAD pretty rigorously by spending around 150 pages discussing concepts before diving into notation.  While in someways the diagrams are easy to comprehend without much training, Booch is a master at defining ideas like complexity, distinguishing between object model and class model, and classification.  The advice about complexity includes discussion of several tools like algorithmic decomposition, object-oriented decomposition, abstraction, hierarchy, and encapsulation.

It is important to remember that you may need to look at your software from several perspectives so that you can capture the static structure and dynamic behavior of both objects and classes.  A class diagram would capture the static structure of one or more classes while a sequence diagram would capture the dynamic behavior of two or more objects as they interact.  Booch also breaks things down into categories structural, behavioral, and interaction diagrams.

UML Diagrams

Structural

Package

Class

Component

Deployment

Object

Composite Structure

Behavioral

Use Case

Activity

State Machine

Interaction

Sequence

Communication

Interaction Overview

Timing

For anyone who can name only three or four UML diagrams this should be a wake up call.  If you spent a day or a few hours a day for a week, you might not know UML very deeply.  Often, UML is taught as a four day course, and sometimes as three or four days for object oriented analysis followed by three or four days of object oriented design.  University courses may teach it as a one or more semester courses, or fold it into a sequence that used to follow the waterfall software life cycle (requirements and analysis (with use cases), software architecture and/or design (with the remaining diagrams), object oriented programming (with Java, C++, etc), and testing (that revisits use cases or state diagrams)).

Martin Fowler has a book that I like called UML Distilled where he essentially lays out a pattern for each diagram type, listing it name, a brief description, samples of the diagram and what the arcs, nodes and decorators mean, and most importantly, when to use them.  In his introductory material he describes UML as having three applications: to make a software blueprint, as a higher level programming language that generates code (or sometimes reverse engineers from code, or transmutes forward and backward in round-trip software engineering), or my favorite, as a sketch that helps communicate between developers some localized and specific aspects of the design.

UML haters are right about a lot of things.  For example, about how much overhead can be involved in using UML to document a design (in blueprint or programming language mode).  They sometimes say, a fool with a tool is still a fool.  It is a bad idea for an under-trained developer to jump in a make diagrams just as it is for a FORTRAN programmer to start writing in C++ or Java from a table that shows which statements are equivalent.  With a UML diagram editor of Computer Aided Software Engineering (CASE) tool (CASE has endured a lot of criticism) it became possible for bad designers to make big bad designs much faster.

UML lovers will point out that it allows us a common language to communicate our design in a visual and expressive way.  As we represent the same design in multiple ways, it gives us a great rehearsal for the code we will write.  Because it is visible it facilitates a form of communications with others that is faster (we process visual information much faster than verbal, and by indirection, than text), and gives us many opportunities for peer review.  Because we use more than one view, it permits us to move between hierarchical views like deployment diagrams, package diagrams, and class diagrams.  We can see the same information at rest in the object diagram, and in motion in the activity diagram and sequence diagram.  By using related diagrams, we can reveal problems with completeness and consistency early, and sometimes use a representation that is easily generated like a state diagram to discover needed content in another diagram like a sequence diagram.


问:
"Viral" license that only blocks legal actions of user and developer against each other
I was thinking a lot about software licensing lately, because I would like to do some coding. I'm not an expert in all those licenses, so I came up with my own idea, and before I will put in on paper, I would like to make sure that I didn't reinvent a wheel, so maybe I would be able to use something that exists.

Main idea behind my license is to guarantee freedom of use the software, but not "freedom to" (positive) (e.g. freedom to having source code), but "freedom from" (negative) (strictly from legal actions against you). It would be "viral" copyleft license.

You would be able to without fear do everything you want with the software (and binaries e.g. reverse engineering), as long as You will include information about author and/or authors, and all derivative works will be distributed with the same license. I'm not interested in anything that would restrict a freedom of company to do something like "tivoization". I'm just trying to accomplish something that would block any legal actions of user and developer, targeted against each other, with the exception of basic attribution.

Does exist something like that?

答:
I don't think it's legally possible for a license to prevent any legal action against you. However, almost any free/open source license will include a warranty disclaimer that will prevent you from being held responsible for what is done with your software, which is about the most a license can do.

Other than that what you are describing sounds a lot like either a BSD-style license or GPLv2 depending on what you mean by "all derivative works will be distributed with the same license".

ContentLicense: CC BY-SA 3.0


答:
This all uppercase part of the BSD license is pretty much what you are saying.  Full text here:

http://opensource.org/licenses/bsd-license.php

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Title: "Viral" license that only blocks legal actions of user and developer against each other

Body:
I was thinking a lot about software licensing lately, because I would like to do some coding. I'm not an expert in all those licenses, so I came up with my own idea, and before I will put in on paper, I would like to make sure that I didn't reinvent a wheel, so maybe I would be able to use something that exists.

Main idea behind my license is to guarantee freedom of use the software, but not "freedom to" (positive) (e.g. freedom to having source code), but "freedom from" (negative) (strictly from legal actions against you). It would be "viral" copyleft license.

You would be able to without fear do everything you want with the software (and binaries e.g. reverse engineering), as long as You will include information about author and/or authors, and all derivative works will be distributed with the same license. I'm not interested in anything that would restrict a freedom of company to do something like "tivoization". I'm just trying to accomplish something that would block any legal actions of user and developer, targeted against each other, with the exception of basic attribution.

Does exist something like that?


答: That sounds just like GPL to me but for some reason you don't want to give away the source code. As far as I can see you don't technically have to give away the source code under GPL however there isn't really any reason not to do so when you say you want the users to be able to do anything they want with their program and that you want a copy-left licence.</p>


问:
Is C# development effectively inseparable from the IDE you use?
I'm a Python programmer learning C# who is trying to stop worrying and just love C# for what it is, rather than constantly comparing it back to Python.

I'm caught up on one point: the lack of explicitness about where things are defined, as detailed in this Stack Overflow question. In short: in C#, using foo doesn't tell you what names from foo are being made available, which is analogous to from foo import * in Python -- a form that is discouraged within Python coding culture for being implicit rather than the more explicit approach of from foo import bar.

I was rather struck by the Stack Overflow answers to this point from C# programmers, which was that in practice this lack of explicitness doesn't really matter because in your IDE (presumably Visual Studio) you can just hover over a name and be told by the system where the name is coming from. E.g.:

Now, in theory I realise this means when you're looking with a text editor, you can't tell where the types come from in C#... but in practice, I don't find that to be a problem. How often are you actually looking at code and can't use Visual Studio?

This is revelatory to me. Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files. The idea of being dependent on an IDE to understand code at such a basic level seems anathema. It seems C# culture is radically different on this point. And I wonder if I just need to accept and embrace that as part of my learning of C#.

Which leads me to my question here: is C# development effectively inseparable from the IDE you use?

答:
Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files.

That's great, but it misses the point of the VS IDE. The point of an IDE like VS is rapid development support via strong code tools like refactoring and intellisense. VS is a very very good editor for C# code.

Now C# lets you code in a style that depends on its IDE to a greater extent (you can use lots of var keywords and the like). Some people prefer to be more explicit, for instance by using namespace aliases to be clear on which namespace a class belongs to (like import in Java or Python). That's more of a coding style choice than a feature of the language.

As C# is statically typed (although with some dynamic extensions, as of v4) it's always fairly easy to find out what types are being referred to - if they're wrong the code won't compile, and VS isn't the only IDE with support for C# intellisense. It's probably the best though.

Developing C# without a powerful IDE (like VS) is rather like hammering in nails by hand when you already have a top of the range nailgun - there might be the odd time you need to do it, but professionals use the right tool for the job.

I'd say the same is probably true of Java too. If there's a powerful IDE with intellisense and code refactor tools out there you should probably be using it.

However, look at it the other way round - if you don't want intellisense, compile time code checking and code-analysis/refactoring then a bloated IDE is not the way to go, and neither is a statically typed language. I think it's the other way round:

Many programmers that prefer a text editor approach to coding don't gain as much from statically typed languages (like C# and Java) and so could be better off if they stick to dynamic ones like Python and Javascript.

I think:

Dynamic languages suit lightweight tools (heavyweight IDEs confer less benefit here)

Static languages suit powerful IDEs (tools can help with the code at the cost of flexibility)


问:
design for a parser to handle very large files
I have written a program which records protocol messages between an application and a hardware device which matches each application request with each hardware response.  This is so that I can later remove the hardware, connect a 'replay' application to the main application and wait for an application request and reply with a matched copy of the requisite hardware reply message.

My replay application saves the matched request/response in a list (using C++ std::list).

This works fine on a small interaction session.  My problem now is that I need to be able to use the replay over a long long session.  With my current implementation, the replay program eventually uses up all available memory on my computer and crashes.

So I need some sort of lookahead - and not parse the whole session in one go.

Can anyone make any suggestions on how to get started?

答:
Large interaction data is usually serialised to a file. Write the data to a CSV file or write it to a database and read back from it. Journal the data when it crosses a certain limit. Saving it this way will keep your memory from crashing. Save it regularly after a span of time.

Lookup CIRCULAR List also.


问:
Are there such thing as assembly SDK's?
I've never worked in assembly, but I was just curious if SDK's exist for assembly programming. For instance, if I wanted to create a linked list, are there libraries available that have already done this, or is everything typically done from scratch?</p>

答:
I might be wrong on this, but I guess there are SDKs regarding processors architectures, ABIs and other hardware stuff. Other than that, I guess there is no such thing.

Everything in an ASM tends to be ad-hoc, so there are no datastructures per se.
Of course, you could design a couple of standard jumps one could make with some sort of programming contract of what you might expect to be in the stack and memory address, but that would be using C. No real advantage.

Title: Are there such thing as assembly SDK's?


问:
Should coding standards be enforced by the continuous integration server?
Should coding standards/style be enforced by the continuous integration server running static analysis tools (ex. PMD, StyleCop/FxCop) and failing the build if the standards are not followed? What types of rules should not be used to fail the build?</p>

答:
As part of a Software Quality Improvement Plan we recently coded a series of code sniffs to integrate into our build process.

We build a lot, being a PHP application there is no real compilation so the build is really a unit test / static analysis / runner, and we can afford to spend a few cycles on this.

We had some code quality issues, and some legacy code with lots of issues.

Starting on the basis that if it does not fail the commit it will be ignored we started confirming commits against our 'desired' coding standard, and failing commits with errors that did not meet the standard.

Maintenance ground to a halt, even the simplest fix to a legacy component required the developer to reformat huge quantities of source, and the build was broken more often than not.  Needless to say we changed the errors to warnings, and now they are, ignored and 'mostly' pointless.

So I would say this (learned from hard experience).

Make sure that the standard of your code base is close enough to the standard that you enforce that you do not require dev's to reformat volumes of code, instantly.  Or..  You are prepared for and expecting the increase in effort.

Being a small team with a huge delivery requirement, we couldn't afford to switch the team to a huge re-factor operation.  Our coding standards are now mostly handled by manual review, and the legacy is being re-written as part of a continuous improvement plan.

When I said that the warnings are 'mostly' pointless,  well we now use them for recording statistics that allow us to measure kpi's that should keep showing improvement.

When we enforce the code sniffs again,  we will start light, and introduce a few sniffs at a time until we have the standard enforced.


答:
NASMX? MASM32? Check these "SDK"s which are just regular MACROs for Win32 Programming with ASSEMBLY language.(for x86 and x64)

For Linked List and other DATASTRUCTURES, you might have to code them yourself. Assembly language toolkits are much like C language toolkits - open and extensible.

Title: Are there such thing as assembly SDK's?

Body: I've never worked in assembly, but I was just curious if SDK's exist for assembly programming. For instance, if I wanted to create a linked list, are there libraries available that have already done this, or is everything typically done from scratch?</p>


答:
At the assembly level, you could build out an "API" by using some Macros and fleshing out a set of assembly functions into a separate file which perform a particular generic task, which you could then call...

Complex functionality, including linked lists, etc., are frequently implemented in a higher level language and called from assembly, Like C, C++, etc. If you are starting out with ASM, but want to utilize more complex patterns and structures, calling a C library is the way to go.

The reason for this is because it quickly becomes an enormous job to manage the spaghetti of registers and addressing muck when you start dealing with an excess of stack frames.

However, if you are interested in implementing complex stuff, it has been done before: Linked Lists in ASM - the only thing you'd need to do is implement this as a macro.

The value of implementing complex functionality in ASM is quickly outweighed by the advantages of just using a higher level language to begin with (which, fyi, are already very fast). If your motivation is speed, my suspicion would be that there is a C library out there can come very close to what you need.

Title: Are there such thing as assembly SDK's?


问:
Where to find common database abbreviations in Spanish
I'm doing a little pro bono work for an organization in Central America. I'm ok at Spanish and my contacts are perfectly fluent but are not techincal people. Even if they don't care what I call some fields in a database I still want to make as clean a schema as possible, and I'd like to know what some typical abbreviations are for field / variable names in Spanish.

I understand abbreviations and naming conventions are entirely personal. I'm not
asking for the "correct" or "best" way to abbreviate database object names. I'm just looking for references to lists of typical abbreviations that would be easily recognizable to a techincally competent native Spanish speaker. I believe I am a decent googler but I've had no luck on this one.

For example, in my company (where English is the primary language) 'Date' is always shortened to 'DT', 'Code' to 'CD', 'Item' to 'IT', etc. It's easy for the crowds of IT temp workers who revolve through on various projects to figure out that 'DT' stands for 'Date', 'YR' for 'Year', or 'TN' for 'Transaction' without even having to consult the official abbreviations list.

答:
Two thoughts on this one:

1) Why not ask them for an abbreviation that would make sense?

They'll have to teach the next person what the DB is supposed to be doing anyway, so they might as well provide some input on the abbreviations.

2) Why not use English for the object names and provide them with a list of the abbreviations you use?

The next person down the line may or may not speak Spanish either.  English may therefore become the common denominator for this particular project.  The project owners can simply forward the next person a copy of the glossary you created.

Of the two, I would suggest the second.  English (broken or not) is the common language for IT.  If you avoid cryptic terms and document your changes well then the next person shouldn't have any problems picking up where you left off.

Documentation in this case is more important than creating what you think is a clean schema.  The documentation will clue them into your thought processes and will make everything more self-evident.


答:
First, know that the std::list is a bad choice for this kind of thing, in particular on reading. The reason is that std::list elements are not guaranteed to be contiguous, make going from element to element very slower because of cache misses (and the lack of predictable memory access behaviour).

I would be you, the first thing I would try would be to replace the std::list by a std::vector, with a call to reserve before starting pushing elements back, to reserve a lot of memory from the start and avoid allocations.
If you use C++11, use the emplace_back() function instead of push_back() to definitively avoid unnecessary copies of the element object.

The vector have a contigous memory which will guarantee fast access on reading the session, and will be more memory efficient because elements are always close: there is no fragmentation of memory.

If that is not enough, consider using something like SQLite. It don't replace in-memory access, but you might use pair of std::array of your records as double buffer in which you put the next batch of records to read that you extract progressively from the sqlite file. To write, just do inserts. Both reading and writing can be done in a separate thread while your application continues running or is processing the records in replay.

The reason this setup might help is that it would make any size of session not (or almost not) impact the application that plays it, because in memory there would be only a part of the whole session readable, making runtime not grow on memory, making things fast. In this case you'll be limited only by the speed access to the disk, which is why I suggest using a (concurrently) double buffer reading of the records. Anyway sqlite is made to be very fast.

Title: design for a parser to handle very large files

Body:
I have written a program which records protocol messages between an application and a hardware device which matches each application request with each hardware response.  This is so that I can later remove the hardware, connect a 'replay' application to the main application and wait for an application request and reply with a matched copy of the requisite hardware reply message.

My replay application saves the matched request/response in a list (using C++ std::list).

This works fine on a small interaction session.  My problem now is that I need to be able to use the replay over a long long session.  With my current implementation, the replay program eventually uses up all available memory on my computer and crashes.

So I need some sort of lookahead - and not parse the whole session in one go.

Can anyone make any suggestions on how to get started?


答:
(Just re-iterating so that you know that I know what you are saying)

It sounds like you are effectively creating an in-memory structure of the various requests and responses.  With a large session, this is creating a significantly large structure that is then taking more memory than you have available.

Instead of trying to keep the entire thing in memory, would it be feasible to go to a disk based system?  For example one could go to a Berkeley db on disk. It has C and C++ bindings that you could use to tie into your current application.

With this approach, one could hash the request (last I recall, Berkeley db likes to have simple keys) and store/retrieve based on the hash.  This way, one doesn't keep the entire database (or list) in memory, but rather does fast indexed lookups on disk.


答: It looks like Spontaneous Assembly is still avialable. Some of it is aimed toward MS-DOS, which you probably don't care about. Other parts, however, are (or should be, anyway) reasonably independent of the target platform, as long as it runs on an x86 processor.

Title: Are there such thing as assembly SDK's?


答:
This About.com page has a short list and this DropBy.Com page has more entries including business abbreviations.  You will probably have trouble with two-letter abbreviations, especially with plurals which double the number of letters already.  I've seen the word for date (fecha) written as fec for example.

Probably best to write them out completely anyway for better clarity, e.g. "fecha_modificacion", "fecha_creacion"  for "modified date" and "create date". Put the noun before the modifier as is the convention in Spanish.

That way someone looking at it later could just do a dictionary lookup rather than relying on some special convention (not a bad idea for English DB's as well).

Title: Where to find common database abbreviations in Spanish

Body:
I'm doing a little pro bono work for an organization in Central America. I'm ok at Spanish and my contacts are perfectly fluent but are not techincal people. Even if they don't care what I call some fields in a database I still want to make as clean a schema as possible, and I'd like to know what some typical abbreviations are for field / variable names in Spanish.

I understand abbreviations and naming conventions are entirely personal. I'm not
asking for the "correct" or "best" way to abbreviate database object names. I'm just looking for references to lists of typical abbreviations that would be easily recognizable to a techincally competent native Spanish speaker. I believe I am a decent googler but I've had no luck on this one.

For example, in my company (where English is the primary language) 'Date' is always shortened to 'DT', 'Code' to 'CD', 'Item' to 'IT', etc. It's easy for the crowds of IT temp workers who revolve through on various projects to figure out that 'DT' stands for 'Date', 'YR' for 'Year', or 'TN' for 'Transaction' without even having to consult the official abbreviations list.


问:
What is a good way to learn about multicore programming at the kernel level in Linux?
I am interested in multicore programming at the kernel level.  I expect this affects many areas and is probably different for each architecture.  What are some must read sections of the kernel?  If I wanted to compare and contrast code for an Intel I7 and an ARM Cortex-A9 MPCore where would I find the differences?</p>

答:
To understand the multicore operation support provided by processors and used by operating systems, diving into the code may not be the ideal method.  It may be important to first understand what it does to get a framework on which to hang the many pieces that relate to how it does it.  Specification deals with the problem domain, code deals with the solution domain, and in most systems there is a design process that does an object oriented or functional decomposition to relate the two.

One way to approach this question is to start with the theory of operation documentation for the architecture of interest, greping for multicore or multiprocessor, two concepts that have close affinity although there are some distinctions related to implementation, particularly on the hardware side.  For the Intel architecture I found some interesting information from Volume 2, Part 2: MP Coherence and Synchronization page 2:507 of the Intel®
 Itanium®
 Architecture
Software Developer’s Manual

From this material, some of the following code becomes much more intelligible.

semaphore.c must use single core and multicore appropriate methods to prevent objects that may be shared from access.  This leads to finding references to spin locks.

spinlock.c leads to some device specific usage and consequently its .h is located in files like arch/arm/include/asm/spinlock.h or arch/ia64/include/asm/spinlock.h

Certainly there is no substitute for reading the code, but there is also no substitute for reading the vendors manuals, particularly when working with one of the most complex devices on the planet.


问:
How do you stay focused at work?
Sometimes, the things I have to do for my job are interesting and engaging.  Sometimes, they aren't.  Occasionally, they really aren't.

Do you have any particular strategies or tricks for dealing with those dull stretches when your brain would rather be doing anything other than what you're supposed to be doing, particularly when the Internet and its boundless opportunities for interesting Slack beckon?

答: I have found the pomodoro technique useful for increasing my concentration at work, specially for things I don't really like doing.</p>

ContentLicense: CC BY-SA 2.5

Title: How do you stay focused at work?


问:
What syntax element do you hate most in a programming language you use frequently?
No matter how much you love a programming language, there are always a few details in it that aren’t quite as nice as they could be.

In this question, I would like to specifically focus on syntax elements. In a programming language that you use frequently (perhaps your favourite programming language, or perhaps the one you are forced to use at work), which syntax element do you find most unreadable, unclear, inconvenient or unpleasant?

答: The fact that Python relies on text formatting.</p>


问:
Are long methods always bad?
So looking around earlier I noticed some comments about long methods being bad practice.

I am not sure I always agree that long methods are bad (and would like opinions from others).

For example I have some Django views that do a bit of processing of the objects before sending them to the view, a long method being 350 lines of code. I have my code written so that it deals with the parameters - sorting / filtering the queryset, then bit by bit does some processing on the objects my query has returned.

So the processing is mainly conditional aggregation, that has complex enough rules it can't easily be done in the database, so I have some variables declared outside the main loop then  get altered during the loop.

```<code>variable_1 = 0
variable_2 = 0
for object in queryset :
     if object.condition_condition_a and variable_2 > 0 :
     variable 1+= 1
     .....
     ...
     .
      more conditions to alter the variables

return queryset, and context
</code>```

So according to the theory I should factor out all the code into smaller methods, so That I have the view method as being maximum one page long.

However having worked on various code bases in the past, I sometimes find it makes the code less readable, when you need to constantly jump from one method to the next figuring out all the parts of it, while keeping the outermost method in your head.

I find that having a long method that is well formatted, you can see the logic more easily, as it isn't getting hidden away in inner methods.

I could factor out the code into smaller methods, but often there is is an inner loop being used for two or three things, so it would result in more complex code, or methods that don't do one thing but two or three (alternatively I could repeat inner loops for each task, but then there will be a performance hit).

So is there a case that long methods are not always bad? Is there always a case for writing methods, when they will only be used in one place?

UPDATE:
Looks like I asked this question a over a year ago.

So I refactored the code after the (mixed) response here, split it into methods. It is a Django app retrieving complex sets of related objects from the database, so the testing argument is out (it would have probably taken most of the year to create relevant objects for the test cases . I have a "this needs done yesterday" type work environment before anyone complains).
Fixing bugs in that part of the code is marginally easier now, but not massively so.

before :

```<code>#comment 1
bit of (uncomplicated) code 1a
bit of code 2a

#comment 2
bit of code 2a
bit of code 2b
bit of code 2c

#comment 3
bit of code 3
</code>```

now:

```<code>method_call_1
method_call_2
method_call_3

def method_1
    bit of (uncomplicated) code 1a
    bit of code 2a

def method_2
    bit of code 2a
    bit of code 2b
    bit of code 2c

def method_3
    bit of code 3
</code>```

答:
True story. I once encountered a method that was over two thousand lines long. The method had regions that described what it was doing in those regions. After reading through a region, I decided to do an automated extract method, naming it according to the region name. by the time I was done, the method was nothing but 40 method calls of about fifty lines each and it all worked the same.

What is too large is subjective. Sometimes, a method can't be broken down any further than what it is currently. It's like writing a book. Most people agree that long paragraphs should usually be split. But sometimes, there is only one idea and splitting it causes more confusion than would be caused by the length of that paragraph.

ContentLicense: CC BY-SA 4.0

Title: Are long methods always bad?


问:
How to visualize the design of a program in order to communicate it to others
I am (re-)designing some packages for R, and I am currently working out the necessary functions, objects, both internal and for the interface with the user. I have documented the individual functions and objects.

So I have the description of all the little parts. Now I need to give an overview of how the parts fit together. The scheme of the motor so to say.

I've started with making some flowchart-like graphs in Visio, but that quickly became a clumsy and useless collection of boxes, arrrows and-what-not. So hence the question:

Is there specific software you can use for vizualizing the design of your program

If so, care to share some tips on how to do this most efficiently

If not, how do other designers create the scheme of their programs and communicate that to others?

Edit: I am NOT asking how to explain complex processes to somebody, nor asking how to illustrate programming logic. I am asking how to communicate the design of a program/package, i.e.:

the objects (with key features and representation if possible)

the related functions (with arguments and function if possible)

the interrelation between the functions at the interface and the internal functions (I'm talking about an extension package for a scripting language, keep that in mind)

So something like this :

But better. This is (part of) the interrelations between functions in the old package that I'm now redesigning for obvious reasons :-)

PS : I made that graph myself, using code extraction tools on the source and feeding the interrelation matrix to yEd Graph Editor.

答: Granulate the application flow and prepate a work flow diagram. Or go for sequence digrams. Flow charts good for expressing the logics; not for app design</p>


问:
Can I release complementary Windows 8 and WP8 apps on their respective stores?
I am creating a pair of apps, one to run preferably on tablets, but also laptops and PCs, and the other for WP8.

These apps are complementary - having one is of no use without the other.

I know there is a Windows Store, and a Windows Phone store, so one would be released on one, and one on the other.

My question is: as these apps are useless by themselves (although in most cases it won't be the same people running both apps), will there be a problem with offering these useless-when-used-alone apps?

IOW: Person A will use the Windows 8 app to interact with some people that have the WP8 app installed; those with the WP8 app will interact with a person or people who have the Windows 8 app installed.

What I'm worried about is if these apps go through a certification process where they must be useful "standalone" - is that the case?

答: There is nothing in the certification process (so far) that prevents this scenario. As long as your application will run without crashing and doesn't violate any of the technical specifications of the platform (e.g. calling unexposed APIs), you'll pass.</p>


问:
My proposed design is usually worse than my colleague's - how do I get better?
I have been programming for couple of years and am generally good when it comes to fixing problems and creating small-to-medium scripts, however, I'm generally not good at designing large scale programs in object oriented way. Few questions

Recently, a colleague who has same number of years of experience as me and I were working on a problem. I was working on a problem longer than him, however, he came up with a better solution and in the end we're going to use his design. This really affected me. I admit his design is better, but I wanted to come up with a design as good as his. I'm even contemplating quitting the job. Not sure why but suddenly I feel under some pressure e.g. what would juniors think of me and etc? Is it normal? Or I'm thinking a little too much into this?

My job involves programming in Python. I try to read source code but how do you think I can improve me design skills? Are there any good books or software that I should study?

Please enlighten me. I will really appreciate your help.

答:
Well, you've already taken the first step. You admit that you have something to learn, that your colleague's work is better than yours, and you want to learn and improve.

The second step is to analyze.  Look at his work and don't just say that it's better; figure out why it's better. Look for specific details and points that he did better.

Once you understand that, extract the principles behind it.  Ask questions like these:

What about this design is better than my design?

Is this point something specific to this design, or is it a general principle that could be applied to other designs in the future?

If it's a general principle, what are its limits?  When is it a good idea not to do things this way?  (This one is very important.  It keeps you from treating some useful idea as a golden hammer, even in inappropriate cases.)

Try to figure things out on your own, because you'll internalize the ideas better if you came up with the chain of reasoning that led you to the conclusion yourself, but also talk with your co-worker to make sure you're getting things right.  (You don't want to go making mistakes in your reasoning and internalizing a bad principle, afterall.)  And feel free to ask your coworker for help if you can't figure things out.  Programming is a discipline where humility tends to be respected, and a lot of coders will jump at the chance to teach someone something new, which is probably a big part of why StackOverflow got so big so fast.


答:
In every aspect of life you will find people who is not as good as you, as well as people who is better than you, especially after just "a couple of years" of experience.

You have to learn from everyone.

Don't feel bad. Maybe you colleague is a natural. You should congratulate him sincerely and learn as much as you can from him.

Don't let professional jealously get between you and an oportunity to learn.

Title: My proposed design is usually worse than my colleague's - how do I get better?

Body:
I have been programming for couple of years and am generally good when it comes to fixing problems and creating small-to-medium scripts, however, I'm generally not good at designing large scale programs in object oriented way. Few questions

Recently, a colleague who has same number of years of experience as me and I were working on a problem. I was working on a problem longer than him, however, he came up with a better solution and in the end we're going to use his design. This really affected me. I admit his design is better, but I wanted to come up with a design as good as his. I'm even contemplating quitting the job. Not sure why but suddenly I feel under some pressure e.g. what would juniors think of me and etc? Is it normal? Or I'm thinking a little too much into this?

My job involves programming in Python. I try to read source code but how do you think I can improve me design skills? Are there any good books or software that I should study?

Please enlighten me. I will really appreciate your help.


答:
I think this is a very positive sign of your skills. It is far more common for people who have difficulty coming up with the 'better' design in a team to be completely incapable of recognizing why another design is better.

You have two really great (and surprisingly uncommon) strengths going for you:

You are capable of assessing your designs against others objectively

You have the desire and put forth effort to make your designs optimal

You're only a couple years in and have a long way to go, but with this attitude you will definitely get there, just don't give up; we all deal with mental set backs like this. As often as I get a chance I like to plug Design Principles (NOT the same as design patterns) and I think this is a perfect example of where they come in handy. Study them and practice applying them in your designs, you will before you know it have taken another step forward in this regard.

At the end of the day remember, designing is hard. We're dealing with complex high level abstractions every day, to create these from thin air, have them work well, and easy to use by colleagues is an extremely difficult task. It takes practice, for years.

So chin up and just remember: there's a bunch of folks out there who can't assess two designs and actually recognize one as preferable over another, how well do you think they're getting along in creating good designs?

Edit:

'nother tip, after getting your head around principles and practicing their application a bit, I think there is another gem from another question here speaking to the value of studying a variety of languages which have different purposes and rules:

Ideally, every programmer should know a language from each class. What could you learn:

A static typed OOP mainstream language: Java, C# (mostly used in enterprise software) and C++ (system programming and complex desktop applications)

A prototype-based OOP language: Javascript (client side web programming)

A procedural language: C (embedded software and system programming)

A functional language: Haskell, ML or Lisp (functional languages are good for highly parallelized software).

A logic programming language (Prolog) probably is not that useful in industry, being used mostly in research in AI.

This will help to broaden the variety of ideas that come to mind when trying to design a solution.


答:
Don't let it get to you. If you have years of experience fixing bugs and making small programs, that's what you'll excel at. Your co-worker probably has years of experience designing larger projects.

Being familiar with the underlying bits is incredibly handy, but if you want to get better at design, you'll have to design a few projects. Repeat until the skill sinks in.

In short, "years of experience" is not always equivalent. Go make your years worth something.


答:
Well don't quit your job. It is better to be working with someone who has better skills than you do, so that you can learn from him or her.

Look at the better design and determine why it is better. LEarn from the accepted design and think about ways where you could apply a simliar design in other situations. Once you know why it is better than your design, then you know what mistatke not to make the next time you do a design. Talk to the other developer and ask how he came up with the design.

To improve design skills, the best thing to do is to create designs, then be brutal with yourself in evaluating them and determining how they can be improved.  Ask yourself questions like: Will it work and does it meet the requirement in all aspects, is it maintainable, how will I be able to test this, will it cause performance issues, how likely is the requirement to change and how well will the design be able to handle change. Read about design patterns and then try to apply them to your designs. Refactor mercilessly after coming up with an intial design. If you are designing a database along with the application, read extensively about normalization and performance tuning the db, you will learn much about database design if you learn how to make a database work most effectively and efficiently. For applications think about DRY and SOLID principles in doing your design. Read about antipatterns to knwo what things to avoid doing.


问:
Rapid prototyping and refactoring
Sometimes when I start a small project (like an android app), I don´t know which approach will work out at the end, and I just go for one approach and give it a try. But if I never used this approach before (for a sort of application I´ve never programmed before) it is like stepping into unknown terrain. I don´t know which libraries to use (maybe I have to try out several libraries) and there are so many unkonwns (like: how to get raw audio data in android)

So then my development process goes like this:

Write a piece of code to see if the approach has a chance. (The more uncertain the approach is, the uglier the code gets)

If it works, refactor a lot until it is beautiful

I think it could be a waste of time if I planned my software design in detail at this point, it would be like planning a trip without a map.

Is this part of aglie development?
How do you deal with unknown terrain in software development?

答: This is roughly how I start new projects and it's worked out pretty well, assuming we're talking about smallish projects. For example, I would not go this route if I were writing an ORM or something of that magnitude. Occasionally I'll resort to more formal research when I'm really in over my head. But for the most part I just start writing code and see what happens. You have to be prepared to throw a lot of code away when you do this however.</p>

Title: Rapid prototyping and refactoring


答:
A couple of years is really not that much. And than there are people with better or worst high level design views. For example I've known people capable of writing complex algorithm for low level programs in a blink of an eye but incapable of understanding higher level design and concepts like cohesion and dependencies. However this is not a de-facto state. Both you can get better at higher level design (read a few books, try a few tricks at home, etc) and also you may discover that at other areas of programming your fellow programmer is less good.
Also, if you think you are about the same level both in experience and techincal knowledge, this may have had bean a random situation. Next time maybe you have better design ideas. Also, instead of quiting your job, take this opportunity and learn from your colleague. Next time, do a design together, try to catch his secrets, his thoughts. Programming is like a craft, it's learned by doing and watching others do it.

Design skills mostly come with experience and after you read a few important books. I would recommend you the followings:

Robert C. Marting - Agile Principles, Patterns and Practices (there are 2 versions, one in Java and one in C#. It doesn't matter which one you pick, the ideas and principles can be applied to any object oriented - and not only - source code)

Than, Robert C. Marting has 2 other interesting books: Clean Code and The Clean Coder

Even if Martin covers all the modern design patterns in his first book, you want to look up the original design patterns book by the Gang of Four.

Finally, there are other books that are highly prised today: Growing Object Oriented Software Guided by Tests, or Refactoring by M. Feathers (I think), or Writing Effective Use Cases by A. Cockburn and few more you will discover on the way.

None of these books is a magic bullet, but reading the first 2 recommendations will probably change your view and perception about programming forever.


问:
Everything has an Interface

Possible Duplicate:

  Do I need to use an interface when only one class will ever implement it?

I am taking over a project where every single real class is implementing an Interface.  The vast majority of these interfaces are implemented by a single class that share a similar name and the exact same methods (ex: MyCar and MyCarImpl).  Almost no 2 classes in the project implement more than the interface that shares its name.

I know the general recommendation is to code to an interface rather than an implementation, but isn't this taking it a bit too far?  The system might be more flexible in that it is easier to add a new class that behaves very much like an existing class.  However, it is significantly harder to parse through the code and method changes now require 2 edits instead of 1.

Personally, I normally only create interfaces when there is a need for multiple classes to have the same behavior.  I subscribe to YAGNI, so I don't create something unless I see a real need for it.  Am I doing it all wrong or is this project going way overboard?

答:
Yes, this project is going way overboard. There are two main reasons why this may happen:

The programmer was blindly following some dogma without understanding where it would actually yield benefits and where not

The programmer is doing test-driven development and makes heavy use of a mocking framework for the tests, and that mocking framework does not (or did not, either when the project was created or when the programmer learned the technique) support mocking concrete classes.

Title: Everything has an Interface


答:
This is a straight up violation of the YAGNI principle and I strongly recommend against doing it that way. It is so easy to introduce an interface later when you really need it that you should not even bother creating it up front. I heard this is a quite common pattern among Java folks but don't ask me why, I have no idea.

However, if this is a team project on which you collaborate, you should follow the established standards, even though they are bad.

Title: Everything has an Interface

Body:
Possible Duplicate:

  Do I need to use an interface when only one class will ever implement it?

I am taking over a project where every single real class is implementing an Interface.  The vast majority of these interfaces are implemented by a single class that share a similar name and the exact same methods (ex: MyCar and MyCarImpl).  Almost no 2 classes in the project implement more than the interface that shares its name.

I know the general recommendation is to code to an interface rather than an implementation, but isn't this taking it a bit too far?  The system might be more flexible in that it is easier to add a new class that behaves very much like an existing class.  However, it is significantly harder to parse through the code and method changes now require 2 edits instead of 1.

Personally, I normally only create interfaces when there is a need for multiple classes to have the same behavior.  I subscribe to YAGNI, so I don't create something unless I see a real need for it.  Am I doing it all wrong or is this project going way overboard?


答:
This is absolutely normal for multiple people to come up with designs of different quality. I have been invited in the past to judge competitions in software design, so I witnessed this firsthand: even the simplest designs resulted in solutions of drastically different quality, all coming from smart and experienced people.

Reading source code is too low-level to help you improve your design skills: code addresses complexity at the lower level than the overall design.

The best way to improve at designing software is to design software*. One way to do it is by looking at design competitions: TopCoder has an archive of 100+ component designs, complete with UML design documentation and implementations in Java and/or C#. Pick up a finished component that you like, read the requirements specification, and try to come up with an original design to fulfill the requirements. Spend an hour or two thinking about the problem and sketching a class diagram, then open the winning design, and read what the author did. Compare his design to yours, spot the differences, and see if your design is better. Check the competition scorecard to see how judges rated the design. This will give you the feedback that you need to decide how to improve your design skills.

* This applies to things other than designing software: do something many times with a qualified feedback, pay attention to what they say, - and you will get better at whatever you are doing.


答:
Having an interface to each class is extreme. You spotted that right.

However, having interfaces implemented by only a single class is not that unusual as you may think. If you are familiar with the Agile principles, they usually say that interfaces belong to the client, which is both logically correct and technically practical. So you may create interfaces to define behavior to the client and compile clients without the real classes available and thus reducing compile times or delivery of modules. Because modules will depend on interfaces, they will be deliverable independently and without a concrete implementation. Than you can just swap implementations as you wish.

If you take this to extreme, you and up with what you see. It's not good at all, but it would be worse to have no interface at all.

Title: Everything has an Interface


答:
This is a common with partial applications of SOLID principles to a project, and not necessarily a bad thing.

Coding against interfaces instead of classes is a reasonable way to maintain Dependency Inversion, and is very useful (some say necessary) for creating testable software components.

However, if your system as exactly 1 interface for every class, and vice versa, you're probably not respecting Interface segregation, and you're almost certainly violating the guideline of You Ain't Gonna Need It.

Consider the cost in development time (now and in the future) of creating interfaces for each class, and evaluate whether better interface segregation would benefit your project. These principles and guidelines exist only to enable you to understand the tradeoffs in various designs, and communicate about them effectively. The decision on which conventions to follow, and how strictly, is in your hands.

Title: Everything has an Interface


答:
I know the general recommendation is to code to an interface rather than an implementation, but isn't this taking it a bit too far?

(IMO) yes. If you have an interface with only one implementor, then you don't really need the interface.

That said, many places will always require 2 implementors. The actual implementation and a mock implementation to allow unit testing of the things that consume it. If your object is just data, or can be used by tests in isolation, great.

The other case where interfaces make sense is as a public interface to an API. That can serve as protection to your consumers even if there is only one implementor (for now).

Title: Everything has an Interface


问:
Is there anything in .NET that allows me to define a grammar and generate a programming language?
I have a course in which the proffesor has asked us to create a DSL for a our final project.  He presented us in the first courses xText with Eclipse.  This being a new course, I am still a bit fuzzy on what Domain Specific Languages means.

This is my current understanding:  a domain specific language is a language that is created for specific problems in software development.  Examples of DSL's are PHP, SQL, JavaScript and on the opposite are languages like Java , C# , C++ , Ruby etc.

Please feel free to correct me if I am wrong.

What I would like to know: is there is any tool for .NET/Visual Studio that is similar to Xtext, that allows me to define a grammar and be allowed to generate a programming language based on that with an activity diagram?

答:
You can try ANTLR
(or ANother Tool for Language Recognition) a parser generator that is among others available for dotnet. In the community you can find definitions for sql, c# and many other languages.

According to google there is also ide support:

ANTLRWorks: The ANTLR GUI Development Environment

Eclipse plugin


答:
There is a Visualization and Modeling SDK for Visual Studio which supports Text Templating (T4 templates) and Domain-Specific Languages.

http://msdn.microsoft.com/en-us/library/dd820703.aspx

Title: Is there anything in .NET that allows me to define a grammar and generate a programming language?

Body:
I have a course in which the proffesor has asked us to create a DSL for a our final project.  He presented us in the first courses xText with Eclipse.  This being a new course, I am still a bit fuzzy on what Domain Specific Languages means.

This is my current understanding:  a domain specific language is a language that is created for specific problems in software development.  Examples of DSL's are PHP, SQL, JavaScript and on the opposite are languages like Java , C# , C++ , Ruby etc.

Please feel free to correct me if I am wrong.

What I would like to know: is there is any tool for .NET/Visual Studio that is similar to Xtext, that allows me to define a grammar and be allowed to generate a programming language based on that with an activity diagram?


问:
How to document experimental or incomplete APIs like @deprecated?
Is there a good term that is similar but different than "deprecate" to mean that a method or API is in the code base but should not be used because its implementation is not complete or will likely change? (Yeah, I know, those methods shouldn't be public, yada yada yada. I didn't create my situation, I'm just trying to make the best of it.)

What do people suggest? Experimental, Incomplete, something else?

If I'm building javadoc documentation for this API that is still in flux, should I use the  @deprecated tag or is there a better convention? To me @deprecated implies that this API is old and a newer preferred mechanism is available. In my situation, there is no alternative, but some of the methods in the API are not finished and so should not be used. At this point I cannot make them private, but I'd like to put clear warnings in the docs.

答:
I've never seen anything like this in other APIs, since experimental or incomplete features have nothing to do in a public API.

Since you have no choices, just put a clearly visible warning that the part of the API is subject to change.


答:
Appropriate term is most likely incubator, this is one used by Google and Apache:

google-web-toolkit-incubator

The Official incubator of widgets and libraries for Google Web Toolkit...

Apache Incubator

...the gateway for open-source projects intended to become fully fledged Apache Software Foundation projects...

If you take a closer look at the projects referred to above, you may notice that "experimental" APIs (eg in GWT) tend to have "dedicated" package names, like com.google.gwt.gen2. This is to avoid polluting future "finalized" API intended for permanent public consumption - because, you know,

"Public APIs, like diamonds, are forever. You have one chance to get it right so give it your best..." (Joshua Bloch, How to Design a Good API and Why it Matters)

Title: How to document experimental or incomplete APIs like @deprecated?

Body:
Is there a good term that is similar but different than "deprecate" to mean that a method or API is in the code base but should not be used because its implementation is not complete or will likely change? (Yeah, I know, those methods shouldn't be public, yada yada yada. I didn't create my situation, I'm just trying to make the best of it.)

What do people suggest? Experimental, Incomplete, something else?

If I'm building javadoc documentation for this API that is still in flux, should I use the  @deprecated tag or is there a better convention? To me @deprecated implies that this API is old and a newer preferred mechanism is available. In my situation, there is no alternative, but some of the methods in the API are not finished and so should not be used. At this point I cannot make them private, but I'd like to put clear warnings in the docs.


答:
I would use @deprecated for purely practical reasons.

Although @deprecated does not convey the exact meaning that you would like, it has a significant advantage: Java compiler has built-in support for it. Compiling with -deprecation flag lets you find all places where you override a deprecated method, helping your users find suspicious code very quickly. You can use @deprecated Javadoc tag to explain what is really going on to anyone who cares to read your documentation. This is where you could tell the user that the API is experimental, should be used at their own risk, and so on.


答: "Getting better" often implies measuring your designs or code against something/someone better, carefully comparing what's different, learning from those differences, and continually trying to improve your future designs based on that.  Feeling too badly about finding out that you need to learn more will slow down this beneficial process.  If you move to someplace where there aren't people (or other resources) who can sometimes or always provide you with a better comparison, you may lose this opportunity to learn and slow down your process of betting better.</p>


答:
Your first question - what is a domain specific language... because this is too big to fit in a comment.

A domain specific language is a language that is designed to work within a particular problem domain.  For example, within the Unreal engine (used for first person shooters), there is a domain specific language called UnrealScript that allows one to modify the behavior of the Unreal engine.  This language is designed for solving general problems but rather is constrained to its specific domain.  Redcode (for corewars) would be another domain specific language. The language within Context Free Art is specific to its domain.

The idea is that with a domain specific language, one could create a DSL that closely maps the problem at hand.  At this point, it is easier to program in the DLS than it is to program in a general language even with the added libraries to handle the problem domain.

As for your second question - the tools in C#... I don't know C# and thus don't know the tools that well.  That said, back when I was taking a compiler class in college two of the tools that were used (and I have since used) are lex and yacc.  Over at Stack Overflow... Lex/Yacc for C#?


问:
How much is modern programming still tied to underyling digital logic?
First of all: I've got no academic background. I'm working primarily with Java and Spring and I'm also fond of web programming and relational databases. I hope I'm using the right terms and I hope that this vague question makes some sense.

Today the following question came to my mind: How much is modern programming still tied to the underlying digital logic? With modern programming I mean concepts like OOP, AOP, Java 7, AJAX, … I hope you get the idea.

Do they no longer need the digital logic with which computers are working internally? Or is binary logic still ubiquitous when programming this way? If I'd change the inner workings of a computer overnight, would it matter, because my programming techniques are already that abstract?

P. S.: With digital logic I mean the physical representation of everything "inside" the computer as zeroes and ones.

Changed "binary" to "digital".

答:
Short version is that modern programming is NOT tied to the underlying logic within the chips themselves.

Most / all modern programming languages abstract away that level of interaction.  Even if you got to the level of Assembly or specific machine code, you're still not working at the level of the logic on the chip itself.

Digital logic design (which is what you're asking about) is still performed for various chips, but this is definitely a small subset of the programming that goes on today.  There are high-level interpreters that facilitate the design and the necessary logic reductions, but they bear little resemblance to something you would recognize as a Java programmer.

Additional thoughts, in broad terms:

The CPU is a chip consisting of bazillions of transistors that are wired together in various ways.  The specifics of the wiring is dictated by Boolean Logic and available reductions.  Ultimately, the chip offers up an API through the instruction set.

High level languages such as java are ultimately compiled down to machine language, which is a series of instructions being fed to the chip.  Java complicates things a little since it goes through a virtual machine in order to generate the chip-level instructions.  Other languages use a compiler to generate the associated assembly and machine code.

Even when a high level programming language offers bitwise operations, these operations are not generating new Boolean logic to be executed by the chip.  The bitwise operations are exposed through the instruction set of the chip and the compiler / VM allow the high level language to access those operations.

There is an exception to all of this, which is the realm of programmable logic controllers (PLCs).  Here, the programmer is ultimately creating the Boolean Logic involved that will drive the chip.  However, this logic generation is still generally obscured from the programmer and is built by the compiler for the PLC.  You could therefore use the same | similar high level code with a different compiler / PLC and it would (should) still work just fine.  There are some nuances with portability, but I'm arbitrarily declaring that out of scope for the question...


答:
Many programmers who use higher-level programming languages do not need to be aware of the binary representation of the data that they work with. That doesn't mean the internal binary representation is not important, it just means that it has been hidden behind a layer of abstraction which most of us do not need to peer through. High-level languages such as Java still have bitwise operators for situations where manipulating binary data is necessary.

One place where low-level binary representations of data can sneak up into a high-level language programing environment is when you use floating point numbers.

Title: How much is modern programming still tied to underyling digital logic?

Body:
First of all: I've got no academic background. I'm working primarily with Java and Spring and I'm also fond of web programming and relational databases. I hope I'm using the right terms and I hope that this vague question makes some sense.

Today the following question came to my mind: How much is modern programming still tied to the underlying digital logic? With modern programming I mean concepts like OOP, AOP, Java 7, AJAX, … I hope you get the idea.

Do they no longer need the digital logic with which computers are working internally? Or is binary logic still ubiquitous when programming this way? If I'd change the inner workings of a computer overnight, would it matter, because my programming techniques are already that abstract?

P. S.: With digital logic I mean the physical representation of everything "inside" the computer as zeroes and ones.

Changed "binary" to "digital".


问:
"Viral" license that only blocks legal actions of user and developer against each other
I was thinking a lot about software licensing lately, because I would like to do some coding. I'm not an expert in all those licenses, so I came up with my own idea, and before I will put in on paper, I would like to make sure that I didn't reinvent a wheel, so maybe I would be able to use something that exists.

Main idea behind my license is to guarantee freedom of use the software, but not "freedom to" (positive) (e.g. freedom to having source code), but "freedom from" (negative) (strictly from legal actions against you). It would be "viral" copyleft license.

You would be able to without fear do everything you want with the software (and binaries e.g. reverse engineering), as long as You will include information about author and/or authors, and all derivative works will be distributed with the same license. I'm not interested in anything that would restrict a freedom of company to do something like "tivoization". I'm just trying to accomplish something that would block any legal actions of user and developer, targeted against each other, with the exception of basic attribution.

Does exist something like that?

答:
Well, if you do not care what is done with your product provided that you are properly attributed for your part in it, maybe you could go with a Creative Commons: Attribution license.

It is not designed for software, but for a more generic concept of “work”. However, according to your question you do not care about source redistribution, or any other restriction other than you being properly attributed. CC:By would give you that.

The fact that it is not a software license per se is what I think makes it suit your needs best. Any software license will contain software-specific restrictions, and you seem not to want any of those.


答:
The easiest way to go is a fluent interface. This requires no tools at all, and gives you great IntelliSense support, but you still have to write things in a .NET-kinda way, such as

```<code> Mix.Paint(Color.Green).With.Paint(Color.Red);
</code>```

Alternatively, you can write beautiful DSLs in Boo. There is an entire book on that subject.

Body:
The easiest way to go is a fluent interface. This requires no tools at all, and gives you great IntelliSense support, but you still have to write things in a .NET-kinda way, such as

 Mix.Paint(Color.Green).With.Paint(Color.Red);

Alternatively, you can write beautiful DSLs in Boo. There is an entire book on that subject.


答:
Adding to the answer by @Frustrated - One other thing that still has us thinking about the underlying digital logic is threading and parallelism. Until we can take our current high level language programs and, without major change, run them on an n Core processor using all n Cores, then it's arguable we are still locked into thinking about the underlying hardware.
We are still 'learning' (i.e. the industry does not have techniques and tools that are widely adopted, reliable and efficient) how to write massively parallel programs. </p>


答:
How much is modern programming still tied to underyling digital logic?

Your question is a lot like asking: How much of everyday life is still tied to physics? Like physics, the digital nature of computers is pervasive: it's what makes them work, and it's what limits them. We may not think in terms of 1's and 0's and AND's and OR's and NOT's when we program, but those are still the atoms that make up our world and their effects are easy to detect. Here are a few examples:

A bit is always either 1 or 0, never something else, and never both at the same time.

A memory location can only hold one value at a time.

Computers are deterministic: given the same data and code, you get the same result every time.

Any value can be represented with arbitrary precision, but most values can't be represented exactly.

If I'd change the inner workings of a computer overnight, would it
  matter, because my programming techniques are already that abstract?

If you change the inner workings of the computer, you'll have to change the way the abstraction layer(s) is implemented so that the abstraction is maintained. For example, if you've got a Python program, it'll run on any machine that provides a Python interpreter. If you replace the Intel processor with an ARM processor, it's a relatively simple thing to modify the Python interpreter so that it continues to work. If you substitute an analog processor or a quantum processor, though, you'll have fundamentally changed the rules of the game, and it may or may not be possible to implement Python correctly. Python is the abstraction layer in this example, but the same goes for any layer.


答:
I'd also like to add (in addition to the great answers) that there is more to it than "He can create a better design than me". The other answers focus on how you can get better at Design, which is all and good... but...

I bet money that YOU can do something better than your co-worker. Not to create a pissing match or anything (You can do Y better? Screw you, I can do X better!), but to point out the truth that everyone has strengths and weaknesses.

At my job there are 4 developers. There are times where the two main "programmers" can create stuff that just leaves me in the dust. Makes my head spin trying to wrap my head around their creations.

But I'm much better at SQL and command-line scripting than they are, and can automate stuff that leaves THEM in the dust.

Are they better than me? In some area's definitely. Hell, in a lot of area's they are - I am the junior developer at my shop by far and individually they have years of experience on me. Despite those years of experience, I am better in some area's than even they are.

Stop focusing on the fact that someone is better at X than you are. That person, without trying or even thinking about it, might be able to out-design you even after you practice at it for the next 10 years. Not that you shouldn't work on fixing your weaknesses at all, but remember than for every strength there is a weakness.

Focus on both - Strengths and weaknesses - of you and your co-workers.


答:
Another vote that it's almost always wrong.  I find two basic cases where it's the proper answer, though:

1)  A method that basically just calls a bunch of other methods and does no real work itself.  You have a process that takes 50 steps to accomplish, you get a method with 50 calls in it.  There's usually nothing to be gained by trying to break that up.

2)  Dispatchers.  OOP design has gotten rid of most such methods but incoming sources of data are by their very nature just data and thus can't follow OOP principles.  It's not exactly unusual to have some sort of dispatcher routine in the code that handles the data.

I would also say that one should not even consider the question when dealing with autogenerated stuff.  Nobody's trying to understand what autogenerated code does, it matters not one iota whether it's easy for a human to understand.

Title: Are long methods always bad?

Body:
So looking around earlier I noticed some comments about long methods being bad practice.

I am not sure I always agree that long methods are bad (and would like opinions from others).

For example I have some Django views that do a bit of processing of the objects before sending them to the view, a long method being 350 lines of code. I have my code written so that it deals with the parameters - sorting / filtering the queryset, then bit by bit does some processing on the objects my query has returned.

So the processing is mainly conditional aggregation, that has complex enough rules it can't easily be done in the database, so I have some variables declared outside the main loop then  get altered during the loop.

```<code>variable_1 = 0
variable_2 = 0
for object in queryset :
     if object.condition_condition_a and variable_2 > 0 :
     variable 1+= 1
     .....
     ...
     .
      more conditions to alter the variables

return queryset, and context
</code>```

So according to the theory I should factor out all the code into smaller methods, so That I have the view method as being maximum one page long.

However having worked on various code bases in the past, I sometimes find it makes the code less readable, when you need to constantly jump from one method to the next figuring out all the parts of it, while keeping the outermost method in your head.

I find that having a long method that is well formatted, you can see the logic more easily, as it isn't getting hidden away in inner methods.

I could factor out the code into smaller methods, but often there is is an inner loop being used for two or three things, so it would result in more complex code, or methods that don't do one thing but two or three (alternatively I could repeat inner loops for each task, but then there will be a performance hit).

So is there a case that long methods are not always bad? Is there always a case for writing methods, when they will only be used in one place?

UPDATE:
Looks like I asked this question a over a year ago.

So I refactored the code after the (mixed) response here, split it into methods. It is a Django app retrieving complex sets of related objects from the database, so the testing argument is out (it would have probably taken most of the year to create relevant objects for the test cases . I have a "this needs done yesterday" type work environment before anyone complains).
Fixing bugs in that part of the code is marginally easier now, but not massively so.

before :

```<code>#comment 1
bit of (uncomplicated) code 1a
bit of code 2a

#comment 2
bit of code 2a
bit of code 2b
bit of code 2c

#comment 3
bit of code 3
</code>```

now:

```<code>method_call_1
method_call_2
method_call_3

def method_1
    bit of (uncomplicated) code 1a
    bit of code 2a

def method_2
    bit of code 2a
    bit of code 2b
    bit of code 2c

def method_3
    bit of code 3
</code>```


答:
Only to combine what I said with what @Prototype Stark said: When you have a SDK like Windows, you get plenty of libraries and those come as object code. The same kind you would get from a C/C++ compiler. Your favorite ASM linker will link to those libraries and turn everything into a nice executable (depending of your OS of choice).

And how can you use WinAPI with ASM? Well, you must follow the calling conventions. You can even specify this when you're compiling C code with some special keywords.

Title: Are there such thing as assembly SDK's?


问:
How to find people to help translate my open source project?
I'm a big StackOverflow fan, but I think this question belongs here, correct me if I'm wrong.
So basically I'm trying to localize my plugin in as many languages as possible. I posted a section on the docs to reach people that wants to help translating but I only got one contributor that attached a German translation. So far I got 4 languages, English, Spanish, French and German.

So my question is, how do you guys translate your projects? Where do you find people interested in contributing? Does anybody use Google translate to do the job?

答:
There are really only two ways to get someone to do work for you.  Either you pay them for it, or you get them to want to do it without being paid.

Assuming you're not looking to hire translators, your best bet is to do exactly what you're doing--make it known among your users that you're looking for localization--and then try to increase the size of your user base.  The more people you have using the program, the more likely you are to run into someone who has the skills and the desire to help you out.


问:
Should I build a multi-threaded system that handles events from a game and sorts them, independently, into different threads based on priority?
Can I build a multi-threaded system that handles events from a game and sorts them, independently, into different threads based on priority, and is it a good idea?

Here's more info:

I am about to begin work on porting a mid-sized game from Flash/AS3 to Java so that I can continue development with multi-threading capabilities.

Here's a small bit of background about the game:

The game contains numerous asynchronous activities, such as "world updating" (the game environment is constantly changing based on a set of natural laws and forces), procedural generation of terrain, NPCs, quests, items, etc.,  and on top of that, the effects of all of the player's interactions with his environment are programmatically calculated in real time, based on a set of constantly changing "stats" and once again, natural laws and forces.

All of these things going on at once, in an asynchronous manner, seem to lend themselves to multi-threading very well.

My question is:

Can I build some kind of central engine that handles the "stacking" of all of these events as they are triggered, and dynamically sorts them out amongst the available threads, and would it be a good idea?

As an example:

Essentially, every time something happens (IE, a magic missile being generated by a spell, or a bunch of plants need to grow to their next stage), instead of just processing that task right then and adding the new object(s) to a list of managed objects, send a reference to that event to a core "event handler" that throws it into a stack of all other currently queued events, which then sorts them out and orders them according to urgency, splits them between a number of available threads for as-fast-as-possible multithreaded execution.

答:
Task and event-based multithreading can work really well--your ideas have similarities to my present multithreading work in native C++.  You start with threads that each have their own well-defined roles to play in the application, that will collaborate with one another by posting tasks and events between them to be run.

Each thread does its own thing, and from time to time processing its own events and tasks that have been queueing up.  A virtual blocking state puts waiting threads to work while they block.  Every thread becomes an event processor, and having nothing to do becomes the only way you ever hard block.

Getting multithreading right is really complex as it is, but it gets much more complex with priority systems.  Most events have to occur in the order posted anyway, and priorities can reorder things to cause starvation in the most unexpected places.  Remember, you have to be able to debug this stuff.  I just keep normal and low priority queues, and use a low-priority flag in the task to choose the queue at post(event) time.  Really know that you are getting tangible from your priority system, before electing to use it.

This model scales nicely to any number of processors, because it is decentralized and allows all threads to be posting and processing events concurrently.  The round trip to ping-pong a task between threads on different processors takes under 500 machine cycles, making it economical for even short tasks.  Task and event execution is fast, with its data now contained within the target thread and ready to roll.


答:
Even though they are a Spanish speaking country, you may be doing them a better favor by using English.

What if they hire Indian consultants to maintain the project? They use English.  What if they hire Russians to maintain the project. They use English. What if they hire a Turkish team? They use English. What if they hire an Egyptian team? They use English. What if... English.

For better or worse, English is the language of computing. Using it makes the project accessible to a larger pool of world developers.


答:
It is nice of you to do this, but preferably write code in english!, otherwise it might be a headache for the next maintainer (even if he/she speaks spanish)

You should ask if it is possible for you to use english for all development since it is the default way most programmers/engineers write code. I would say it is the best practice around and it shouldn't be that much complicated even for non-english speakers.

Most resources to learn how to program are in english, so chances are most programmers are already exposed to english. Additionally, all language keywords tend to be spanish (except for PHP's "Paamayim Nekudotayim" compiler token variable, or if you use some wacky spanish compiler).

I am Mexican, and I have never ever written code in spanish, nor I would like to. English has shorter, cleaner, sweeter and more predictable words for programming than spanish.

Take for example the word for year, which is *año*, if you write it with an *n* instead of an *ñ* you would get *ano* which means *anus*.

Additionally, you most probably would have to take off all accents, which —if you have the some sense of grammar— can/will make words sound funny in your head (maybe I'm just a grammar nazi).

Finally, some people just give up trying to find the appropriate name for a variable in spanish and end up writing it in english, so surprise, you now have a bilingual codebase.

P.S.: I would seriously punch someone in the face if I found they were abbreviating variables everywhere and I had to maintain that code... then I would quit.


问:
How do programmers quit a job?
I'm thinking about leaving my current employer and wondering how one goes about that process in the programming world. We have a lot of projects on the go at the moment and I'm the only developer. We have 4-5 projects that are fairly big and need to be done in the next few months and even a few longer than that.

I'm leaving because I'm the only employee and that's doing me no good. I'm young and want to learn, so a team would be nice. It's also too much work and the company is managed horribly.

I have no contract to worry about so I could theoretically quit and just not come back without notice. Just wondering how this is normally handled.

Should I write a resignation letter

How much notice should I give

Should I give a reason for leaving

Should I go to my boss who is the main reason I'm leaving or go to his boss?

Overview of replies

From the feedback here, it looks as though it's best to give 2-4 weeks of notice, and present a written resignation. Don't go into detail explaining why you're leaving in most cases. Don't burn bridges. Be professional.

答:
I've resigned from several jobs.  To answer your questions from my experience:

Should I write a resignation letter?

You can if you want to, but you generally don't need to unless they request one.  You can just go to your boss, ask for a few minutes of his time, and say something like "I'm planning to resign.  Do you need written notice, or is this sufficient?  How much notice do you need?"

How much notice should I give?

The courteous thing to do is ask your boss how much he thinks he needs.  In the US, two weeks is standard for any job short of the highest levels of management (and at that level, you most likely would have a contract specifying a notice period).

Should I give a reason for leaving?

No.  Companies are the way they are because they want to be that way.  Companies that want to change will make efforts to do so.  If they haven't made that effort, they won't suddenly do it just because you call attention to their shortcomings.

The best thing is to say you've enjoyed working there (if you can say it with a straight face), but it's time for a change, or "new challenge", or some such.  You always want to keep doors open, and pointing out flaws is never a way to appeal to anyone.

Should I go to my boss who is the main reason I'm leaving or go to his boss?

While you don't have to care what your boss thinks of you, again, this is a matter of keeping good relations, which is a good thing to do in every circumstance.  Go to your boss, tell him you're leaving, and don't give any negative reasons.

Even if you swear you'll never work there again, you never know what the future holds.  Perhaps someday you'll be interviewing with another company and someone from the old company will be there now and remember you.  Will they say, "He's a good programmer; it's a shame he left"?  Or will they say, "He seemed like a good programmer, but he quit saying the job sucked and his boss was an idiot, and I don't ever want to work with someone like that again"?

In addition to all that...

Leave for your successor exactly what you'd want to have left for you.  Write notes, documents, whatever that person will need.  Make a list of network or database permissions he/she will need.  Create a document describing each existing project and its current status, recent changes, etc.  Create a document on the new projects and some tips on whom to talk to about them.

No matter how resentful you may be toward the place (and believe me, I understand and have worked in similar places), it's never wrong to be professional and courteous even to people who don't deserve it.  In the city I live in, I've met many people who've worked in places I've worked in and know the same people I do.  For better or worse, your reputation will probably follow you, so as you plan your graceful exit, think carefully about what you want that reputation to be.

Title: How do programmers quit a job?


问:
Servlet : Usage of Constants.java class vs context param
I'm just wondering whether to keep some of my variables in Constants class or keep it in web.xml

Say, I want to keep a variable of Facebook graph API prefix or api_key, client_id

From my understand, the difference between Constants.java and web.xml is web.xml is easier to rewrite on compile using ant.

So, you can replace your variables in web.xml according to what environment you are building you app for. (client_id varies by development environment/production environment, for example)

If I understand it right, then Facebook graph API prefix should be kept in Constants.java (because it always is "https://graph.facebook.com/") and api_key, client_id should be kept in web.xml?

What's the proper way to use them?

答:
In your scenario, these values are best kept in properties file. Create a properties file in classpath and read it at your application startup to instantiate the values. Or you can read them fresh for each request, if they tends to change. Java provides very easy way for reading/writing properties file with Properties class.

You can also externalize the properties file if you want. i.e. put them into user home directory to make them completely independent. Think of it, when you change the value and the running application takes the new value without re-build or even re-deployment.


答:
It's perfectly alright to write lengthy functions. But it varies on the context whether you really need or not. For e.g. some of the best algorthms are expressed best when it a peice. On the other hand, a large percentage of routines in object-oriented programs will be accessor routines, which will be very short. Some o of the lengthy processing routines which has lengthy switch-cases,if conditions can be optimized via table driven methods.

There's an excellent short discussion in Code Complete 2 about the length of the routines.

The theoretical best 497 maximum length is often described as one or two pages of program listing, 66 to 132 lines. Modern programs tend to have volumes of extremely short routines mixed in with a few longer routines.

Decades of evidence say that routines of such length are no more error prone than shorter routines. Let issues such as depth of nesting, number of variables, and other complexity-related considerations dictate 535 the length of the routine rather than imposing a length

If you want to write routines longer than about 200 lines, be careful. None of the studies that reported decreased cost, decreased error rates, or both with larger routines distinguished among sizes larger than 200 lines, and you’re bound to run into an upper limit of understandability as you pass 200 lines of code.
536 restriction per se.

Title: Are long methods always bad?


答:
GPL does exactly what you're asking, with the exception that it mandates source distribution. Source distribution, with GPL, is necessary to achieve the "freedom to" part: without sources, users cannot freely modify the software, which is the primary goal of the GPL.

Alternatively, BSD-style licenses (including other liberal licenses such as MIT, Apache, Mozilla, etc.) also do exactly what you want, except for the viral part. They basically instate the "freedom from" part (i.e., the user can do anything with the software they want, except sue the author and claim that it's their own, and the author can't restrict the user any more than that).

Both licenses allow selling the software for money, putting DRM on it (although that's pointless, since the source is freely available), reverse-engineering binaries, etc.

A halfway solution like you propose is problematic, and not very useful either: if you make it viral, then that's already a large enough obstacle for many corporate users, and whether the modified source has to be published or not is relatively meaningless (more so if you explicitly allow reverse engineering); at the same time, you miss out on the actual benefit of a GPL-like license, namely that it encourages users to publish their changes so that they can be merged upstream.

Considering all this, you should think very hard whether the world needs yet another software license; most likely, it does not. There's a whole zoo of both viral and non-viral licenses, and some of them have even been held up in court.

TL;DR: A license like you propose has no benefits over either BSD or GPL; decide for one of them and live with the downsides.


问:
What does well written, readable tests look like?
Doing unit testing for the first time at a large scale, I find myself writing a lot of repetitive unit tests for my business logic. Sure, to create complete test suites I need to test all possibilities but readability feels compromised doing what I do - as shown in the psuedocode below.

How would a well written, readable test suit look like?

```<code>describe "UserEntity" ->
  it "valid name validates"
    ...
  it "invalid name doesnt validate"
    ...

  it "valid list of followers validate"
    ..
</code>```

答:
In general, a well written test suite inevitably contains some repetition, as you are testing the same method over and over with different parameters and results. But if you have significant chunks of duplicate test code, you can improve it by refactoring. Extract repeated code parts into separate methods which you can then reuse.

For a more detailed treatment, check out Growing Object-Oriented Software Guided by Tests. It contains lots of tips and practical examples on how to make your test code more concise, fluent and readable.


答:
in my eyes a good test looks like:

```<code>/*
description of what is tested (include mentions of whether it's general case, edge case, exceptional case)

include references to any relevant bug reports
*/
void testSomthing(){
    prepare mocked behavior (if any)

    set the input for the method

    set expected_output from the test

    gotten_output=do call to tested method

    assertEquals(gotten_output, expected_output);
}
</code>```

repeat for each test

without the documentation you won't know which of the 2 dozen tests on a method test what

Title: What does well written, readable tests look like?

Body:
Doing unit testing for the first time at a large scale, I find myself writing a lot of repetitive unit tests for my business logic. Sure, to create complete test suites I need to test all possibilities but readability feels compromised doing what I do - as shown in the psuedocode below.

How would a well written, readable test suit look like?

```<code>describe "UserEntity" ->
  it "valid name validates"
    ...
  it "invalid name doesnt validate"
    ...

  it "valid list of followers validate"
    ..
</code>```

Body:
in my eyes a good test looks like:

/*
description of what is tested (include mentions of whether it's general case, edge case, exceptional case)

include references to any relevant bug reports
*/
void testSomthing(){
    prepare mocked behavior (if any)

    set the input for the method

    set expected_output from the test

    gotten_output=do call to tested method

    assertEquals(gotten_output, expected_output);
}

repeat for each test

without the documentation you won't know which of the 2 dozen tests on a method test what


答:
I really do like the AAA pattern.</p>

```<code>// Arrange
arrange needed mocks, stubs, parameters, whatever

// Act
test

// Assert
validate test
</code>```

Body:
I really do like the AAA pattern.

// Arrange
arrange needed mocks, stubs, parameters, whatever

// Act
test

// Assert
validate test


答:
I don't know if someone has already mentioned this, but one of the reasons long methods are bad is because they usually involve several different levels of abstraction. You have loop variables and all kinds of things happening. Consider the fictitious function:

```<code>function nextSlide() {
  var content = getNextSlideContent();
  hideCurrentSlide();
  var newSlide = createSlide(content);
  setNextSlide(newSlide);
  showNextSlide();
}
</code>```

If you were doing all the animation, calculation, data access etc in that function it would have been a mess. The nextSlide() function keeps a consistent abstraction layer (the slide state system) and ignores others. This makes code readable.

If you have to constantly step into smaller methods to see what they do then the exercise of dividing up the function has failed. Just because the code you are reading is not doing obvious things in child methods doesn't mean child methods are a bad idea, just that it was done incorrectly.

When I create methods I usually end up dividing them up into smaller methods as a sort of divide and conquer strategy. A method like

```<code>   if (hasMoreRecords()) { ... }
</code>```

is certainly more readable than

```<code>if (file.isOpen() && i < recordLimit && currentRecord != null) { ... }
</code>```

Right?

I agree about absolute statements are bad and also agree that usually a long method is bad.

Title: Are long methods always bad?

Body:
I don't know if someone has already mentioned this, but one of the reasons long methods are bad is because they usually involve several different levels of abstraction. You have loop variables and all kinds of things happening. Consider the fictitious function:

function nextSlide() {
  var content = getNextSlideContent();
  hideCurrentSlide();
  var newSlide = createSlide(content);
  setNextSlide(newSlide);
  showNextSlide();
}

If you were doing all the animation, calculation, data access etc in that function it would have been a mess. The nextSlide() function keeps a consistent abstraction layer (the slide state system) and ignores others. This makes code readable.

If you have to constantly step into smaller methods to see what they do then the exercise of dividing up the function has failed. Just because the code you are reading is not doing obvious things in child methods doesn't mean child methods are a bad idea, just that it was done incorrectly.

When I create methods I usually end up dividing them up into smaller methods as a sort of divide and conquer strategy. A method like

   if (hasMoreRecords()) { ... }

is certainly more readable than

if (file.isOpen() && i < recordLimit && currentRecord != null) { ... }

Right?

I agree about absolute statements are bad and also agree that usually a long method is bad.