问:
Is running an executable as a child process the same as linking a library?
I'm planning on running an executable as a child process in my program (e.g. using Ruby's popen or C's exec() family of functions). However, the executable I'm planning on running is licensed through the GPL.

The GPL, as I understand it, requires that all linked code to GPL licensed code needs to also be GPL.

But there's also an "arm's length" exception, discussed in the FAQ:

However, in many cases you can distribute the GPL-covered software alongside your proprietary system. To do this validly, you must make sure that the free and non-free programs communicate at arms length, that they are not combined in a way that would make them effectively a single program.

Would runnning an executable as a child process be part of this exception, or would it still be considered "linking" for the purposes of the license?

If it is considered "linking", how does it differ from running program, like Nmap, from the a command line?

答:
You are going to have a hard time getting a good answer to this question. The issue is that the correct answer to your question relies on a complicated legal question for which there is as yet no answer.

I am not a lawyer, but I'll tell you my own position, for what that's worth. Linking, because it does not involve a creative process, cannot create a new work for copyright purposes. Linking is legally like stapling. Linking two works together is just like stapling two DVDs together. The output is, legally, the same as the input. It is the two works.

So if your work was not a derivative work before you linked it, it is not a derivative work after you linked it. The GPL requires source code of distributed works be distributed. So the question is whether the work whose source code you don't want to distribute is a derivative work. Since linking can't change this, the question comes down to whether the work was a derivative work before you linked it.

Legally, with only a few exceptions by statute that don't apply here, a work is a derivative work if it contains significant protectable expression taken from the other work. Note that functional elements are not protectable expression, only creative elements are.

So the answer to your question is: If your code contains sufficient protecable expression taken from a work covered by the GPL to make it a derivative work of that work, then yes. Otherwise, no.


问:
How do I isolate difficult to reproduce bugs?
There's a bug in my program. Doesn't really matter what the platform is. Every so often, a row in a ListView is the wrong color. I tried setting a watchpoint for the variable that is supposed to dictate the color of the row, and it doesn't change... I am guessing it means the problem could be in the framework code. I've only witnessed it happen once.. My client has noticed it though, and wants it fixed. No idea where to start. Someone told me to artificially increase the load of the program.

What are some methods for hunting down difficult to find bugs?

答:
Use a memory debugger like valgrind, or a debugging memory allocator like Electric Fence, or on Mac OS X or the iPhone Simulator (but unfortunately not actual iOS devices), Guard Malloc.

What programming language are you using?  If you told me maybe I could offer more helpful advice.

Telling us the platform would help too.  For example Apple's frameworks for both Mac OS X and the iOS write to the console.  Your client can use the iPhone Configuration Utility to capture console logs.  If you are calling one of Apple's APIs incorrectly, it is possible that your error is logged.

If your language is C or Objective-C, you can use the CLANG Static Source Code Analyzer.  It's built into Xcode now, and will work on other platforms as a command-line tool if you build it from source.

ContentLicense: CC BY-SA 3.0


答: Artificially increasing the load isn't a bad idea, mostly because if there is a bug it'll increase the chance of it appearing, but then you need to make sure you're logging the program state constantly to work out where it's gone wrong.</p>

Title: How do I isolate difficult to reproduce bugs?

Body:
There's a bug in my program. Doesn't really matter what the platform is. Every so often, a row in a ListView is the wrong color. I tried setting a watchpoint for the variable that is supposed to dictate the color of the row, and it doesn't change... I am guessing it means the problem could be in the framework code. I've only witnessed it happen once.. My client has noticed it though, and wants it fixed. No idea where to start. Someone told me to artificially increase the load of the program.

What are some methods for hunting down difficult to find bugs?


问:
Getting management to hire a new developer?
I've been working here for about 3 months now, and this company has been around since 2003. I've the only full time developer, and I don't know what happened to the part time guy who was doing work before I got hired, I haven't seen him since a month after I started, aside from a couple emails.

Essentially, that makes me the only developer, trying to balance adding new features to our main product (subscription website service), developing an Android-based version of the product, handling client issues, working on migrating clients from old version to new version (and the headaches that will result from this), fixing issues with a signup service for out ISP side of things, and helping with tech support for the ISP side. Not to mention the massive overhaul I'm fairly certain the database needs, that will mean at least a few months' work.

My bosses hired an intern to help me with the Android version, but the one boss randomly went to England until December, taking the intern with him.

Any tips I can use on convincing management to hire somebody else? Even if just a second full time support guy to help with the phone calls?

答: Prioritize everything and publish it if you have multiple stakeholders.  When a new task comes in ask where it goes on the priority list.  You should not have more than one person setting this priority either, there should be someone or a set group making this decision.  When they realize that certain things are never going to get done based on your workload (and you should stick to 40 hour weeks when estimating workload), then you can bring up the need for a dedicated assistant.  Think about assigning them the tasks that you don't want, you were there first so don't let them bring in someone to do the android app while you toil away on tickets and meaningless crap.</p>

ContentLicense: CC BY-SA 2.5


问:
How to automate a tasks system in a CMS software
I'm currently developing v2.0 of my personal cms. However, I'm stuck. I strongly feel that my old solution for "tasks" is not very dynamic and must be revisited. Currently I'm looking the whole concept of how to dynamically add tasks and run them.

What I mean by task system

Like always in cms software, there are a lot of content, such as images, dynamic files, database entries, etc. I created my own task system aka. The Parser (sounds evil right?) It is made of two files, one parser-classes and other the triggers with the $parser = new ParserClasses(); (I hope you understand what I mean.) Some of the features the parser does:

First turn off the site (after the parser is done, turn it back on)

Checks for active files (files that don't have parent mysql entry, will be deleted)

Clears out old cache

Generates new static cache

Deals with languages and translation related cache

and other tasks related to cms management and maintenance

Why do I want to make it more automatic

Basically all plugins and some themes (add-ons in general,) use this task system. But the problem is that it's not very dynamical, because all functions sit in one huge class. This means that the add-on cannot be installed without opening your php editor.

How I was planning to do it

First I would create my own task language, with preset functions to handle files, cache,  etc. (very broad example: GenerateFreshCache('pages')). Now, storing it is the issue.. My ideas are:

To create tasks-table in mysql database. Then add tasks there, with my task language. Later while() them from the database and eval(). (This is a good way, because I can add scheduled times and similar in function, for CRON jobs. Or even categorize the tasks.)

Add .php files to some folder, where they get loaded. They will probably use the same task language, but don't need to be eval()'ed. (I'm scared that this would slow down the parser, because so many files are getting included.)

However, I'm not sure about those ideas and I'm hoping someone has already come across this functionality and can give me pointers. All crazy ideas and concepts are welcome, thanks in advance.

Conclusion

Thanks to everyone who replied. I picked the answer, that helped me the most and not "ohh, too much work, use framework". My task systems core is done and working. Took 2-3 days and currently ~600 lines of code and two classes (outer and inner core.) I finally ended up with two mysql tables, one with tasks (task db) and another with combos (multiple tasks combined together for easier run.) Also, added some features so it would be safe to run via ajax (cant really talk about that, top secret^^). There are might be too many loops, handling the tasks parsing, however this makes adding new tasks very very simple.. Just add it to tasks DB and add the task to cron-list-automatic-run-list or run it straight up via the admin panel.

答:
I like the idea of storing tasks in the db. I do not like the idea of create a "task language". Why not store everything in the database? Your task table would include an action code and the associated content. When you poll the db for tasks you would have access to all of the content needed to generate the pages. You perform the action based upon the code and can track timestamps of when the actions were taken. This negates your #2 of adding file to a folder.

The generated pages can be stored in the db. Heck you could even translate them on the fly (if they are not HTML already). After you successfully operate on a task you can mark it off as complete. This type of system gives you the ability to re-enable older tasks and doesn't force you you to generate files and store them in the file system (which could be a problem in a hosted environment).

This type of system is used by Wordpress and seem to function just fine.


问:
How to turn truth table into smallest possible if / else block
How can I take a truth table and turn it into a compacted if block?

For instance, let's say I have this truth table where A and B are conditions and x, y and z are possible actions:

```<code>A B | x y z
-------------
0 0 | 0 0 1
0 1 | 0 0 1
1 0 | 0 1 0
1 1 | 1 0 0
</code>```

This could transform into below if block:

if(A)
{
    if(B)
    {
        do(x)
    }
    else
    {
        do(y)
    }
}
else
{
    do(z)
}
```

This is an easy sample, but I frequently have several conditions that combined in different ways should produce different outputs and it gets hard to figure out the most compacted and elegant way to represent their logic in an if block.

答:
If you are designing from a Karnaugh map, then the code may as well look that way too:</p>

```<code>//                   a      b
def actionMap = [ false: [false: { z() },
                          true:  { z() }],
                  true:  [false: { x() },
                          true:  { y() }]]

actionMap[a][b]()
</code>```

Body:
If you are designing from a Karnaugh map, then the code may as well look that way too:

//                   a      b
def actionMap = [ false: [false: { z() },
                          true:  { z() }],
                  true:  [false: { x() },
                          true:  { y() }]]

actionMap[a][b]()


答:
Congratulations, you are working on re-inventing the message queue. It is ok, everyone does it at least once. I know I've done it a half dozen times. In any case, rather than inventing a task language and taking on that complexity, what you should look for is a message queueing product for PHP. I would make a recommendation, but I haven't done anything more than monkeypatch in PHP in recent memory so I'm not sure which platform to start with.

If you decide you must do it yourself, I'd avoid writing a task language -- just pass a task type plus data. Instantiate tasks via a factory of some sort, pass in data. Don't forget lots of logging and such so you can have an idea why your task is silently failing.

Title: How to automate a tasks system in a CMS software

Body:
I'm currently developing v2.0 of my personal cms. However, I'm stuck. I strongly feel that my old solution for "tasks" is not very dynamic and must be revisited. Currently I'm looking the whole concept of how to dynamically add tasks and run them.

What I mean by task system

Like always in cms software, there are a lot of content, such as images, dynamic files, database entries, etc. I created my own task system aka. The Parser (sounds evil right?) It is made of two files, one parser-classes and other the triggers with the $parser = new ParserClasses(); (I hope you understand what I mean.) Some of the features the parser does:

First turn off the site (after the parser is done, turn it back on)

Checks for active files (files that don't have parent mysql entry, will be deleted)

Clears out old cache

Generates new static cache

Deals with languages and translation related cache

and other tasks related to cms management and maintenance

Why do I want to make it more automatic

Basically all plugins and some themes (add-ons in general,) use this task system. But the problem is that it's not very dynamical, because all functions sit in one huge class. This means that the add-on cannot be installed without opening your php editor.

How I was planning to do it

First I would create my own task language, with preset functions to handle files, cache,  etc. (very broad example: GenerateFreshCache('pages')). Now, storing it is the issue.. My ideas are:

To create tasks-table in mysql database. Then add tasks there, with my task language. Later while() them from the database and eval(). (This is a good way, because I can add scheduled times and similar in function, for CRON jobs. Or even categorize the tasks.)

Add .php files to some folder, where they get loaded. They will probably use the same task language, but don't need to be eval()'ed. (I'm scared that this would slow down the parser, because so many files are getting included.)

However, I'm not sure about those ideas and I'm hoping someone has already come across this functionality and can give me pointers. All crazy ideas and concepts are welcome, thanks in advance.

Conclusion

Thanks to everyone who replied. I picked the answer, that helped me the most and not "ohh, too much work, use framework". My task systems core is done and working. Took 2-3 days and currently ~600 lines of code and two classes (outer and inner core.) I finally ended up with two mysql tables, one with tasks (task db) and another with combos (multiple tasks combined together for easier run.) Also, added some features so it would be safe to run via ajax (cant really talk about that, top secret^^). There are might be too many loops, handling the tasks parsing, however this makes adding new tasks very very simple.. Just add it to tasks DB and add the task to cron-list-automatic-run-list or run it straight up via the admin panel.


问:
How far can I push refactoring without changing external behavior?
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?

答:
The best way to define "external behaviour," in this context, may be "test cases."

If you refactor the code and it continues to pass the test cases (defined before the refactoring), then the refactoring has not changed the external behaviour. If one or more test cases fail, then you have changed the external behaviour.

At least, that is my understanding of the various books published on the topic (e.g., Fowler's).


问:
Is it essential to learn algorithms to be a real programmer?
I'm a PHP programmer, and until now I have not needed to learn algorithms...

Now I'm start learning Python (a real programming language), because I need to use matplotlib. Does it make sense to start by reading a Python algorithm book and then learn matplotlib and numpy or should I jump to matplotlib and numpy?

Best Regards,

答:
Algorithms to a programmer is a hammer to a blacksmith. Sure you can get by without and use alternatives to get the job done, but if you want to do it right and do it well it is essential.

Good thing about algorithms is that it is programming language independent, so learn the theory once and you can implement it in any language. Here is a good website that I've been building to start learning from: www.ambesty.com They use Java but it comes with sample code to learn from. They offer simple ADT and Sorting algorithms to more complex ones like data compression algorithms. Very interesting read. Good luck


答:
If you are developing business applications (only), Get to learn the basics only, such as lists, queues, sorting, string search, etc. so that you'd learn the terminology, how performance is affected and measured and so on.
A better use of your time would be to focus on new technology, OO patterns, effective database design, app. development methodologies, and such!</p>

Title: Is it essential to learn algorithms to be a real programmer?

Body:
I'm a PHP programmer, and until now I have not needed to learn algorithms...

Now I'm start learning Python (a real programming language), because I need to use matplotlib. Does it make sense to start by reading a Python algorithm book and then learn matplotlib and numpy or should I jump to matplotlib and numpy?

Best Regards,


问:
How to explain that it's hard to estimate the time required for a bigger software project?
I'm a junior developer and I find it hard to estimate how much time it takes to finish a bigger software project. I know how to structure the architecture in general, but it's hard for me to know what details I have to do and what problems I have to solve. So it's hard to estimate how much time it will take to finish a bigger project, because I don't know what problems I need to solve and how long it takes to solve them.

How do I explain this to a person that is not a software developer?

答:
You could ask him/her to estimate how long it would take for her to access some far away location in an uninhabited corner of the world. As an extreme example, let's choose some lesser known peak in the Himalayas, where very few (if any) people have ever climbed on. She would need an awful lot of preparation plus practice before even starting the journey, plus a bunch of permits, each of which can delay the trip for months to years... and a good support team... then once up on the hill slope, she would need to wait and pray for good weather to start climbing towards the peak... etc. etc. Most of these are hard to impossible to estimate, even with prior experience.

And the point is: each software project is a bit like climbing a new mountain, where no one has been before, so no one has direct prior experience. Seasoned developers may have gathered experience on more or less similar projects, but there will always be new elements and surprises - otherwise, if a software project were exactly like some previous one, there would be absolutely no point doing it.


问:
Example of Terms of Services for Agile contracting?
In my experience as a freelance developper, I've had some difficulties with clients, whom insist on getting an estimate over flimsy requirements. They then expect me to deal with requirements changes, sometimes late in the project, and stick to that estimate.

Since I've never come up myself with some T.O.S. tailored for this situation, I ended up bound by a contract of a more general nature, which inevitably became unsasatisfactory...

Legal lingo not being my forte, I've been lookin for some publicly released T.O.S. to try to remedy this situation. Ideally these would be from an agile shop, under a licensing scheme allowing derivatives. This would help me lay out the contractual groundwork for a sane customer relationship, especially when dealing with changes.

答:
Clients wanting you to be agile sounds more like clients that just want to change their mind (which is fine).

It seems like instead of:

Get requirements

Sign the contract with Julien to deliver X for $Y.

Julien delivers X

Julien gets paid Y

They want:

Get very, very vague requirements

Sign the contract with julien to deliver whatever they want (X? Y? X+Y? Z??), which is undetermined, and pay Julien $Y.

Julien works toward ever-changing requirements.

Requirements are never met.

Julien never gets paid because they are never satisfied.

In this case I would simply charge per-hour.

Don't worry about fixed price or an "agile" contract.  If you try to re-contract for every change, it will eventually become more pain than it is worth.  Your best bet here would be to have a per-hour charge, and have them sign off on timesheets you provide on a per-week or something similar basis.  This way both you and they can be as agile as needed while you have a better guarantee of getting paid.  Just do great work and any good client will see your value.  If not, you're better off just passing on the particular client if you have the opportunity.

For a more Agile approach..

You could, essentially, have a shorter estimate contract per-iteration.  Each 2-week (or whatever time) iteration that you plan, have a shorter contract/amendment that outlines the requirements and estimates just for that iteration.  Let the client change requirements, but only give them that luxury at the end of each iteration when you do the planning for the next iteration.


答:
Have you explained that to the person? You are the professional software engineer, so the person that you are building software for should be considering your knowledge and feedback when it comes to the design and implementation of software systems.

The Cone of Uncertainty is probably a good starting point. Software projects are hard to estimate until more of the details are known, which happens later in the project. In addition, changing requirements will also change estimates. Your initial estimates at the beginning of a project will have a large amount of variability.

You might be interested in other estimation techniques, too. You mentioned that you are only a junior developer. Generally, more experienced developers have a better ability to estimate since they have seen more problems, solved them, and (hopefully) kept track of estimate versus actual time. You could take advantage of this using estimation techniques such as wideband delphi or planning poker.

As a junior developer, start tracking estimates and actual time now. You might be interested in reading about the Personal Software Process developed at the Software Engineering Institute. The core PSP books are A Discipline for Software Engineering, PSP: A Self-Improvement Process for Software Engineers, and Introduction to the Personal Software Process. I believe that Introduction to the Personal Software Process would cover the topics that you would find most helpful. I think it's generally overkill for most developers, but it does have some good ideas and good practices that can be pulled out and used in order to improve personal productivity and hone various skills (including estimation) that you'll continually use over your career.

If you will be doing a lot more work in estimation, I would highly recommend two of Steve McConnell's books: Software Estimation: Demystifying the Black Art (focuses on estimation as an art and science) and Rapid Development: Taming Wild Software Schedules (general software engineering process and project management topics).

Title: How to explain that it's hard to estimate the time required for a bigger software project?

Body:
I'm a junior developer and I find it hard to estimate how much time it takes to finish a bigger software project. I know how to structure the architecture in general, but it's hard for me to know what details I have to do and what problems I have to solve. So it's hard to estimate how much time it will take to finish a bigger project, because I don't know what problems I need to solve and how long it takes to solve them.

How do I explain this to a person that is not a software developer?


答:
Estimation of the entire project's time is usually performed by the project manager not the programmer.

You can build an argument based on the fact that the project manager has the full list of tasks required. Without this list, any estimation will be a 'bad' guess.

Also, time depends on many factors such as how many people are available and the scope of requirements, which you did not say you have. Architecture alone is not enough.


答:
I've met people who claim they can estimate software, but I don't know how they do it.  Neither have any of them been able to explain how they do it.

As a consultant, my clients often require me to work on a fixed-bid basis.  Thus I need to estimate so that I can prepare a realistic bid.  I have never once succeeded at this.  One would think I would overbid as often as I underbid, but that is never the case.  The result is that I often lose a lot of money on my contracts, and end up earning a lot less than I would if I were working for a company as a regular employee.

I've been searching for many years for a book that would teach me how to estimate software, but I have yet to find one.

As for explaining this to someone who is not a coder.  You could point out that no one in the industry is consistently able to meet their estimates.  It happens all the time that new software products are preannounced, only to ship months or years after the date that was originally announced.

If a big company like Microsoft can't figure out how to estimate the time that goes into producing its own products, how can I?

Whether I'm being paid by the hour or by the job, my clients always expect me to provide these estimates.  I don't know how they expect me to produce them when such estimation is not taught anywhere, and I have no rational basis for my estimates.


答:
Refer to literature. There's a huge pile of complex and often contradictory material, which, as proven by practice (experiments), doesn't work as expected. At least academics are swayed by a pile of books.

Must-read: http://en.wikipedia.org/wiki/The_Mythical_Man-Month

The Mythical Man-Month: Essays on Software Engineering is a book on software engineering and project management by Fred Brooks, whose central theme is that "adding manpower to a late software project makes it later". This idea is known as Brooks' law, and is presented along with the second-system effect and advocacy of prototyping.

Brooks' observations are based on his experiences at IBM while managing the development of OS/360. He had added more programmers to a project falling behind schedule, a decision that he would later counter-intuitively conclude to have delayed the project even further. He also made the mistake of asserting that one project — writing an ALGOL compiler — would require six months, regardless of the number of workers involved (it required longer). The tendency for managers to repeat such errors in project development led Brooks to quip that his book is called "The Bible of Software Engineering", because "everybody quotes it, some people read it, and a few people go by it." The book is widely regarded as a classic on the human elements of software engineering...


问:
Pointless Code In Your Source
I've heard stories of this from senior coders and I've seen some of it myself. It seems that there are more than a few instances of programmers writing pointless code. I will see things like:

Method or function calls that do nothing of value.

Redundant checks done in a separate class file, object or method.

if statements that always evaluate to true.

Threads that spin off and do nothing of note.

Just to name a few. I've been told that this is because programmers want to intentionally make the code confusing to raise their own worth to the organization or make sure of repeat business in the case of contractual or outsourced work.

My question is. Has anyone else seen code like this? What was your conclusion was to why that code was there?

If anyone has written code like this, can you share why?

答:
Method or function calls that do nothing of value.

Not necessarily bad. Methods in a base class often call empty methods that are meant as override points for subclasses. Example: Cocoa Touch's UIView has a -didAddSubview: method that's documented as doing nothing in the default version. UIView's -addSubview: method has to call -didAddSubview: even though it does nothing because subclasses may implement it to do something. Methods that do nothing and the reasons for them should be documented, of course.

If an empty or useless function/method is obviously there for reasons historical, it should be excised. Take a look at earlier versions of the code in your source code repository if you're not sure.

Redundant checks done in a separate class file, object or method.

Hard to say if that's okay without some context. If the checks are clearly done for the same reason, it may mean that there's not a clear separation of responsibilities and some refactoring is called for, especially when both checks result in the same action being taken. If the action resulting from the both checks is not the same, then the two checks probably are being done for different reasons even if the condition is the same, and that's likely okay.

if statements that always evaluate to true.

There's a big difference between:

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

and:

```<code>if (foo() == true) {
    // ...
}
</code>```

where foo() happens to always return true.

The first case happens a lot when people are debugging. It's easy to use an if (0) {... to temporarily remove a chunk of code while you're trying to isolate a bug, and then change the 0 to 1 to restore that code. The if should be removed once you're done, of course, but it's easy to forget that step, or to miss one or two if you've done it in several places. (It's a good idea to identify such conditionals with a comment that you can later search for.) The only harm is the confusion it might cause in the future; if the compiler can determine the value of the condition at compile time, it'll remove it entirely.

The second case can be acceptable. If the condition represented by foo() needs to be tested from several places in the code, factoring it out into a separate function or method is often the right thing to do even if foo() always happens to be true right now. If it's conceivable that foo() might eventually return false, then isolating that condition in a method or function is one way to identify all the places where the code relies on that condition. However, doing that does create some risk that the foo() == false condition will go untested and could lead to problems later; the solution is to make sure that you add unit tests that explicitly test the false case.

Threads that spin off and do nothing of note.

This sounds like an artifact of history, and something that could be identified either during a code review or through periodic profiling of the software. I suppose it could be created intentionally, but I have a hard time imagining that someone would actually do that on purpose.

Title: Pointless Code In Your Source

Body:
Method or function calls that do nothing of value.

Not necessarily bad. Methods in a base class often call empty methods that are meant as override points for subclasses. Example: Cocoa Touch's UIView has a -didAddSubview: method that's documented as doing nothing in the default version. UIView's -addSubview: method has to call -didAddSubview: even though it does nothing because subclasses may implement it to do something. Methods that do nothing and the reasons for them should be documented, of course.

If an empty or useless function/method is obviously there for reasons historical, it should be excised. Take a look at earlier versions of the code in your source code repository if you're not sure.

Redundant checks done in a separate class file, object or method.

Hard to say if that's okay without some context. If the checks are clearly done for the same reason, it may mean that there's not a clear separation of responsibilities and some refactoring is called for, especially when both checks result in the same action being taken. If the action resulting from the both checks is not the same, then the two checks probably are being done for different reasons even if the condition is the same, and that's likely okay.

if statements that always evaluate to true.

There's a big difference between:

if (1) {
    // ...
}

and:

if (foo() == true) {
    // ...
}

where foo() happens to always return true.

The first case happens a lot when people are debugging. It's easy to use an if (0) {... to temporarily remove a chunk of code while you're trying to isolate a bug, and then change the 0 to 1 to restore that code. The if should be removed once you're done, of course, but it's easy to forget that step, or to miss one or two if you've done it in several places. (It's a good idea to identify such conditionals with a comment that you can later search for.) The only harm is the confusion it might cause in the future; if the compiler can determine the value of the condition at compile time, it'll remove it entirely.

The second case can be acceptable. If the condition represented by foo() needs to be tested from several places in the code, factoring it out into a separate function or method is often the right thing to do even if foo() always happens to be true right now. If it's conceivable that foo() might eventually return false, then isolating that condition in a method or function is one way to identify all the places where the code relies on that condition. However, doing that does create some risk that the foo() == false condition will go untested and could lead to problems later; the solution is to make sure that you add unit tests that explicitly test the false case.

Threads that spin off and do nothing of note.

This sounds like an artifact of history, and something that could be identified either during a code review or through periodic profiling of the software. I suppose it could be created intentionally, but I have a hard time imagining that someone would actually do that on purpose.


问:
How do I avoid "Developer's Bad Optimization Intuition"?
I saw on a article that put forth this statement:

Developers love to optimize code and with good reason. It is so
  satisfying and fun. But knowing when to optimize is far more
  important. Unfortunately, developers generally have horrible intuition
  about where the performance problems in an application will actually
  be.

How can a developer avoid this bad intuition? Are there good tools to find which parts of your code really need optimization (for Java)? Do you know of some articles, tips, or good reads on this subject?

答:
These tools are called profilers. You can use them to actually measure which part(s) of your program take the most time to execute, so where to focus your tuning efforts.

It is equally important to measure again after the changes, to verify that your changes have the intended effect.

ContentLicense: CC BY-SA 4.0


答:
The only way to know where to optimize is to profile your code. Instead of making changes that you think will provide a benefit, know for sure where the worst-performing code is and start there.

Java makes this pretty easy with the VisualVM tool, which has been bundled with recent releases of the Java Development Kit (JDK). The idea is to find out which methods are called the most and in which methods you are spending most of your time, both in your code and in external libraries. You can also get performance data on garbage collection so you can tune your collector and adjust min/max heap space required by your application.

Title: How do I avoid "Developer's Bad Optimization Intuition"?

Body:
I saw on a article that put forth this statement:

Developers love to optimize code and with good reason. It is so
  satisfying and fun. But knowing when to optimize is far more
  important. Unfortunately, developers generally have horrible intuition
  about where the performance problems in an application will actually
  be.

How can a developer avoid this bad intuition? Are there good tools to find which parts of your code really need optimization (for Java)? Do you know of some articles, tips, or good reads on this subject?


答:
Use a good profiler to identify expensive methods.

Document how long the hot spots actually took.

Write a faster implementation of the hot spots

Document how long the hot spots now take, hopefully not making them hotspots anymore.

Essentially you need to be able to prove to others where the problem was, and that this change made it go away.

Not being able to prove an improvement, qualifies - in my personal opinion - for immediate rollback to the original version.


答:
You can think of “external” meaning

External to the daily stand up.

So any change to the system that does not effect none pigs, can be considered to be refactoring.

Changing a class interface is a none issue, if the class is only used by a single system that is built and maintained by your team.    However if the class is a public class in the .net framework that is used by every .net programmer it is a very different matter.

Title: How far can I push refactoring without changing external behavior?

Body:
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?


答:
Another point you could make is that software engineering is still in its infancy compared to other fields of engineering, and has not matured enough for estimable development techniques to have appeared.

Software engineering is also in a continuous state of flux.  By the time a technology has been around enough to be considered mature, it is often abandoned in favor of some new technology.  That prevents anyone from gaining enough experience with any one technology to be able to produce reliable estimates.

Contrast this with construction estimation.  That's a very well-understood problem, not just because contracts are awarded based on bids, but because humanity has been building things since the dawn of civilization.


问:
Is there a GPL-compatible software license for libraries which allows static linking, but requires redistribution of library source code?
I'm looking for an existing library license which satisfies the following conditions:

GPL-compatible

Can be statically linked with closed-source programs

Binary modifications of the library, including cases where the library is statically linked with another project, must be accompanied by the library source code

Licenses which are close but not quite what I need:

LPGL - does not allow static linking with non-free software*

Eclipse Public License - not GPL-compatible due to a patent clause

GPL linking exception - does not require source code redistribution

*: The LGPL allows static linking with some specific technical conditions - specifically, it must be possible to make modifications or use newer versions of the library, and to do that one would need to make available the object files and build scripts for the non-free components. Generally speaking, this is technically difficult and sometimes impossible (in the case of e.g. templates or inlined functions), and very often (as is my case) the underlying reasons for which static linking is required conflict with these LGPL requirements. For this reason, LGPL is unsuitable for my use case, and frankly I've yet to see a project which used static linking with an LGPL library in this manner, considering all the associated technical and legal (templates/macros/inlining) problems.

答:
The LGPL will allow that.

From Wikipedia, "The main difference between the GPL and the LGPL is that the latter allows the work to be linked with (in the case of a library, 'used by') a non-(L)GPLed program, regardless of whether it is free software or proprietary software.1 The non-(L)GPLed program can then be distributed under any terms if it is not a derivative work."

Any changes to the library must be redistributed, but the library itself can be used without requiring distribution of the main program.


问:
VB.Net vs C# debate
I've been in workplaces where, at the start of a project, the "Should we use VB.Net or C#" question has been raised.

Granted, it's probably less common to have to make that decision now than it was in the early days of .Net, particularly given the trend towards language convergence, but it can still be a heated debate.

So, between VB.Net and C#, Which language do you prefer and why?

答:
Being a somewhat older dev (is 59 "somewhat" older?), I learned BASIC first on a Commodore VIC-20, taught myself Turbo Pascal (v1!), went on to learn COBOL at college, and spent 14 years developing on IBM mainframes, with brief diversions writing a medium sized apps in Revelation BASIC (a variant of PICK BASIC) and a few utilities in Modula-2, before side-stepping over to VB5 and VB6.  And then came .NET.

Because of my Basic background, I thought I should start out with VB.NET, only to find that I kept trying to do things the "old" way and it was driving me nuts (okay, more nuts).  Being that I had done some work in C, I thought I would give C# a whirl to see how that went.  And OMG, that was like emerging from a dark tunnel into clear daylight!  Totally unexpected.  And I used to make disparaging noises about C being a "write-only" language -- "so hard to understand that a C programmer couldn't figure out what his own code did 6 months after he wrote it", an observation made by semi-famous novelist that I thought sounded cute at the time.

So, by virtue of being a bit unfamiliar with C, C# was paradoxically easier for me to learn .NET programming in than the far more should-be-familiar Basic paradigm.  I still like VB6, but have come to love C#.  The best programming language on the planet.

Title: VB.Net vs C# debate


问:
What makes for "good style" in Java?
I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it.

I've been programming in Java for a few years. I've often discussed design decisions with colleagues on the basis of what constitutes 'good style'. Indeed, there are a number of StackOverflow questions/answers that discuss a design on the basis of whether something is 'good style'.

But what makes 'good style'? Like many things, I know it when I see it... but I wanted to have better idea than just my conscience saying that this design doesn't feel right.

What are the things you think about in order to produce good, well designed code?

(I acknowledge that this is somewhat subjective, as what is 'good style' will depend on the task at hand). (Also, I should add that I'm not interested in team styles - e.g. "we use indents of 2 spaces rather than 4"..., and I'm not interested in the Java code conventions.)

Edit: thanks for all the good answers/comments so far. I'm especially keen for answers that would help codify those things that make a programmer's conscience (and possibly stomach) wrench?

答:
A few brief points:

Intent-revealing names

No non-instructive comments

No method with a complexity so high that you can't fit it all in your head at once

Single-responsibility objects

Follow code conventions (you said you didn't care about it, but it's vitally important)

Title: What makes for "good style" in Java?


问:
When would polling for events be better than using observer pattern?
Are there scenarios where polling for events would be better than using the observer pattern? I have a fear of using polling and would only start using it if someone gave me a good scenario. All I can think of is how the observer pattern is better than polling. Conside this scenario:

You are programming a car simulator. The car is an object. As soon as the car turns on, you
  want to play a "vroom  vroom" sound clip.

You can model this in two ways:

Polling: Poll the car object every second to see if it's on. When it's on, play the sound clip.

Observer pattern: Make the car the Subject of the observer pattern. Have it publish the "on" event to all observers when itself turns on. Create a new sound object that listens to the car. Have it implement the "on" callback, which plays the sound clip.

In this case, I think the observer pattern wins. Firstly, polling is more processor intensive. Secondly, the sound clip does not immediately fire when the car turns on. There  can be up to a 1 second gap because of the polling period.

答:
Polling is a lot easier to get to work over a network when connections may fail, servers may go done etc.  Remember at the end of the day a TCP socket needs “polling” keep-a-live messages otherwise the server will assume the client has gone away.

Polling is also good when you wish to keep a UI updated, but the underlying objects change very fast, there is no point update the UI more than a few times a second in most apps.

Provided the server can response “no change” at very low cost and you don’t poll too often and you don’t have 1000s of clients polling, then polling works very well in real life.

However for “in memory” cases, I default to using the observer pattern as it is normally the least work.


问:
How to avoid being sued for your software?
I have a written a small app as a research project that uses open source libraries. It can do packet sniffing, network scanning and man in the middle attacks on wifi and lan.

This software is intended to be used for security auditing.

But users can also use it to circumvent the MAC filtering of their ISP and get free internet.

The case seems similar to that of uTorrent. uTorrent can be used legally, but almost everyone uses it for illegal downloading.

If users download my software and use it like that, can the ISP sue me as the author of the software? What should I put into the Terms and Conditions to avoid being sued for misuse of my software?

EDIT

I'm from Eastern Europe, but live in the UK. In which country should I ask a lawyer? People can download my software globally.

答: This depends heavily, heavily on the jurisdiction you find yourself under. Consult a lawyer before moving ahead. Just as an example, in my jurisdiction (Gemany) it could already be interpreted as illegal to own such software, never mind use it, no matter whether for "good" or "evil". You think that is ridiculous? Well, so do most professionals - but that doesn't change the fact that you can't deal responsibly with liability without legal advice.


答:
As with most legal questions on this site, I would recommend contacting a lawyer.

We're simple programmers, not laywers :)

Title: How to avoid being sued for your software?

Body:
I have a written a small app as a research project that uses open source libraries. It can do packet sniffing, network scanning and man in the middle attacks on wifi and lan.

This software is intended to be used for security auditing.

But users can also use it to circumvent the MAC filtering of their ISP and get free internet.

The case seems similar to that of uTorrent. uTorrent can be used legally, but almost everyone uses it for illegal downloading.

If users download my software and use it like that, can the ISP sue me as the author of the software? What should I put into the Terms and Conditions to avoid being sued for misuse of my software?

EDIT

I'm from Eastern Europe, but live in the UK. In which country should I ask a lawyer? People can download my software globally.


答:
The LGPL does allow static linking, but you must provide the minimum source requirements for a user to build the derived work against his own version of the LGPL work. When static linking, you would need to distribute at least the compiled object files of the closed-source work, combined with any scripts required to perform the linking process.

The LGPL section 4.d states: do one of the following:

Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.

Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.

Edit:

For the technical problems with inline functions, templates, macros etc - the LGPL is a bit more flexible here, and allows you to incorporate code from the header files without being required to distribute the work using these headers under the LGPL - provided the following conditions are met.

Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.

Accompany the object code with a copy of the GNU GPL and this license document.

Title: Is there a GPL-compatible software license for libraries which allows static linking, but requires redistribution of library source code?

Body:
I'm looking for an existing library license which satisfies the following conditions:

GPL-compatible

Can be statically linked with closed-source programs

Binary modifications of the library, including cases where the library is statically linked with another project, must be accompanied by the library source code

Licenses which are close but not quite what I need:

LPGL - does not allow static linking with non-free software*

Eclipse Public License - not GPL-compatible due to a patent clause

GPL linking exception - does not require source code redistribution

*: The LGPL allows static linking with some specific technical conditions - specifically, it must be possible to make modifications or use newer versions of the library, and to do that one would need to make available the object files and build scripts for the non-free components. Generally speaking, this is technically difficult and sometimes impossible (in the case of e.g. templates or inlined functions), and very often (as is my case) the underlying reasons for which static linking is required conflict with these LGPL requirements. For this reason, LGPL is unsuitable for my use case, and frankly I've yet to see a project which used static linking with an LGPL library in this manner, considering all the associated technical and legal (templates/macros/inlining) problems.


答:
Adding to Ryan's list:

Follow the SOLID principles

Ensure that your code doesn't have too much cyclic complexity

Test Driven Java is always a good thing

If you have a xFactoryFactory class, you're doing it wrong :-)

Given the open source libraries in the Java ecosystem, re-inventing the wheel is bad style

Use Joda time for date and time

I'll stop there.

Title: What makes for "good style" in Java?

Body:
I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it.

I've been programming in Java for a few years. I've often discussed design decisions with colleagues on the basis of what constitutes 'good style'. Indeed, there are a number of StackOverflow questions/answers that discuss a design on the basis of whether something is 'good style'.

But what makes 'good style'? Like many things, I know it when I see it... but I wanted to have better idea than just my conscience saying that this design doesn't feel right.

What are the things you think about in order to produce good, well designed code?

(I acknowledge that this is somewhat subjective, as what is 'good style' will depend on the task at hand). (Also, I should add that I'm not interested in team styles - e.g. "we use indents of 2 spaces rather than 4"..., and I'm not interested in the Java code conventions.)

Edit: thanks for all the good answers/comments so far. I'm especially keen for answers that would help codify those things that make a programmer's conscience (and possibly stomach) wrench?


问:
Lone Programmer vs. Everything Else
I guess you could call me a "MicroISV" because it's basically just me doing the work to create a product to be sold commercially. I'm sure there are many out there like me, so here's my question:

Besides the programming/coding aspect to get your code out the door, do you DIY or vendor-out everything else? For example, web site creation, internet marketing, accounting/taxes, company minutes, customer support, setting up ecommerce/banking, server management, procurement, etc.

All of those activities seem to be out of the realm of what I'm good at or have the patience/time for, but I don't know if the alternative is too untrustworthy or too expensive to make it worthwhile to try to farm out these tasks to someone else (like a local company, vendors on oDesk, etc.).

I can certainly understand wanting to keep all these tasks "in-house" (i.e. me) to protect strategy, plans, code, private things like bank account numbers, but is it really that much of a risk to outsource these tasks? What is your experience?

答:
A friend of mine was very successful as a software consultant, right up until his accountant skipped town, taking all of my friend's records with him.  This left my friend with no clue about how to do his taxes.  He had no other choice but to go out of business.

It happens all the time that accounts cook the books to their benefit and the detriment of their clients.  I guess my friend's accountant thought that he was just about to get caught.

Newbie consultants and software publishers are always advised to get the advice of good lawyers and accountants, but I have not found to be worth the money I paid them.  I ended up doing much better for myself by learning to do my own accounting, and by learning about the parts of the law that effect my business.

Now that's no substitute for asking for expert advice when appropriate.  But there are a lot of things about the law and about accounting that one can readily learn about just by reading about them.  This enables one to resort to the experts only when one has a really arcane questions.

If you do outsource your accounting, insist that you be provided with regular backups of your books, and study your books, bank statements and online banking regularly to be certain that you are not being embezzled.

Title: Lone Programmer vs. Everything Else


答:
Find out what they plan on doing with this estimate. In their mind they want to know if it will take months or years and you're trying to get the exact hours (Typical Engineer).

See if you can work on a piece of the project and then put together a better estimate if needed.

If they keep pushing, you're going to be forced to itemize as much of the tasks as you can an apply a time frame. Tell them you will let them know as soon as you see anything that may affect the estimate and make adjustments. People usually try to avoid surprises.


问:
Can software licensed under GNU General Public License v3 be sold by the original author?
As I know, softwares licensed under the GNU GPL is totally free and not allowed for sale. However, today I found this program called Minitube and it is sold even though it is licensed under GPLv3. Does the original author has a permission to sell his own software, even if he releases it under the GPLv3?</p>

答:
You are wrong. You can sell code under GPL. And you don't have to be the owner.

But you also have to provide/publish to your customer or user source code modification. (And your customers are allowed to redistribute the code free of charge. This is why most GPL code is free as in beer.)

One of the main idea behind the GPL is that the user must be able to modify or audit software. But the licence itself does not refrain you to sell the software.

See this page from the FSF on selling GPL software.


答: Yes, the original author is not bound by the terms of the GPL. The GPL is a License granted to any person who has a copy of the program. If you don't have a copy of the program, you are not entitled to the source code. The original author is also allowed to release the software under as many licenses as they wish. Once a piece of software has multiple authors, they must all agree to any licensing changes.</p>

Title: Can software licensed under GNU General Public License v3 be sold by the original author?

Body: As I know, softwares licensed under the GNU GPL is totally free and not allowed for sale. However, today I found this program called Minitube and it is sold even though it is licensed under GPLv3. Does the original author has a permission to sell his own software, even if he releases it under the GPLv3?</p>


问:
How do I appropriately license my open-source project?
I have just recently completed my first open source project and while it is mostly a tool I still want to release it as open source considering it is C# so if someone wanted to they could decompile it. Also, I'm not looking to sell it.

I was researching licensing but the wording is a bit over my head. Mostly I'm just looking for a license that recognizes me as the creator and does not allow anyone else to put their name on it and "steal it." I'm most likely going to use either google code or sourcefourge to host the project and ideally I could have a donation button. I'm not sure if or which software licenses would prevent that sort of thing?

Also, I'm not really sure how licenses and copyrights "work." Do I just choose a license and paste it at the top of every source file? Should I include my name as well? Do I also put the licenses in the project's root directory? How does one obtain a copyright? It seems like most people just stick it on their stuff. Is there an actual process to obtaining one?

As for software licenses I've looked at so far, it seems like Apache 2.0 or MIT/BSD is what I'm looking for but I'm not exactly sure. Basically I just don't want anyone to steal my program and put their name on it. Other than that I'm fine with people looking at the source code, modifying it, or taking pieces from it, as long as they credit me.

答:
The Berne Copyright Convention specifies that copyright descends on a creative work the instant it is created.  You don't need to do anything special to copyright your work.  That wasn't always the case - back in the day, one needed to register copyrights, and renew them periodically, but that's not the case anymore.

You SHOULD place a copyright notice in each of your source files, as well as the About or Credits box of your binary.  Note that you will still own the copyright of your work even if you don't include a copyright notice, but having it there prevents trouble in the event of a dispute.

The various open source licenses have different requirements for applying them to your code.  The BSD and MIT licenses must be pasted verbatim into each source file.

The GPL is generally provided separately in a file called COPYING or COPYING.txt, with a notice in each file stating that it is licensed under the GPL, and that the license itself is in the file COPYING or COPYING.txt.  Detailed instructions for applying the GPL are found at the end of the GPL license text itself.  If you use the GPL, follow its instructions, not what I posted here.

OwnerDisplayName: James


答:
From your comments, it appears that you're looking for a way to license a library that you wrote so you can use it in a proprietary project but still have the license be GPL-compatible.

First off, this is a bit nonsensical.  The GPL carries a whole lot of anti-proprietary-software ideological baggage with it.  It's designed that way; the whole point of it is to make it as difficult as possible to integrate GPL or LGPL code into a proprietary project.

However, licenses are for other people.  They don't apply to the copyright owner, which is you, the person who wrote the library.  You can use your own code however you want to, regardless of the terms of the license you put on it.  So you can make it GPL or LGPL and still use it in your proprietary project and you'll be fine.

On the other hand, if you want people in general to be able to use it in GPL projects or also to be able to use it in proprietary projects but still be required to publish the source to whatever changes they make, try dual-licensing it as (L)GPL and MPL.


答:
The GPL is a copyright license.  Such licenses only apply to people other than the copyright owner.  The original author of the code is free to do with it as he wishes.

This makes dual-licensing possible, typically done by giving away GPL-licensed source while selling the same code to closed-source developers under a different license.  That's how Trolltech made money from Qt.  It is GPL-licensed, but before Nokia bought Trolltech, a developer seat for the proprietary version of Qt was quite expensive, a thousand dollars I think.

As pointed out above, despite the fact that the GPL is a Free Software license, it doesn't mean that you are not permitted to charge money for it.  "Free" in this case refers to the rights passed on to those who obtain GPL-licensed code.  You can charge anything you want for GPL code, you just have to abide by the terms of the license.

Lots of companies make vast sums of money selling GPL code: Google with Android, IBM with Linux for their RS-6000 servers, Red Hat with Red Hat Enterprise Linux.  But all of their source that is linked with GPL source has to be GPL-licensed itself, and has to be made available to those who obtain copies of the binary.

Note that you don't have to actually distribute the source.  Lots of people think that one has to post one's source online to comply with the GPL.  That's not actually the case.  Neither is it sufficient to post the code online: Richard Stallman pointed out a while back that those without an Internet connection would not be able to obtain your source if that was the only way you distributed.

To comply with the GPL, if I remember correctly, you must make a written offer to provide the source, and you have to actually provide the source when you are asked for it.  You can charge a "reasonable" amount of money for the source, to cover the costs of media duplication, shipping and handling and so on.  Even the Free Software Foundation sells its own source code on physical media, despite the fact that it is all available online.


问:
What is a "powerful" language?
I have often seen people fighting over that their favorite language is more "powerful" than others. When it comes to describing a programming language, I can understand what an object oriented language is or what a dynamic language is, but I still can't figure out what exactly a "powerful" language is. What are your thoughts?</p>

答: They are all tools in your tool chest. A hammer can be powerful, but not if you need a wrench. C/C++ is great if you are a systems programmer, but Adobe Flash is probably a better fit for that gaming web site you want to build.</p>

Title: What is a "powerful" language?


问:
I'm writing about language syntax. Is there a language out there in which parameters are placed inside method name?
in JavaScript:

function getTopCustomersOfTheYear(howManyCustomers, whichYear) {
   // Some code here.
}
getTopCustomersOfTheYear(50, 2010);
```

<p>in C#:</p>

<pre class="lang-cs prettyprint-override"><code>public List<Customer> GetTopCustomersOfTheYear(int howManyCustomers,
 int whichYear)
{
   // Some code here
}
List<Customer> customers = GetTopCustomersOfTheYear(50, 2010);
</code>```

in PHP:

public function getTopCustomersOfTheYear($howManyCustomers, $whichYear)
{
   // Some code here
}
$customers = getTopCustomersOfTheYear(50, 2010);
```

<p>Is there any language out there which support this syntax:</p>

<pre class="lang-c prettyprint-override"><code>function GetTop(x)CustomersOfTheYear(y)
{
    // Some code here
}
returnValue = GetTop(50)CustomersOfTheYear(2010);
</code>```

Isn't it more semantic, more readable form of writing a function?

Update: The reason I'm asking this question is that, I'm writing an article about a new syntax for a new language. However, I thought that having such syntax for declaring methods could be nicer and more friendly to developers and would decrease learning-curve of the language, because of being more closer to natural language. I just wanted to know if this feature has already been contemplated upon or not.

答:
Yes, and yes. Yes there's such a language, and yes, many people find it more readable once they get used to it.

In Objective-C, the method would be:

```<code>- (NSArray*)getTop:(int)count customersOfTheYear:(Year)year;
</code>```

That's actually a pretty contrived example that doesn't read very well, so here's a better one from actual code:

```<code>+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
</code>```

That the prototype for a method that returns a new UIColor instance using the red, green, blue, and alpha values. You'd call it like this:

```<code>UIColor *violet = [UIColor colorWithRed:0.8 green:0.0 blue:0.7 alpha:1.0];
</code>```

Read more about message names with interspersed parameters in The Objective-C Programming Language.

Body:
Yes, and yes. Yes there's such a language, and yes, many people find it more readable once they get used to it.

In Objective-C, the method would be:

- (NSArray*)getTop:(int)count customersOfTheYear:(Year)year;

That's actually a pretty contrived example that doesn't read very well, so here's a better one from actual code:

+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;

That the prototype for a method that returns a new UIColor instance using the red, green, blue, and alpha values. You'd call it like this:

UIColor *violet = [UIColor colorWithRed:0.8 green:0.0 blue:0.7 alpha:1.0];

Read more about message names with interspersed parameters in The Objective-C Programming Language.


答:
Objective-C does that.  Here is a typical prototype:

```<code>- (void) areaWithHeight: (float) height andWidth: (float) width;
</code>```

Here is how you call such a method:

```<code>float area = [self areaWithHeight: 75 andWidth: 20];
</code>```

Objective-C is primarily used with Cocoa for Mac OS X and Cocoa Touch for iOS, but gcc will build Objective-C code on just about every platform that gcc works on.

Title: I'm writing about language syntax. Is there a language out there in which parameters are placed inside method name?

Body:
in JavaScript:

function getTopCustomersOfTheYear(howManyCustomers, whichYear) {
   // Some code here.
}
getTopCustomersOfTheYear(50, 2010);
```

<p>in C#:</p>

<pre class="lang-cs prettyprint-override"><code>public List<Customer> GetTopCustomersOfTheYear(int howManyCustomers,
 int whichYear)
{
   // Some code here
}
List<Customer> customers = GetTopCustomersOfTheYear(50, 2010);
</code>```

in PHP:

public function getTopCustomersOfTheYear($howManyCustomers, $whichYear)
{
   // Some code here
}
$customers = getTopCustomersOfTheYear(50, 2010);
```

<p>Is there any language out there which support this syntax:</p>

<pre class="lang-c prettyprint-override"><code>function GetTop(x)CustomersOfTheYear(y)
{
    // Some code here
}
returnValue = GetTop(50)CustomersOfTheYear(2010);
</code>```

Isn't it more semantic, more readable form of writing a function?

Update: The reason I'm asking this question is that, I'm writing an article about a new syntax for a new language. However, I thought that having such syntax for declaring methods could be nicer and more friendly to developers and would decrease learning-curve of the language, because of being more closer to natural language. I just wanted to know if this feature has already been contemplated upon or not.

Body:
Objective-C does that.  Here is a typical prototype:

- (void) areaWithHeight: (float) height andWidth: (float) width;

Here is how you call such a method:

float area = [self areaWithHeight: 75 andWidth: 20];

Objective-C is primarily used with Cocoa for Mac OS X and Cocoa Touch for iOS, but gcc will build Objective-C code on just about every platform that gcc works on.


问:
Where do you draw the line between quantity and quality?
My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still feel like I have a lot to learn. Which route do I take (or is there another?):

Quantity: If they want crap, I can give them lots of it.

Quality: Ignore the request, and hope that my productivity will increase with experience.

答: When is the last time you went out to a restaurant? Did you go to 5 star because it has the best quality? Probably not, there is a cost trade off. Programmers are expensive and clients dont often want or need top quality. If the bare minimum gets the job done to the customers satisfaction there isn't any point over engineering it.</p>


答:
Look also at how much memory your program uses, not just its speed or runtime.

Lots of coders who work with garbage-collected languages such as Java are under the mistaken impression that garbage-collection prevents memory leaks.  That is not the case.  If you hold a reference to an object you don't need anymore, it won't get collected, and so it will leak.

I have seen Java web applications that were so leaky that they would run their server out of swap space!

If you use both a runtime profiler and some manner of memory profiler, you will learn to write faster and leaner code intuitively.  This has the effect that your code is more likely to run fast on the first try.


问:
What is the benefit of not using Hungarian notation?
One of the things I struggle with is not using Hungarian notation.  I don't want to have to go to the variable definition just to see what type it is.  When a project gets extensive, it's nice to be able to look at a variable prefixed by 'bool' and know that it's looking for true/false instead of a 0/1 value.

I also do a lot of work in SQL Server.  I prefix my stored procedures with 'sp' and my tables with 'tbl', not to mention all of my variables in the database respectively.

I see everywhere that nobody really wants to use Hungarian notation, to the point where they avoid it.  My question is, what is the benefit of not using Hungarian notation, and why does the majority of developers avoid it like the plague?

答:
Let's say we have a method like this (in C#):

```<code>int GetCustomerCount()
{
    // some code
}
</code>```

Now in code we call it like this:

```<code>var intStuff = GetCustomerCount();
// lots of code that culminates in adding a customer
intStuff++;
</code>```

The int doesn't tell us very much.  The mere fact that something is an int doesn't tell us what's in it.  Now let's suppose, instead, we call it like this:

```<code>var customerCount = GetCustomerCount();
// lots of code that culminates in adding a customer
customerCount++;
</code>```

Now we can see what the purpose of the variable is.  Would it matter if we know it's an int?

The original purpose of Hungarian, though, was to have you do something like this:

```<code>var cCustomers = GetCustomerCount();
// lots of code that culminates in adding a customer
cCustomers++;
</code>```

This is fine as long as you know what c stands for.  But you'd have to have a standard table of prefixes, and everyone would have to know them, and any new people would have to learn them in order to understand your code.  Whereas customerCount or countOfCustomers is pretty obvious at first glance.

Hungarian had some purpose in VB before Option Strict On existed, because in VB6 and prior (and in VB .NET with Option Strict Off) VB would coerce types, so you could do this:

```<code>Dim someText As String = "5"
customerCount = customerCount + someText
</code>```

This is bad, but the compiler wouldn't tell you so.  So if you used Hungarian, at least you'd have some indicator of what was happening:

```<code>Dim strSomeText As String = "5"
intCustomerCount = intCustomerCount + strSomeText  // that doesn't look right!
</code>```

In .NET, with static typing, this isn't necessary.  And Hungarian was too often used as a substitute for good naming.  Forget Hungarian and choose good names instead.

Body:
Let's say we have a method like this (in C#):

int GetCustomerCount()
{
    // some code
}

Now in code we call it like this:

var intStuff = GetCustomerCount();
// lots of code that culminates in adding a customer
intStuff++;

The int doesn't tell us very much.  The mere fact that something is an int doesn't tell us what's in it.  Now let's suppose, instead, we call it like this:

var customerCount = GetCustomerCount();
// lots of code that culminates in adding a customer
customerCount++;

Now we can see what the purpose of the variable is.  Would it matter if we know it's an int?

The original purpose of Hungarian, though, was to have you do something like this:

var cCustomers = GetCustomerCount();
// lots of code that culminates in adding a customer
cCustomers++;

This is fine as long as you know what c stands for.  But you'd have to have a standard table of prefixes, and everyone would have to know them, and any new people would have to learn them in order to understand your code.  Whereas customerCount or countOfCustomers is pretty obvious at first glance.

Hungarian had some purpose in VB before Option Strict On existed, because in VB6 and prior (and in VB .NET with Option Strict Off) VB would coerce types, so you could do this:

Dim someText As String = "5"
customerCount = customerCount + someText

This is bad, but the compiler wouldn't tell you so.  So if you used Hungarian, at least you'd have some indicator of what was happening:

Dim strSomeText As String = "5"
intCustomerCount = intCustomerCount + strSomeText  // that doesn't look right!

In .NET, with static typing, this isn't necessary.  And Hungarian was too often used as a substitute for good naming.  Forget Hungarian and choose good names instead.


答:
In Common lisp, you can define keyword arguments for a function like this:

(defun area (&key width height)
    (* width height))
```

<p>The function is called like this:</p>

<pre class="lang-lisp prettyprint-override"><code>(area :width 2 :height 3)
</code>```

In Ada you don't need a special declaration - you can call any procedure or function alternatively by listing the arguments in order, or by naming the arguments like this:

```<code>a := area(width => 2, height => 3);
</code>```

Finally, the boost library includes a layer of hacks to add the feature to C++: http://www.boost.org/doc/libs/release/libs/parameter/doc/html/index.html

Body:
In Common lisp, you can define keyword arguments for a function like this:

(defun area (&key width height)
    (* width height))

The function is called like this:

(area :width 2 :height 3)

In Ada you don't need a special declaration - you can call any procedure or function alternatively by listing the arguments in order, or by naming the arguments like this:

a := area(width => 2, height => 3);

Finally, the boost library includes a layer of hacks to add the feature to C++: http://www.boost.org/doc/libs/release/libs/parameter/doc/html/index.html


问:
Is there a canonical book on x86 assembly?
There are lots of books on assembly. However, they usually deal with ISAs about which I don't care, such as MIPS or ARM. I don't deal with these architectures; there's no reason for me to try to learn them.

But x86 assembly books seem... nonexistent.

Let's say for example I'm trying to build a toy compiler generating Windows Portable Executable files.

Is there a book out there that's the de-facto standard for describing best practices, design methodologies, and other helpful information on x86 assembly? What about that book makes it special?

答:
A very good book for learning x86 Assembly is Pentium Processor Optimization Tools.  While the book's main focus is the optimization of assembly code, it teaches Pentium assembly along the way, and is a good reference book as well.

It is long out of print but is not hard to find used.

It comes with a floppy disk containing an "assembly code optimizer".  It does not actually optimize your code, but instead produces a commented listing that points out where inefficiencies such as pipeline stalls lie.

The tool that comes with a book is a limited version of a more featureful product that the author's company used to sell, but for reasons I am unfamiliar with they are long out of business.  I don't know why - I would think such a tool would sell like hotcakes.

x86 in general is a very complex topic as there are many variants that are supported by different models of microprocessors.  Once you know the basics you will want to consult Intel's or AMD's databooks for the precise chip you are targeting.  Unfortunately code that runs fast on one model of CPU may not be as fast on a different chip.


答:
I couldn't find the name of it, but there's a design pattern to accomplish something similar, where a function call returns a new object modified as described.   For example:

```<code>query = db.getTopCustomers(50).forYear(2010);
</code>```

It isn't used very often because your data has to be very orthogonal in order to avoid unmanageable complexity under the hood, but can be useful in the right circumstances.

Body:
I couldn't find the name of it, but there's a design pattern to accomplish something similar, where a function call returns a new object modified as described.   For example:

query = db.getTopCustomers(50).forYear(2010);

It isn't used very often because your data has to be very orthogonal in order to avoid unmanageable complexity under the hood, but can be useful in the right circumstances.


答:
To my way of looking at things, Hungarian Notation is a kludge to get around an insufficiently powerful type system. In languages that allow you to define your own types it's relatively trivial to create a new type that encodes the behavior you're expecting. In Joel Spolsky's rant on Hungarian Notation he gives an example of using it to detect possible XSS attacks by indicating that a variable or function is either unsafe (us) or safe (s), but that still relies on the programmer to visually check. If you instead have an extensible type system you can just create two new types, UnsafeString and SafeString, and then use them as appropriate. As a bonus, the type of encode becomes:

```<code>SafeString encode(UnsafeString)
</code>```

and short of accessing the internals of UnsafeString or using some other conversion functions becomes the only way to get from a UnsafeString to a SafeString. If all your output functions then only take instances of SafeString it becomes impossible to output an un-escaped string [ baring shenanigans with conversions such as StringToSafeString(someUnsafeString.ToString()) ].

It should be obvious why allowing the type system to sanity check your code is superior to trying to do it by hand, or maybe eye in this case.

In a language such as C of course, you're screwed in that an int is an int is an int, and there's not much you can do about that. You could always play games with structs but it's debatable whether that's an improvement or not.

As for the other interpretation of Hungarian Notation, I.E. prefixing with the type of the variable, that's just plain stupid and encourages lazy practices like naming variables uivxwFoo instead of something meaningful like countOfPeople.

Title: What is the benefit of not using Hungarian notation?

Body:
One of the things I struggle with is not using Hungarian notation.  I don't want to have to go to the variable definition just to see what type it is.  When a project gets extensive, it's nice to be able to look at a variable prefixed by 'bool' and know that it's looking for true/false instead of a 0/1 value.

I also do a lot of work in SQL Server.  I prefix my stored procedures with 'sp' and my tables with 'tbl', not to mention all of my variables in the database respectively.

I see everywhere that nobody really wants to use Hungarian notation, to the point where they avoid it.  My question is, what is the benefit of not using Hungarian notation, and why does the majority of developers avoid it like the plague?

Body:
To my way of looking at things, Hungarian Notation is a kludge to get around an insufficiently powerful type system. In languages that allow you to define your own types it's relatively trivial to create a new type that encodes the behavior you're expecting. In Joel Spolsky's rant on Hungarian Notation he gives an example of using it to detect possible XSS attacks by indicating that a variable or function is either unsafe (us) or safe (s), but that still relies on the programmer to visually check. If you instead have an extensible type system you can just create two new types, UnsafeString and SafeString, and then use them as appropriate. As a bonus, the type of encode becomes:

SafeString encode(UnsafeString)

and short of accessing the internals of UnsafeString or using some other conversion functions becomes the only way to get from a UnsafeString to a SafeString. If all your output functions then only take instances of SafeString it becomes impossible to output an un-escaped string [ baring shenanigans with conversions such as StringToSafeString(someUnsafeString.ToString()) ].

It should be obvious why allowing the type system to sanity check your code is superior to trying to do it by hand, or maybe eye in this case.

In a language such as C of course, you're screwed in that an int is an int is an int, and there's not much you can do about that. You could always play games with structs but it's debatable whether that's an improvement or not.

As for the other interpretation of Hungarian Notation, I.E. prefixing with the type of the variable, that's just plain stupid and encourages lazy practices like naming variables uivxwFoo instead of something meaningful like countOfPeople.


问:
How to automate a tasks system in a CMS software
I'm currently developing v2.0 of my personal cms. However, I'm stuck. I strongly feel that my old solution for "tasks" is not very dynamic and must be revisited. Currently I'm looking the whole concept of how to dynamically add tasks and run them.

What I mean by task system

Like always in cms software, there are a lot of content, such as images, dynamic files, database entries, etc. I created my own task system aka. The Parser (sounds evil right?) It is made of two files, one parser-classes and other the triggers with the $parser = new ParserClasses(); (I hope you understand what I mean.) Some of the features the parser does:

First turn off the site (after the parser is done, turn it back on)

Checks for active files (files that don't have parent mysql entry, will be deleted)

Clears out old cache

Generates new static cache

Deals with languages and translation related cache

and other tasks related to cms management and maintenance

Why do I want to make it more automatic

Basically all plugins and some themes (add-ons in general,) use this task system. But the problem is that it's not very dynamical, because all functions sit in one huge class. This means that the add-on cannot be installed without opening your php editor.

How I was planning to do it

First I would create my own task language, with preset functions to handle files, cache,  etc. (very broad example: GenerateFreshCache('pages')). Now, storing it is the issue.. My ideas are:

To create tasks-table in mysql database. Then add tasks there, with my task language. Later while() them from the database and eval(). (This is a good way, because I can add scheduled times and similar in function, for CRON jobs. Or even categorize the tasks.)

Add .php files to some folder, where they get loaded. They will probably use the same task language, but don't need to be eval()'ed. (I'm scared that this would slow down the parser, because so many files are getting included.)

However, I'm not sure about those ideas and I'm hoping someone has already come across this functionality and can give me pointers. All crazy ideas and concepts are welcome, thanks in advance.

Conclusion

Thanks to everyone who replied. I picked the answer, that helped me the most and not "ohh, too much work, use framework". My task systems core is done and working. Took 2-3 days and currently ~600 lines of code and two classes (outer and inner core.) I finally ended up with two mysql tables, one with tasks (task db) and another with combos (multiple tasks combined together for easier run.) Also, added some features so it would be safe to run via ajax (cant really talk about that, top secret^^). There are might be too many loops, handling the tasks parsing, however this makes adding new tasks very very simple.. Just add it to tasks DB and add the task to cron-list-automatic-run-list or run it straight up via the admin panel.

答:
Why not remove tasks?
Make functions which will do things that you do in tasks, and call them when you modify an entity.

So lets say that you are using come translation library to translate news articles.

Why not call generateTranslations when someone updates or creates entity?

EDIT1:(reply to comment) Yeah, but from what i can see, you are fixing mismatched entries in database in task?
I think that's totally wrong, you should write your app so such things can't happen. Only thing that MAYBE should be written as task is cache generation, and that is only if you are limited and constrained by some other system. (for example if your server can only generate all cache in one go, but i am fairly sure that is not the case)
I re-read your comment, and i can see that you are using task mainly for fixing things, you should really refactor all of your code and fix those bugs.
I mean, you are literally patching data to compensate for bugs that you introduced.

EDIT2: Here are some things that should go in tasks:
Sending email containing info on some-all articles created since last "same" email was sent.

Parsing content from other sources (getting articles from other sites) IF that source cant notify you of new data that you need to get or send you new data.


答:
For a good example of when polling takes over from notification, look at operating system networking stacks.

It was a big deal for Linux when the networking stack enabled NAPI, a networking API that allowed the drivers to switch from an interrupt mode (notification) to a polling mode.

With multiple gigabit Ethernet interfaces the interrupts would often overload the CPU, causing the system to run slower than it ought to. With polling the network cards collect packets in buffers until polled or the cards even write the packets into memory via DMA. Then when the operating system is ready it polls the card for all of its data and does the standard TCP/IP processing.

The polling mode allows the CPU to collect Ethernet data at its maximum processing rate without useless interrupt load. The interrupt mode allows the CPU to idle between packets when work is not so busy.

The secret is when to switch from one mode to the other. Each mode has advantages and should be used in the proper place.

Title: When would polling for events be better than using observer pattern?

Body:
Are there scenarios where polling for events would be better than using the observer pattern? I have a fear of using polling and would only start using it if someone gave me a good scenario. All I can think of is how the observer pattern is better than polling. Conside this scenario:

You are programming a car simulator. The car is an object. As soon as the car turns on, you
  want to play a "vroom  vroom" sound clip.

You can model this in two ways:

Polling: Poll the car object every second to see if it's on. When it's on, play the sound clip.

Observer pattern: Make the car the Subject of the observer pattern. Have it publish the "on" event to all observers when itself turns on. Create a new sound object that listens to the car. Have it implement the "on" callback, which plays the sound clip.

In this case, I think the observer pattern wins. Firstly, polling is more processor intensive. Secondly, the sound clip does not immediately fire when the car turns on. There  can be up to a 1 second gap because of the polling period.


答:
The Art of Assembly Programming is an excellent resource that has quite a bit about x86 programming.

x64 ABI documentation is also useful. I was trying to find a link to the version that was on AMDs website, but I can't seem to find it anymore, so I guess this one will have to do.

Something that can help quite [a bit] while learning is, instead of trying to write a complete app from scratch in assembly, instead write most of it in C (or any other compiled language really) and then call a chunk of assembly code from that. Once you've done that, reverse it, write an assembly program, and call some C functions from that.

Edit: Fixed a typo.

Title: Is there a canonical book on x86 assembly?

Body:
There are lots of books on assembly. However, they usually deal with ISAs about which I don't care, such as MIPS or ARM. I don't deal with these architectures; there's no reason for me to try to learn them.

But x86 assembly books seem... nonexistent.

Let's say for example I'm trying to build a toy compiler generating Windows Portable Executable files.

Is there a book out there that's the de-facto standard for describing best practices, design methodologies, and other helpful information on x86 assembly? What about that book makes it special?


问:
Using Fonts in your Applications
When writing applications for software, specifically mobile devices, will there be a problem with using any specific type of fonts (copyright/patent issues)?

If so, how can we avoid this possible problems?

Will it then make a difference if the app was a paid version or a free version?

答:
Fonts are like songs; they are protected by copyright, and you need a license to use them.

If the font license is a free, unrestrictive license, then you probably won't have to pay money to use it.  If the font is already on someone's mobile device as part of the operating system installation, you shouldn't have to pay for a license.

If the font is a commercial font that requires you to pay a license fee to use it, then that's what you have to do.  Check the license agreement for the font; there should be sufficient information there to figure out what you need to do.

Title: Using Fonts in your Applications


答: You should be using fonts that are licensed for commercial use. Some fonts cannot be widely used or distributed, depending on the licensing. Read the font license when purchasing or contact the author for information. This may apply to both free and paid fonts.</p>

Title: Using Fonts in your Applications

Body:
When writing applications for software, specifically mobile devices, will there be a problem with using any specific type of fonts (copyright/patent issues)?

If so, how can we avoid this possible problems?

Will it then make a difference if the app was a paid version or a free version?


答:
We can't define what a "powerful" language is without first defining the word "powerful."

The literal definition of power would be "potency", and I think we can all agree that the vast majority of compilers - and even many interpreters that aren't Turing-complete - do an equally good job of getting the processor to execute their instructions.  So as far as the literal definition, the answer to the question would be "almost any language at all."

Practically, we really ought to stop there; defining a "powerful language" is a bit like defining a "good person" or a "quality product."  There is absolutely no objective definition of these words that you could get everybody, or even a majority of experts, to agree upon, and most definitions simply end up begging the question.  Depending on who you talk to, power could be any of the following:

A rich general-purpose framework or library for performing a wide variety of common tasks

A sophisticated domain-specific syntax that "does one thing and does it well"

Direct access to machine functions, i.e. the ability to write low-level code

Abstracting away machine-level concepts, i.e. the ability to write high-level code

A very rich type system allowing for advanced strategies like reflection, DI, and static analysis

A very loose type system that allows programmers to just get it done (type coercion, etc.)

The ability to treat everything as an object, which offers conceptual verification

The ability to treat everything as a function, which offers mathematical verification

Automatic memory and resource management (GC, RAII) leading to fewer bugs

Manual memory and resource management, potentially leading to optimized performance

A minimum amount of syntactic noise, leading to improved readability

A more English-like syntax, which offers a shallower learning curve

The ability to write very concise code (i.e. ternary operator, null-coalescing, null-extension)

The inability to write potentially confusing code (i.e. no ternary operators, etc.)

Does everybody see what's going on here?  Virtually every bullet-point feature can be interpreted as a sign of "power", and so can its exact opposite!

Somebody, somewhere, obviously thought that variable variables were an awesome idea that would make the language very powerful.  I won't judge; I'm not a PHP guy.

I propose that instead of all this holy-war nonsense, we all use this Really Simple Definition:

The most powerful language is the one that allows you to ship the highest-quality product at the lowest cost in the shortest amount of time.

Vague?  You betcha.  That's why anyone who wants to call him/herself a professional has to understand both the programming concepts and the project domain.  That's the only way you're going to be able to decide what's "powerful" for you.

Otherwise, you might just be bringing a really big knife to a gun fight.

Title: What is a "powerful" language?

Body: I have often seen people fighting over that their favorite language is more "powerful" than others. When it comes to describing a programming language, I can understand what an object oriented language is or what a dynamic language is, but I still can't figure out what exactly a "powerful" language is. What are your thoughts?</p>


答:
That depends on the individual font and how it is encoded, then decoded into a human-readible glyph.

The shapes of the glyphs in fonts cannot be copyrighted.  If fonts could be copyrighted, then every printed text that was rendered in such a copyrighted font would be a derivative work.

However, the data files that encode fonts can be copyrighted.  If you bundle a font with your app, you have to take care to comply with any license terms under which that font is published.  If you buy a font for personal use from Adobe, you are not license to redistribute it.  I'm sure Adobe is happy to allow for redistribution, but to get licensed for that, you'll need to pay them a lot of money.

Many of the technologies for translating the font data files into the rendered glyphs that you see on-screen are patented.  That is not likely to be a problem for you on mobile devices, as the patent licensing is the responsibility of whoever is distributing the implementation of these font-rendering technologies.  That's usually the handset vendors.

You will only need to obtain patent licenses if you yourself provide the code that translates a font's data file into a screen glyph.  If you are using the type rendering engine that is built into your mobile device's operating system then you don't need to worry about the patents.

Note that source code is not considered to be an implementation of a patented technology.  Google doesn't have to pay any fees or obtain any licenses to distribute the Android sources.

That's up to the device vendors, as program binaries ARE considered implementations that are subject to the patent laws.  I suspect that many such vendors don't understand that, and that they all figure that Google has licensed all the patents that cover the Android codebase.  That would be the case if they were licensing a mobile OS in binary form, but it's not the case when they are just getting source code.

Title: Using Fonts in your Applications