答:
I think this is not a programming but a management issue, and what you currently do seems to be the best you can achieve. I also agree: this is far less than what you should have.

The problem here is that the component structure and interface definitions (the very heart of the system) looks like a playground. If this was a software product, it would like programmers constantly change "their" components "because they have to", and don't care about that the other programmers code don't compile or break. Sounds like a nightmare... The good news: the same scenario is already solved in software development with version control systems (committing, testing, branching, etc.).

I know nothing about your environment, but I think you (and more importantly, your managers) should consider this a problem (source of bugs, frustration, decreasing efficiency and reason for colleagues wanting to leave), and handle it adequately. Benjamin correctly detailed the technical part, I would add the management and architecture side. My quick, unverified idea is the following:

implement or use a simple type management toolkit describing the components, attributes, services - the result must be a plain text config, json or xml file! These files should be version controlled to follow the changes.

for any modification, the hw guys should create a new branch, where you should add your components. The point: you can simply diff the type descriptors and change your code accordingly.

If this component descriptor part gets its real, "master" role in the company with proper technical background, other tools may appear, like:

header source code generators on both the GUI and the HW service layer;

working property sheets runtime generated from the type defs, ...

These are not that great deal, I have done such things just because this makes development more efficient: having the "core functionality" available from the configs leaves more time to do the real job (and less repeated errors). I am sorry that I can only talk about this, my public stuff is only on "proof of concept" level, but the sources here might give you the taste.

These are serious programming efficiency and system stability boosters - but this can't be reached if the core data descriptors are handled in a spreadsheet and can be changed anytime, "just because" - and by my opinion, this is not a gui developer problem, but a management level issue.

Title: Developing an Interface to a Dynamic System

Body:
I work for a small company and have been designing a GUI to interface our embedded system.  The problem with this embedded system is that it is not a finished product (may never be) and is constantly under development and being tweaked and updated for different customers and applications in small volumes.

So to deal with this I made a program that can export all the data from a spreadsheet where most of the embedded system variables are sourced from and throw them into a small database for the GUI application to use.  This database program I made also spits out a cross reference file for the embedded system which allows the GUI to look up all the variables.

This system works pretty well so far, and is even integrated with version control among the GUI, database, and embedded system.  The big problem is that there is constant development on several projects that use this system and it gets terribly tedious to keep the system up to date and bring in new changes.  This has gotten to the point to where I have had to code the GUI to dynamically (generically) generate all interfaces since I am never guaranteed to find the same data the same way.  I have not been able to come up with a good way to uniquely identify the data I import from excel since all fields are able to be changed (due to engineering stubbornness, code re-factoring and/or excel issues) and I cannot assign a fixed reference within the sheet itself.

So, are there any good methods or ideas on how to handle the chaos?


问:
memory and time intensive php task
Sorry if this question has been asked before, but I couldn't find anything usable.

I'm working on a project for a client and currently I have to loop through the users table which is about 3000 records and still growing.

I have to do some calculations on a nightly basis which I am going to be using cron/php.  The calculations script uses about 3.5mb of memory and takes about 1 second to run.

When loading individual users my current php setup handles this fine, but if I try and loop through the user list my php script execution time runs out.

I've read after doing some searching that I can make the page reload itself after each user calculation and just keep my previous place in the loop and this sounds like a good idea, but I wanted to hear some opinions from others that have handled similar situations and how you handled these types of tasks.

Thanks.

答:
The naive solution would be to increase PHP's request timeout setting; there's a php.ini setting for that.

But since you're running in a cron job, I'm wondering why you have a page load at all - you should be running the job as php-cli, that is, from a command line, without any web functionality at all (and thus, also outside of apache). For CLI scripts, there is no timeout (or at least, there is none for the default setup; not sure if it is possible to impose one), and on most systems, the CLI version uses its own php.ini, which means you can give your cron job more generous memory limits if you have to.

If you use php-cgi / mod_php / ..., you will have to wrap the script in a curl or wget call just to be able to put it in a cron job - this is a clumsy solution, and also insecure, because now anyone who can send requests to your application can trigger the cron job - easy prey for DoS attacks. If you use php-cli instead, you can run the script directly from cron: PHP even allows for a hash-bang line (#!/usr/bin/env php), but most likely, you will want to call php explicitly, so you can override php.ini and such.

ContentLicense: CC BY-SA 3.0

Title: memory and time intensive php task


问:
SQLite resources or any other storage concept for mobile applications?
I would like to know what storage concepts are used for mobile or handheld devices, where an app is operated on?. AFAIK one of them is SQlite.

Can anyone shed a light on this concept? perhaps links and resources will be much useful to many of new developers. Thanks a ton.:)

EDIT: My target would be Android and ios OS.

答:
I am also quite new to mobile development, but I have found the following fact (which is quite logical but  a bit disappointing, more experienced colleagues might correct me): this is business, and each vendor wants to keep users in their herds, they want to sell gadgets to them in the end.

They really want developers work on their platforms, but they don't care (better: don't like) multi-platform applications. They want us to make users love their products, especially the distinctive eye-candies of the ever new versions, and use our applications as their market advantage... Why on Earth should they support making multi-platform things? :-)

Of course that is a niche, and there are different multi-platform toolkits, google threw this summary, and stackoverflow has another good start. You should check what they offer for data persistence. Pro: you have the "and". Con: I suppose they offer always a bit less on each platform than available in native development, and of course you will learn that tool as your "platform"...

The result: instead of locking to iOS OR Android, you lock to the chosen toolkit with your code and (what is even more important): your experience. The toolkit may be fine and offer the precious "AND", but... if I have to guess which experience will be rewarded more and which company will exist longer, I would bet on Google and Apple, not "TheNthBestMobileMultiPlatformToolCompany"...

My 2 cents: if you choose what to learn now, and don't have too much (I mean years of serious) programming experience, select iOS.

That is a massive environment, the best I have met the last twenty-some years. Yes, it's limiting. Yes, it's expensive (but you can start working for free with a little hack). But if you learn it, you learn very good and stable concepts (like Core Data), and if you master it, you have more chance to get paid well for it. Oops, another con: the weird syntax of Objective C. It is relatively easy to switch among different Java, C, script dialects, while Objective C is really... ehm... special, and if you have to move from it one day, that might be harder.

With Core Data you will see no SQL, but what is more important: you will have an environment that helps you design your data structure and cares about persistence, transactions, GUI control binding, relation management, etc. in the background, with a must read reference, good tutorials and usable web help like Cocoa Dev Central or Ray Wenderlich portal. It will take time to find a situation where Core Data sucks, and even he says he hit the 5%, and for the rest it's okay.

For the memo: I don't personally like iOS, and currently hack it in my way to get what I want from it (going against the docs sometimes) but "give credit when credit is due". My opinion is that true multi-platform development (I mean: not using a toolkit, which is practically yet another single platform promising more possible buyers, but making your own tools and concepts) is for obsessed maniacs. Including me. ;-)


问:
Multiplayer Game Listen Servers: Ensuring Integrity
I'm making a simple multiplayer game of Tic Tac Toe in Python using Bridge (its an RPC service built over a message queue - RabbitMQ) and I'd like to structure it so that the client and the server are just one file. When a user runs the game, he is offered a choice to either create a game or join an existing game. So when a user creates a game, the program will create the game and also join him as a player to the game. This is basically a listen server (as opposed to a dedicated server) - a familiar concept in multiplayer games.

I came across a really interesting question while trying to make this - how can I ensure that the player hosting the game doesn't tamper with it (or atleast make it difficult)? The player hosting the game has access to the array used to store the board etc., and these must be stored in the process' virtual memory, so it seems like this is impossible. On the other hand, many multiplayer games use this model for LAN games.

答:
There is no technological way to ensure such a thing.

You can only appeal to player's morals and build a community, where such cheating will not be taken as proper way to play and win. Things like bans of cheaters and cheat reporting system are good way to help with this, but this can be double-edged sword.


问:
Importing Data from Google Analytics
I am planning on building a web app with many different public-facing HTTP servers; each of which will have Google Analytics (GA) installed on them.

I'd like to create a "dashboard" app that consolidates the GA data into one screen. I've been perusing the documentation for this so-called GA API, but I can't tell what the end result of the GA API is:

Does the GA API allow me to do exactly what I am looking for it to do? Or...

Does the GA API do something entirely different (like allow me to share my data with Google+ or something else weird)

Since an API can be used to CRUD any kind of data, I guess I'm asking which way the GA API goes: is it for querying (reading) data from 1+ server instances, or is it for modifying data on those servers or somewhere else? Thanks in advance!

答:
The GA API is mainly for retrieving the gathered data. You can query this data in a lot of ways. Depending on your requirements, you may want to get the data you need on a daily basis and keep it cached, to reduce the web requests.

I have seen tools around that do this for you, but unfortunately I do not remember any names.

Title: Importing Data from Google Analytics


问:
Mobile cross-platform SDK for computationally intensive apps
I am aware of the PhoneGap toolkit for creating mobile applications for virtually all mobile platforms with a significant market share. However, the code in PhoneGap that is shared between the different platforms is written in JavaScript. While I like JS, I think it's hardly appropriate for computationally intensive tasks. The situation with Titanium is pretty much the same.

So, is there any way that I can create a cross-platform mobile app that has the computationally intensive code shared between the platforms?

Some context: Obviously, I don't want to implement the time consuming algorithm in many different languages, since this violates DRY, increases the chance for bugs slipping in at least one version and require boilerplate code to work.

I've looked at Xamarin's MonoTouch and Mono for Android tools, but while they cover iOS and Android, they're not nearly as versatile for deployment as PhoneGap. On the other hand, (IMO) the statically typed nature of C# is more suited for intense computation than JS.

Are there any other SDK/tools appropriate for the task that I don't know about or a point about the mentioned above that I've missed?

Also, uploading data to a web service for processing is not an option, because of the traffic required.

答:
Phonegap and other similar solutions proposes a really abstracted wrapper to the real platform, so they make you loose a lot of perfomance, your best option is to write your application in C and/or C++.

Starting from Windows Phone 8 the Windows Phone OS will start to give full support for the C and C++, Android already has that kind of support thanks to the NDK and is also possible to use this languages under iOS.
RIM is also offering a native SDK with support for C and C++ for Blackberry.

C# is statically typed and this is true, but it runs under a virtual machine, so this also make you loose some resources, also a good codebase written in C and/or C++ can make your app/library portable on desktop with a minimum effort.


问:
Representing business rules with exceptions
I know it is expensive but (IMO) I believe it is a very good practice. I'm talking about rules like say, you can't save an Invoice if you are not a sales person... so in that case throwing an exception saying 'your are not authorized' or such...

Another approach it would be having objects with a status or something like that

Is there any other approach? how do you feel about it?

答:
In the example you've given us I think that raising an exception is a bad idea.  If you know that the user is not authorized before they start working and you still allow them to do some function and then smack them with an message AFTER they've already completed the task, that's just a bad design.

Using exceptions to enforce business rules is not a good design.

ContentLicense: CC BY-SA 2.5


问:
Java Phones: How to set up JTAPI?
I want to use JTAPI (1.4 - latest) to create an app that will call my phone whenever I need it to. I downloaded JSR043 (JTAPI specification) and have been reading the API docs and it seems pretty straight forward with respect to how to code JTAPI.

However I seriously doubt that getting a Java app on my laptop to call my cell phone doesn't require some 3rd party or middle man service provider and possibly other entities/configurations as well.

So I ask: besides using the JTAPI in my Java code, what do I need to install or set up to have a Java app that calls my phone? Thanks in advance!

答:
Hardware with phone capabilities and a phone service ( a service from an ISP ).

Also you have to consider that:

There are no Reference Implementations (RI) or Compatibility Tests
  Suites (CTS) available for the Java Telephony API.

http://java.sun.com/products/jtapi/overview.html

Title: Java Phones: How to set up JTAPI?


问:
The benefits of using RAII in C++
Suppose I'm a teacher and I want to explain to my students what are the benefits of using RAII in C++: I need a very good example, full of details, but that is easy to understand.

Which approach would you use?

答:
I would think one way to convey the notion is by example. Implement a class that requires some resource that is likely to fail at times. Opening a file that may not exist or something similar. First implement it without using RAII, then show how all the error handling code just disappears when using RAII sensibly.

The reduced complexity of the code using RAII should make the benefits quite obvious I think.

Title: The benefits of using RAII in C++


答:
There's the classic opening and closing of a file.  Using RAII the main flow of the algorithm will be clear without getting cluttered up with lots of try/finally-close logic littering the landscape.

Besides the clarity it provides to the code (separating clean up from core logic), there is the safety. If you have database you want to make sure connections are taken from the pool as LATE as possible. And returned to the pool as SOON as possible. Without RAII there is a high chance that someone could accidentally hang on to a connection somewhere. This increases the chance the pool will be empty and things will blow up. On a system with high user volume this is serious.

Safety and clarity.

EDIT: Oh, almost forgot. It also lends it self very well to reverse-order clean up. As a rule-of-thumb you generally want to clean stuff up in the reverse order you obtained it. For example if you are at a bank, you open the door, then open the safe. At the end of the day you want to close the door of the safe before you close the door to the bank (like a stack). Since RAII is literally controlled by the stack it is a natural fit for reverse-order clean up via scoping.

RAII is just so darn elegant. In my opinion it is the "answer" to resource clean up. Unlike a garbage collector it appropriate for more than just memory. Unfortunately not many programmers understand it; both old-school and new-school.

Title: The benefits of using RAII in C++

Body:
Suppose I'm a teacher and I want to explain to my students what are the benefits of using RAII in C++: I need a very good example, full of details, but that is easy to understand.

Which approach would you use?


答: At my workplace, we pull down the GA data periodically and store it in-house, so that we can run reports on it and generate dashboards from it at our convenience, so to speak; we're using a pretty direct series of RESTful calls and dumping it into a MySQL database, and then using jQuery to create dashboards from that.  This decouples our front end from the overhead of the GA service calls.</p>

Title: Importing Data from Google Analytics

Body:
I am planning on building a web app with many different public-facing HTTP servers; each of which will have Google Analytics (GA) installed on them.

I'd like to create a "dashboard" app that consolidates the GA data into one screen. I've been perusing the documentation for this so-called GA API, but I can't tell what the end result of the GA API is:

Does the GA API allow me to do exactly what I am looking for it to do? Or...

Does the GA API do something entirely different (like allow me to share my data with Google+ or something else weird)

Since an API can be used to CRUD any kind of data, I guess I'm asking which way the GA API goes: is it for querying (reading) data from 1+ server instances, or is it for modifying data on those servers or somewhere else? Thanks in advance!


答:
The benefit to RAII is ultimately encapsulation, in that once you've created an object you no longer need to worry about what to do with it once you've finished using it.

So, if you have a class that opens a file handle, you can make whatever operations you like on that object (which affects the underlying file) and when you destroy the object, you no longer have to think "do I have to close the file handle" or "is the file handle closed yet". Its gone, dealt with, fully automatically handled for you. And that magic happens because of RAII.

So you can compare RAII to C-style manual memory management, where you'd open a file, pass the handle around to various functions, and then have to remember to pass the handle to a close_file() function.
You can compare it to 'coffee'-style garbage collection manual object management, where you'd create an object that opens a file, perform operations on the object and then have to remember to call dispose or wrap your object in a using block to make the dispose method run - and have to put special code in your finaliser to clear it up as well.

And then you can show the C++ way where you don't have to remember to do anything at all, it just magically works for you, right there and then (so if you suddenly have to re-open the file, it's not locked by an object that is waiting to be garbage collected).

PS. Herb Sutter's talk at Build about modern C++ features has a section on RAII, starting at 13:50 minutes in where he shows a comparison between C-style code and C++ RAII code.

Title: The benefits of using RAII in C++


问:
Java Cryptography Extension
I was told that in order to support AES256 encryption inside my Java app that I would need the JCE with Unlimited Strength Jurisdiction Policy Files.

I downloaded this from Oracle and unzipped it and I'm only seeing 2 JARs:

local_policy.jar; and

US_export_polic.jar

I just want to confirm I'm not missing anything here! My understanding (after reading the README.txt) is that I just drop these two into my <JAVA_HOME>/lib/security/ directory and they should be installed.

By the names of these JARs I have to assume that its not the Java Crypto API that cannot handle AES256, but it's in fact a legal issue, perhaps? And that these two JARs basically tell the JRE "yes, it's legally-acceptable to run this level of crypto (AES256)." Am I correct or off-base?

答:
The following blog post answers your questions:

http://blogs.adobe.com/livecycle/2011/10/configuring-the-jdk-for-rights-management-encryption-using-aes-256-bit-keys.html

You effectively need the two JARs to be able to use AES256 encryption, and you need to perform the following steps, and I quote:

Copy the two JAR files to the your JDK’s /jre/lib/security/ folder, replacing the similarly named files that are already there.

Now, to the second part of your question: yes, it is dues to legal issues:

Due to import control restrictions by the governments of a few
  countries, the jurisdiction policy files shipped specify that “strong”
  but limited cryptography may be used. An “unlimited strength” version
  of these files indicating no restrictions on cryptographic strengths
  is available for those living in eligible countries (which is most
  countries). But only the “strong” version can be imported into those
  countries whose governments mandate restrictions. The JCE framework
  will enforce the restrictions specified in the installed jurisdiction
  policy files.

Also, there is a related Q/A on the Security Stack: Export laws on the cloud (key size). Although the question is specific to the cloud, the main answer covers more ground than just the "cloud" and lists the countries you cannot get a license to sell your software to and those for which your require an import permit.

Finally, you may find more information on Wikipedia about the Export of cryptography in the United States.

Title: Java Cryptography Extension


答:
If you really expect your table to grow, you should start thinking about batching the process, do your calculations in steps. The simplest way would be to have a secondary table that would hold the user id and the timestamp of when the user was last processed, and limit your cron script to loop through, for example, 500 users per time. The exact numbers will depend on what exactly you are doing, it'll be a bit of a trial and error.

If you do decide to batch the process, you'll obviously need to run the cron script more than once, that's easy enough, only process users that weren't recently processed (by checking the timestamp) and, of course, logging them as processed afterwards. If your user ids are sequential, you could save yourself the trouble of logging each processed user id and just log the last one of the batch, however if something goes wrong in the middle of the batch, you wouldn't have any idea of where it stopped. Your choice ;)

Next you need to optimize the hell out of your loop. Start with the simple stuff, are you using for or foreach? There's an abundance of references claiming one being faster than the other, but the truth is you'll have to test them and find out which one is faster (if there's actually a difference) for you. Depends on your php version, os, and the structures you're looping (if you are looping iterable objects, for example), and obviously you should run your test on the server where your script will live, especially if the environment is different from your local development one.

Then, it's time to profile and optimize your calculations. You aren't telling us what you are doing, but 3.5mb of memory sounds a bit much for a single iteration. It could be that your calculations are so intensive and you've done your best, or there might be something obvious you're missing, in any case that's something only a profiler can tell you.

Although max_execution_time is hardcoded to 0 (no limit) for the CLI SAPI, you might want to limit the execution time through set_time_limit or ini_set('max_execution_time') (same thing) for two reasons:

It will help testing the script via the browser, where there is a limit (in php.ini). It wouldn't be advisable to allow browser access to the production script, but during development it wouldn't make sense to setup cron just to test your script.

Although there's no limit for CLI scripts, it wouldn't hurt to impose the limit just in case something awry happens. Database servers do hiccup once in a while, and you don't really want your script to run ad infinitum (== until it runs out of memory).

If you are having memory problems, then it's time to do some garbage collecting. The naive approach would be to call gc_collect_cycles at the end of your script, forcing the garbage collection of any existing cycles at that time. It wouldn't hurt if you've unset() any memory hungry resources before hand. Remember that php loops don't create their own scope, for example:

```<code><?php

foreach($array as $key => $value) {
   doSomething($value);
}

var_dump($key, $value);

?>
</code>```

will work, dumping the last $key and $value of the loop, which means that at the end of the loop you don't have one ($array) but three unused variables, that will be collected when php decides it's a good time to collect garbage. To force it, do something like:

```<code><?php

foreach($array as $key => $value) {
   doSomething($value);
}

unset($array, $key, $value);
gc_collect_cycles();

?>
</code>```

I'm 99% certain that unset($array, $key, $value); is unnecessary here, however it's a favourite hack of the < php 5.3 days, and I'm sticking with it (at least until I fully understand how garbage collection works in php ;).

For anything more than that, you really need to give us the specifics of your calculations, and show us your code.

Title: memory and time intensive php task

Body:
Sorry if this question has been asked before, but I couldn't find anything usable.

I'm working on a project for a client and currently I have to loop through the users table which is about 3000 records and still growing.

I have to do some calculations on a nightly basis which I am going to be using cron/php.  The calculations script uses about 3.5mb of memory and takes about 1 second to run.

When loading individual users my current php setup handles this fine, but if I try and loop through the user list my php script execution time runs out.

I've read after doing some searching that I can make the page reload itself after each user calculation and just keep my previous place in the loop and this sounds like a good idea, but I wanted to hear some opinions from others that have handled similar situations and how you handled these types of tasks.

Thanks.

Body:
If you really expect your table to grow, you should start thinking about batching the process, do your calculations in steps. The simplest way would be to have a secondary table that would hold the user id and the timestamp of when the user was last processed, and limit your cron script to loop through, for example, 500 users per time. The exact numbers will depend on what exactly you are doing, it'll be a bit of a trial and error.

If you do decide to batch the process, you'll obviously need to run the cron script more than once, that's easy enough, only process users that weren't recently processed (by checking the timestamp) and, of course, logging them as processed afterwards. If your user ids are sequential, you could save yourself the trouble of logging each processed user id and just log the last one of the batch, however if something goes wrong in the middle of the batch, you wouldn't have any idea of where it stopped. Your choice ;)

Next you need to optimize the hell out of your loop. Start with the simple stuff, are you using for or foreach? There's an abundance of references claiming one being faster than the other, but the truth is you'll have to test them and find out which one is faster (if there's actually a difference) for you. Depends on your php version, os, and the structures you're looping (if you are looping iterable objects, for example), and obviously you should run your test on the server where your script will live, especially if the environment is different from your local development one.

Then, it's time to profile and optimize your calculations. You aren't telling us what you are doing, but 3.5mb of memory sounds a bit much for a single iteration. It could be that your calculations are so intensive and you've done your best, or there might be something obvious you're missing, in any case that's something only a profiler can tell you.

Although max_execution_time is hardcoded to 0 (no limit) for the CLI SAPI, you might want to limit the execution time through set_time_limit or ini_set('max_execution_time') (same thing) for two reasons:

It will help testing the script via the browser, where there is a limit (in php.ini). It wouldn't be advisable to allow browser access to the production script, but during development it wouldn't make sense to setup cron just to test your script.

Although there's no limit for CLI scripts, it wouldn't hurt to impose the limit just in case something awry happens. Database servers do hiccup once in a while, and you don't really want your script to run ad infinitum (== until it runs out of memory).

If you are having memory problems, then it's time to do some garbage collecting. The naive approach would be to call gc_collect_cycles at the end of your script, forcing the garbage collection of any existing cycles at that time. It wouldn't hurt if you've unset() any memory hungry resources before hand. Remember that php loops don't create their own scope, for example:

<?php

foreach($array as $key => $value) {
   doSomething($value);
}

var_dump($key, $value);

?>

will work, dumping the last $key and $value of the loop, which means that at the end of the loop you don't have one ($array) but three unused variables, that will be collected when php decides it's a good time to collect garbage. To force it, do something like:

<?php

foreach($array as $key => $value) {
   doSomething($value);
}

unset($array, $key, $value);
gc_collect_cycles();

?>

I'm 99% certain that unset($array, $key, $value); is unnecessary here, however it's a favourite hack of the < php 5.3 days, and I'm sticking with it (at least until I fully understand how garbage collection works in php ;).

For anything more than that, you really need to give us the specifics of your calculations, and show us your code.


问:
Is it practical to have perfect validation score on HTML?
I was in a heated discussion the other day, about whether or not it's practical to have a perfect validation score on any HTML document. By practical I mean:

Does not take a ridiculous amount of time compared to it's almost-perfect counterpart.

Can be made to look good on older browsers and to be usable on very old browsers.

Justifies the effort it may take to do so (does it come with some kind of reward on SEO/Usability/Accessibility that cannot be achieved in a simpler way with almost-perfect validation)

So basically, is perfect validation score practical on any HTML document?

答:
Unless you're going to validate as HTML 3.2 or something (and lose all the perks that come with HTML 4 or 5), your HTML is going to break in very old browsers anyway.  You're not really helping them just by having valid HTML 5.  You'd have to wrap your CSS and JS in comments, provide fallback mechanisms for browsers that lack Ajax support, etc.  So in reality, you are making more work for yourself if you care too much about that stuff.

So the question becomes, "how far back should i care about support?".  And the answer depends on your target audience (keeping in mind that 100% compatibility with every browser is a pipe dream outside of intranets).  If your site is expecting visits from PC users, there's no real need to support IE 3 or Mosaic or whatever -- no portion of users worth mentioning will be using it.  Mobile browsers, maybe you want HTML 3.2 support (some phone browsers are hopelessly out of date).  Past that, though, you don't really get anything but warm fuzzies.

What matters more is forward compatibility -- ensuring that as HTML evolves, upgrading browsers won't break your site.  For that, validation is a better thing.  The chance of support for stuff being removed is pretty low; even the HTML4 stuff that's "unsupported" in HTML 5 is supported, there are explicit instructions on how to treat it, and there's no real mechanism anymore to remove it (since doing so would break existing content).  So if your page is valid HTML 4, and doesn't use (or provides fallback mechanisms for) the stuff that's new in HTML 5, that covers probably 99% of all users, even using most of the "old" browsers.


答:
Since you didn't specify what kind of test are you talking about, i'm discussing this in general terms.

Many of this so called "validation test" are just a syntax check with a DOM of reference, this means that an high score is for a well formatted source, a lower score is for documents that does not respect the DOM guideline.

The main problem with the HTML is the fact that is an interpreted language and you do not have an implementation of reference and also the values and the attributes that you can use within the language can't be associated with an unique behaviour or an unique result.

Most of the times you also end up with the need for some hacks that can break your syntax check, sometimes is better having an uncorrected syntax rather than having an HTML page that looks ugly and can be rendered in the wrong way.

From what i know i also can't define Usability/Accessibility because this 2 words can have an infinite numbers of definitions, for a mobile user this can mean a website with bigger buttons, for a person with some eye problems can be interpreted as a better color contrast in the page; this really depends on what are you targeting.

As I said, this tests are just a syntax check but their real meaning is around zero or less, some clients can require thos little logos at the bottom of the page but i do not think that they know what a webpage is made of and how it works.

Title: Is it practical to have perfect validation score on HTML?

Body:
I was in a heated discussion the other day, about whether or not it's practical to have a perfect validation score on any HTML document. By practical I mean:

Does not take a ridiculous amount of time compared to it's almost-perfect counterpart.

Can be made to look good on older browsers and to be usable on very old browsers.

Justifies the effort it may take to do so (does it come with some kind of reward on SEO/Usability/Accessibility that cannot be achieved in a simpler way with almost-perfect validation)

So basically, is perfect validation score practical on any HTML document?


问:
Single Responsibility Principle: Responsibility unknown
I store sessions in a SessionManager. The session manager has a dependency to ISessionPersister.

SessionManager

```<code>private readonly ISessionPersister sessionPersister;
public SessionManager(ISessionPersister sessionPersister)
{
    this.sessionPersister = sessionPersister;
}
</code>```

ISessionPersister

```<code>public interface ISessionPersister : IDisposable
{
    void PersistSessions(Dictionary<string, ISession> sessions);
}
</code>```

Q: If my application shuts down how / where do I call PersistSessions? Who is responsible?

First Approach: Use Dispose in SessionManager

```<code>protected virtual void Dispose(bool disposing)
{
    if (disposing)
    {
       if (this.sessionPersister != null && this.sessionMap != null && this.sessionMap.Count > 0)
       {
           this.sessionPersister.PersistSessions(this.sessionMap);
        }
    }
}
</code>```

Is that the way to go or are there any better solutions?

答: It depends on the type of application. In a WinForms application, for example, you could use the Form.Closing event of your main form. There is also an Application.ApplicationExit event, which works independently of any form.


答: RAII is used in several places in the standard library. It's useful to see clear examples used by the standard. Good examples include any of the iostream classes, fstream, sstream, etc. Even auto_ptr (or now unique_ptr) demonstrate RAII for memory situations. </p>

Title: The benefits of using RAII in C++


答:
The question has no constructive answer unless it is clarified, but assuming that “validation” means what it used to mean (checking conformance to a Document Type Definition) in the HTML context, then the correct answer is: Validation as such means nothing except checking that your document complies to the formalized syntax rules that you wish to set up (by reference, which is the common way, or by giving your own rules). This is useful but relatively trivial.

If “validation” means using whatever program you’re using that claims to check for “validity”, then it all depends on what that program does.


问:
Writing selenium tests, should I just get it done or get it right?
I'm attempting to drive my user interface (heavy on javascript) through selenium.  I've already tested the rest of my ajax interaction with selenium successfully.  However, this one particular method seems to be eluding me because I can't seem to fake the correct click event.  I could solve this problem by simply waiting in the test for the user to click a point and then continuing with the test but this seems like a cop out.  But I'm really running out of time on my deadline to have this done and working.  Should I just get this done and move on or should I spend the extra (unknown) amount of time to fix this problem and be able to have my selenium tests 100% automated?</p>

答:
Try to find all possible workarounds.

And if nothing works classify them as non-automatable tests with proper blocker documentation. Maybe in future versions of selenium (or you application) you get some workaround for the step.


问:
What OO Design to use ( is there a Design Pattern )?
I have two objects that represent a 'Bar/Club' ( a place where you drink/socialise).

In one scenario I need the bar name, address, distance, slogon

In another scenario I need the bar name, address, website url, logo

So I've got two objects representing the same thing but with different fields.

I like to use immutable objects, so all the fields are set from the constructor.

One option is to have two constructors and null the other fields i.e:

```<code>class Bar {
     private final String name;
     private final Distance distance;
     private final Url url;

     public Bar(String name, Distance distance){
          this.name = name;
          this.distance = distance;
          this.url = null;
     }

     public Bar(String name, Url url){
          this.name = name;
          this.distance = null;
          this.url = url;
     }

     // getters
}
</code>```

I don't like this as you would have to null check when you use the getters

In my real example the first scenario has 3 fields and the second scenario has about 10, so it would be a real pain having two constructors, the amount of fields I would have to declare null and then when the object are in use you wouldn't know which Bar you where using and so what fields would be null and what wouldn't.

What other options do I have?

Two classes called BarPreview and Bar?

Some type of inheritance / interface?

Something else that is awesome?

答:
My answer to anyone with this type of problem is to break it down into manageable steps.

First just create two classes BarOne and BarTwo (or call them both Bar but in different packages)

Start using your objects as separate classes don't worry about the code duplication for now. You will notice when you get cross over (duplicate methods) from one to the other

You may find out that they are in no way related, and so you should ask yourself are they both really a bar if not rename the offending class to what it now represents

If your finding common fields or behaviour you can then extract an interface or superclass with the common behaviour

Once you have an interface or superclass you could create a builder or factory to create/retrieve your implementation objects

(4 and 5 are what the the other answers to this question are about)


问:
Getting through a lengthy book?
This may seen like a weird question, but since we're challenged--as engineers--to constantly adapt to changing technologies, we always find ourselves buried in documentation.  That said, we also need to consider that time is of the essence because people want their stuff fixed and improved with little hesitation if any.

How do you get through lengthy manuals, books/manuals within a short period of time?

Take for example: "The Linux Programming Interface," by Michael Kerrisk, which is roughly 1500 pages in length.  How would you get through a monster of a book like this if you're pressed for time while still learning most of the material?

答:
My father taught me this trick when I was a child.

Just read the book from any place without any order (or in any order,
english is not my native language).
Any way you like it. Skip hard parts, skip boring parts.
Just read.

First it will look quite a waste of time.
Suddenly you'll realize that you understand something.
And that parts that you've considered to be hard are not that hard.
With boring parts, well, it is not always the rule, but at least
you'll get the ability to distinct boring parts that could be skipped of that one
that are nevertheless worth to read.

Surprisingly, reading this way is less time consuming and more efficient
compared to "disciplined" approach.

Its like painting something wooden. One layer of paint is never enough.

Title: Getting through a lengthy book?


答:
I think the problem is that you aren't modeling a Bar in either of those scenarios (And your are modeling two different problems, objects, etc..). If I see a class Bar I'd expect some functionality related to drinks, the menus, the seats available, and your object has none of that. If I see your objects behavior you are modeling information about an establishment. Bar is what you are using those for at this moment, but it's not the intrinsically behavior they are implementing. (In another context: If you are modeling a Marriage, you'll have two instance variables Person wife; Person husband; a wife is the current role you are giving that object at that moment, but the object is still a Person).
I'd do something like this:</p>

```<code>class EstablishmentInformation {
     private final String name;

     public EstablishmentInformation(String name){
          this.name = name;
     }

     // getters
}

class EstablishmentLocationInformation {
    EstablishmentInformation establishmentInformation;
     private final Distance distance;

     public EstablishmentLocationInformation (String name, Distance distance){
          this.establishmentInformation = new EstablishmentInformation(name)
          this.distance = distance;
     }
}

class EstablishmentWebSiteInformation {
    EstablishmentInformation establishmentInformation;
     private final Url url;

     public EstablishmentWebSiteInformation(String name, Url url){
          this.establishmentInformation = new EstablishmentInformation(name)
          this.url = url;
     }
}
</code>```

Title: What OO Design to use ( is there a Design Pattern )?

Body:
I have two objects that represent a 'Bar/Club' ( a place where you drink/socialise).

In one scenario I need the bar name, address, distance, slogon

In another scenario I need the bar name, address, website url, logo

So I've got two objects representing the same thing but with different fields.

I like to use immutable objects, so all the fields are set from the constructor.

One option is to have two constructors and null the other fields i.e:

```<code>class Bar {
     private final String name;
     private final Distance distance;
     private final Url url;

     public Bar(String name, Distance distance){
          this.name = name;
          this.distance = distance;
          this.url = null;
     }

     public Bar(String name, Url url){
          this.name = name;
          this.distance = null;
          this.url = url;
     }

     // getters
}
</code>```

I don't like this as you would have to null check when you use the getters

In my real example the first scenario has 3 fields and the second scenario has about 10, so it would be a real pain having two constructors, the amount of fields I would have to declare null and then when the object are in use you wouldn't know which Bar you where using and so what fields would be null and what wouldn't.

What other options do I have?

Two classes called BarPreview and Bar?

Some type of inheritance / interface?

Something else that is awesome?

Body:
I think the problem is that you aren't modeling a Bar in either of those scenarios (And your are modeling two different problems, objects, etc..). If I see a class Bar I'd expect some functionality related to drinks, the menus, the seats available, and your object has none of that. If I see your objects behavior you are modeling information about an establishment. Bar is what you are using those for at this moment, but it's not the intrinsically behavior they are implementing. (In another context: If you are modeling a Marriage, you'll have two instance variables Person wife; Person husband; a wife is the current role you are giving that object at that moment, but the object is still a Person).
I'd do something like this:

class EstablishmentInformation {
     private final String name;

     public EstablishmentInformation(String name){
          this.name = name;
     }

     // getters
}

class EstablishmentLocationInformation {
    EstablishmentInformation establishmentInformation;
     private final Distance distance;

     public EstablishmentLocationInformation (String name, Distance distance){
          this.establishmentInformation = new EstablishmentInformation(name)
          this.distance = distance;
     }
}

class EstablishmentWebSiteInformation {
    EstablishmentInformation establishmentInformation;
     private final Url url;

     public EstablishmentWebSiteInformation(String name, Url url){
          this.establishmentInformation = new EstablishmentInformation(name)
          this.url = url;
     }
}


问:
Company PC refresh, laptop or desktop?
My company is getting PC refreshes with a choice of to have a desktop or laptop.  Each one seems to have its pros and cons. Would you want the flexibility and freedom of the laptop but take the risk of working extra hours at home? Or a desktop limited to one place, but not having to worry about taking work home and disrupting home time?

I'm not asking what would be better for coding, but more for convenience and productivity.  I currently have a desktop and work about 8 to 9 hours a day, with only coming in on the weekends for when we get behind on major deadlines. I love developing but I also have quite a busy life after work. I feel that having a work laptop will only haze the line of work and home.

答: I recently underwent a refresh and opted to use a laptop, but only because I could have a docking station with an external mouse/keyboard and 2 monitors.  The main benefit is that home working is simplified as I could only access my desktop from home by RDP, and we all know how dis-orientating developing over RDP can be...especially over a dog-slow connection!</p>

Title: Company PC refresh, laptop or desktop?


问:
WWDC 2012 announced features on iOS 5?
I am relatively new to iOS development, so after watching a bunch of WWDC videos announcing new awesome features for the iPhone SDK, I still got a few questions regarding their support for older devices. Specifically:

Do the new compiler features (such as literals support, auto-synthesize, etc) require iOS 6 on the target device, or can the new style code be deployed to iOS 5 devices?

Auto-layout for iOS, same question. Will it only be supported on iOS 6, or 5 as well? If it's 6 only, what kind of fallback are we expected to implement?

Would really appreciate if someone could clarify this for me, as I'm thinking about rewriting my older unfinished project and I would love to use some of that improved SDK functionality.

答:
My understanding is that features implemented by the compiler, such as object literals, can be deployed on older systems. Features that require support from the runtime or from new/modified frameworks, probably including auto layout, will require iOS 6.

It's trivial to figure out whether any given feature will work on iOS 5... just build a simple sample project that uses the feature and try to run it under iOS 5. I don't remember how the new auto-synthesize stuff fits in, for example, but you can certainly try it out.

Title: WWDC 2012 announced features on iOS 5?


答:
There are two types of books: tutorials and reference books/manuals.

It's useful and necessary to read tutorials from cover to cover, and preferably do all the exercises. Otherwise, you'll never be sure not to have missed something important.

What comes to reference books, one can't remember everything in such a book in a short period of time (i.e. less than a month, or even more). It's more useful to learn the key concepts and to see exactly what features are described in the book. So you'll be able to find those features easily when needed, and you wouldn't reinvent a bicycle because you know there already is one.

Title: Getting through a lengthy book?

Body:
This may seen like a weird question, but since we're challenged--as engineers--to constantly adapt to changing technologies, we always find ourselves buried in documentation.  That said, we also need to consider that time is of the essence because people want their stuff fixed and improved with little hesitation if any.

How do you get through lengthy manuals, books/manuals within a short period of time?

Take for example: "The Linux Programming Interface," by Michael Kerrisk, which is roughly 1500 pages in length.  How would you get through a monster of a book like this if you're pressed for time while still learning most of the material?


问:
moving from Windows to Linux
I need to reconcile these 2 facts:

I don't feel comfortable working on Linux;

I need to develop software for Linux.

Some background: I have a 10+ years of programming experience on Windows (almost exclusively C/C++, but some .NET as well), I was a user of FreeBSD at home for about 3 years or so (then had to go back to Windows), and I've never had much luck with Linux. And now I have to develop software for Linux. I need a plan.

On Windows, you can get away with just knowing a programming language, an API you're coding against, your IDE (VisualStudio) and some very basic tools for troubleshooting (Depends, ProcessExplorer, DebugView, WinDbg). Everything else comes naturally.

On Linux, it's a very different story. How the hell would I know what DLL (sorry, Shared Object) would load, if I link to it from Firefox plugin? What's the Linux equivalent of inserting __asm int 3/DebugBreak() in the source and running the program, and then letting the OS call a debugger? Why the hell release builds use something, called appLoader, while debug builds work somehow different? Worst of all: how to provision Linux development environment?

So, taking into account that hatred is usually associated with not knowing enough, what would you recommend? I'm ok with Emacs and GCC. I need to educate myself as a Linux admin/user, and I need to learn proper troubleshooting tools (strace is cool, btw), equivalents to the ones I mentioned above.

Do I need to do Linux from Scratch? Or do I need to just read some books (I've read "UNIX programming environment" by Kernighan and "Advanced Programming..." by Stevens, but I need to learn something more practical)? Or do I need to have some Linux distro on my home computer?

答:
I don't think you need to do Linux from Scratch. If I were you I would go for Ubuntu. It is more comfortable, and being based on debian, there is plenty of technical material available.

If you do want more of a head-first dive into Linux, Gentoo is a good option. It requires you to read quite a lot about configuration and kernels, but it also gives you quite a functional system to work in af

OwnerDisplayName: rincewind

Title: moving from Windows to Linux


答:
Gigantic reference manuals aren't for casual reading.  I have many on my bookshelf, and I reach for them only when I have a question and turn to the index first.

Most of the how-to or introductory books in the software engineering world are only a few hundred pages at most.  I get most of my reading done in bed (each night I read until I pass out with a book on my chest, 'tis the price that must be paid to stay employed in this business).

Also, a long flight is good for catching up on your reading.  If you fly often, get an e-reader, and not one of the new sissy models with a color lcd screen.  Get a proper e-ink kindle or similar.  Perfect for reading up on some new technology on your way to a job interview, for example.

Title: Getting through a lengthy book?


答:
As already mentioned, You cannot possibly comprehend everything in long technical text in just a short amount of time. Therefore, my take on this would be to identify the key points by first skimming through the text. Next focus your reading on what seems most relevant to whatever field you're working in.

Using spaced repetition would be a good idea in order to enhance future retention of topics or details that you think would be worthwhile to remember for longer than the next few days.

Now it isn't always simple to assess the relative importance of various topics in a text; this is especially true when doing initial research in an unfamiliar field. In such situations I personally often find myself tempted to approach texts in a very meticulous manner, with the result being that I end up not seeing the forest for the trees and I might even miss out on the ideas or concepts that would have been most important for me to understand. Obviously setting out to study a topic in detail, but in too short time-span, is just setting out to fail in the first place.

Title: Getting through a lengthy book?


答:
I know that the answer has been accepted already, but I just want to say this.

Different browsers respond differently to errors. If you have errors in your HTML, the probability that it will look the same in different browsers will be smaller.

This isn't about older browsers. It's about current browsers. If you look at your webpage with the latest browsers, differences in how they display it will be smaller if you use error-free HTML.

Here's a list with samples of how browsers respond to errors on my own website.


问:
Functional Programming, JavaScript and UI - some neophyte questions
In the discussion here, the comments in the accepted answer suggest that I approach the given code from a functional perspective, which was new to me at the time. Wikipedia said, among other things, that FP "avoids state and mutable data", which includes according to the discussion global vars. Now, being that I am already pretty far along in my project I am not going to learn FP before I finish, but:

How is it possible to avoid global vars if, for instance, I have a UI whose entire functionality changes if a mousebutton is down? I have a number of things like this.

Why was there a strong negative reaction among some experienced coders to implementing FP in JS? When I brought up what seemed to me to be supportive comments by Crockford, people got even madder. Are there strong arguments against using fp in JS? What constitutes a "functional language" and why is JS "not it"?

答:
Please note: There is never an excuse for being a total douchebag. I am not justifying bad behavior on IRC but hopefully this will offer some perspective.

Avoiding global vars is easy. If I understand FP correctly however, the idea is to avoid generalized state altogether. This does not jive well with closure/event-driven UI work, IMO, which are two things JavaScript is very good at. You should of course, be careful to avoid letting state become overly generalized to the point where a wide variety of objects can be responsible for changing it. When tempted to make state completely global, you should be asking yourself if you shouldn't be creating a composite object of several smaller UI objects that owns responsibility for that state.

Crockford's done a lot of good work but we don't all revere him as some sort of god and I for one disagree with a lot of stuff he's declared "the bad parts" of JavaScript.  I also find most of JSLint's default rules excessive, silly, and overly reflective of one developer's personal coding preferences. Function hoisting for instance, is fantastic. I love getting straight to the business logic in my apps at the top of my objects and callback functions and declaring the inlines below. FP itself seems overly procedural, IMO. Complex UI, which you don't see a lot of on Yahoo, is better served by a more loosely-coupled, event/messaging-driven paradigm in my experience. JS derives it's flexibility and power from closures and first-class functions. Not having any upper layers where state can be referenced isn't really a great fit with that, IMO.

Edit: Avoiding global vars

```<code>(function(){

    var comboBoxesLoaded = false;

    comboBoxesLoaded = UI.ComboBoxFactory.initiateComboBoxes();
    //builds comboboxes and returns true

})()

alert(comboBoxesLoaded); //undefined error here.
</code>```

Technically, you're not declaring a global var. comboBoxesLoaded is a state var scoped in an anonymous function but it's better to have a comboBox object that maintains its own state and also manages stuff like one (or several) comboBoxes loading in new data when another is changed.

All this does is avoid global namespace collisions, which is good, but you're still maintaining state in an overly general space where anything else you drop inside the anon function could hit it. (the idea behind this pattern is that you drop a ton of your code inside that anon function so you don't have to sweat blowing up other code you don't control by accidentally giving a global var the same name)

But it's stil better to let your combobox factory manage that state. It can listen to other objects to make changes but when you're certain you know only the factory is actually putting its hands on its own internal state vars you have one central point to go to when you're wondering why you're encountering an unexpected state at some point of breakage and the object itself can keep track of who it was listening to last.

Example of composite objects? That's getting into writing a small app territory. Maybe later.

Body:
Please note: There is never an excuse for being a total douchebag. I am not justifying bad behavior on IRC but hopefully this will offer some perspective.

Avoiding global vars is easy. If I understand FP correctly however, the idea is to avoid generalized state altogether. This does not jive well with closure/event-driven UI work, IMO, which are two things JavaScript is very good at. You should of course, be careful to avoid letting state become overly generalized to the point where a wide variety of objects can be responsible for changing it. When tempted to make state completely global, you should be asking yourself if you shouldn't be creating a composite object of several smaller UI objects that owns responsibility for that state.

Crockford's done a lot of good work but we don't all revere him as some sort of god and I for one disagree with a lot of stuff he's declared "the bad parts" of JavaScript.  I also find most of JSLint's default rules excessive, silly, and overly reflective of one developer's personal coding preferences. Function hoisting for instance, is fantastic. I love getting straight to the business logic in my apps at the top of my objects and callback functions and declaring the inlines below. FP itself seems overly procedural, IMO. Complex UI, which you don't see a lot of on Yahoo, is better served by a more loosely-coupled, event/messaging-driven paradigm in my experience. JS derives it's flexibility and power from closures and first-class functions. Not having any upper layers where state can be referenced isn't really a great fit with that, IMO.

Edit: Avoiding global vars

(function(){

    var comboBoxesLoaded = false;

    comboBoxesLoaded = UI.ComboBoxFactory.initiateComboBoxes();
    //builds comboboxes and returns true

})()

alert(comboBoxesLoaded); //undefined error here.

Technically, you're not declaring a global var. comboBoxesLoaded is a state var scoped in an anonymous function but it's better to have a comboBox object that maintains its own state and also manages stuff like one (or several) comboBoxes loading in new data when another is changed.

All this does is avoid global namespace collisions, which is good, but you're still maintaining state in an overly general space where anything else you drop inside the anon function could hit it. (the idea behind this pattern is that you drop a ton of your code inside that anon function so you don't have to sweat blowing up other code you don't control by accidentally giving a global var the same name)

But it's stil better to let your combobox factory manage that state. It can listen to other objects to make changes but when you're certain you know only the factory is actually putting its hands on its own internal state vars you have one central point to go to when you're wondering why you're encountering an unexpected state at some point of breakage and the object itself can keep track of who it was listening to last.

Example of composite objects? That's getting into writing a small app territory. Maybe later.


问:
Where is the application of Calculus (of continuous quantities) in Computer Science or programming
I am a Software Engineer professional. I have studied calculus as a core course in my graduation studies. I want to ask question, that what/where is the implementation of calculus in computer science?</p>

答:
I used a lot of calculus for creating continuous interpolations.
For example, I use this in fractal animation software, where smooth transitions are desired.
Furthermore, everything that has to do with continuous motion, like a game with a bouncing ball, etc. or acceleration sort of becomes easier with calculus.
Thirdly, a lot of the stuff mentioned above can be simplified/optimized if one has a basic understanding of trigonometric functions.</p>


答:
I think you answered your question in the question:

"On Windows, you can get away with just knowing a programming language, an API you're coding against, your IDE (VisualStudio) and some very basic tools for troubleshooting (Depends, ProcessExplorer, DebugView, WinDbg). Everything else comes naturally."

Gues what, on Linux you can get away with just knowing a programming language, an API (or a couple), your IDE (Eclipse or NetBeans, even Geany, Emacs, or vim, if you like) and some basic tools for troubleshooting (gdb, tracing tools, lint, htop, ps).

You have a lot of knowledge invested in the Windows programming ecosystem. Much of that is (hopefully) abstract knowledge (what's a compiler, a debugger, a shared library, a process, a thread? What do they do?) that will tranlate easily, once you get up to speed on the different tools. Some is domain specific (What DLL is linked when I add X to a project?), but even moving from one class of language to another within Windows would require some new learning.

Install Ubuntu or Fedora in a VM, read some C++ Hello World in Eclipse or NetBeans tutorials, and some debugging in Eclipse/NetBeans tutorials, and let your brain's natural ability to adapt take over. It'll translate ideas for you if you relax and just put it to work.

Title: moving from Windows to Linux

Body:
I need to reconcile these 2 facts:

I don't feel comfortable working on Linux;

I need to develop software for Linux.

Some background: I have a 10+ years of programming experience on Windows (almost exclusively C/C++, but some .NET as well), I was a user of FreeBSD at home for about 3 years or so (then had to go back to Windows), and I've never had much luck with Linux. And now I have to develop software for Linux. I need a plan.

On Windows, you can get away with just knowing a programming language, an API you're coding against, your IDE (VisualStudio) and some very basic tools for troubleshooting (Depends, ProcessExplorer, DebugView, WinDbg). Everything else comes naturally.

On Linux, it's a very different story. How the hell would I know what DLL (sorry, Shared Object) would load, if I link to it from Firefox plugin? What's the Linux equivalent of inserting __asm int 3/DebugBreak() in the source and running the program, and then letting the OS call a debugger? Why the hell release builds use something, called appLoader, while debug builds work somehow different? Worst of all: how to provision Linux development environment?

So, taking into account that hatred is usually associated with not knowing enough, what would you recommend? I'm ok with Emacs and GCC. I need to educate myself as a Linux admin/user, and I need to learn proper troubleshooting tools (strace is cool, btw), equivalents to the ones I mentioned above.

Do I need to do Linux from Scratch? Or do I need to just read some books (I've read "UNIX programming environment" by Kernighan and "Advanced Programming..." by Stevens, but I need to learn something more practical)? Or do I need to have some Linux distro on my home computer?


答:
Use books as reference documentation

I normally just "index" the books I'm interested in, that is, I read the actual index, make sense of it, then just randomly read the book for 5 to 10 minutes to try to know it.

Whenever I recall about something interesting in X book it is generally because I need it. Then I go back to the book and use it as reference.

There is always (unscheduled) time to read

The other way I get through books: I carry them in my smartphone. Whenever I'm bored, need a break or at lunch-time, I start reading from my phone (I use Kindle for Android)... at the end of the week I'm generally amazed on how much I advanced my reading without having to schedule it.

Note: I have a Galaxy Note, so reading is very pleasant in my phone.

Title: Getting through a lengthy book?


答:
In the post that you reference, first off, I agree fully with the advice of @lwburk
He writes a very nice answer.

Secondly, I'd like to quickly address the "functional programming" aspect, this may be distracting, potentially not what was originally intended, and is a good candidate for inviting comments that diverge from the core issue here.

So, I would like to expand on the advice of @lwburk, and on your follow-up question, as it is a valid Advanced JavaScript question:

How is it possible to avoid global vars?

At a high-level, what is being referenced here is a Design Pattern in JavaScript called (among other names) the Namespace pattern. It is fundamentally beneficial, but... as with any design pattern, it is possible to over-use, while uncommon, into an anti-pattern. Which sounds to me, like your counter-argument. So, let me explain... please hear me out.

The reasoning behind limiting global variables boils down to a simple purpose. We wish to avoid naming conflicts, collisions, or otherwise clobbering of variables as others come into scope... with the same name - at runtime. There are other reasons, but this is the primary one.

To me, this may be potentially simple, because if your environment has minimal change, and the chance of clobbering is minimal, then this pattern is, in some cases, not implemented for its intended purpose,

but... following this pattern uniformly has an upside of
  object-oriented encapsulation, and this reasoning is why it is
  commonly recommended for all environments.

Encapsulating data within an object makes it modular, in addition to protecting it from clobbering. Here is the pattern:

```<code>var app = app || {};

app.init = (function() {

  // Private vars and methods
  var foo; // ...

  // Methods in here are public
  return {
    method: function() {

    }
  };

}());
</code>```

Now, just look at the app variable for the namespace, the internal part is an advanced topic called Closures and IIFE(Immediately invoked function execution)
at first it looks egyptian, but get used to it, soon it becomes an old friend.
It looks like this:

(function() {
    var x; //here
    function xy (){} //here

```<code>// do Stuff here.
</code>```

}());

This is a really important pattern!

The reason is that it allows you to turn JS into an oozy play-doh like substance. What the heck do I mean? Encapsulate all your variables within a named object. Now they can maintain state and float around in your single global member "namespace". Why is this a flexible substance? I'll get to that in the answer to the second question, as they seem related. But for now realize that this pattern allows JS to become highly transient: once modular.

Be warned, this is the beginning of Advanced JavaScript - not the end. Allowing one object to communicate with another namespaced objects is, yet another, advanced topic.

Quick Tangent:

*To keep objects nicely modular and decoupled, send events between an intermediary not direct references (it is so easy to do so) between all objects. References become a maintenance-nightmare. Look up PubSub or Evented Views for this tangent.

Let me explain why flexibility may cause mixed-reaction.

Why was there a strong negative reaction?

Such a good question, worthy of a psychological or socialogical review. And we dont have time. More often than not, when speaking about Advanced JavaScript - for whatever reason... a strong negative reaction can occur. Have you observed this in practice, yes?

it may be that the original question is inflammatory,

however, I see here you are asking an honest question of serious
  intent. So let me please dismiss that speculation.

The other possibility is that, potentially, there is a negative reaction external to your question. Wait that is strange? What? Why?

There seems, an unspoken stigma. A misconception. Anyone know what I am talking about - have you observed this? Something, somehow, somewhere - there is a n embedded reaction... JS has a tangled history with naming, confused with Java,... misunderstood as a 'Toy-Language' and yadda yadda yadda,

(look up Enter the Dragon - Dmitry Baronovski) That said, there is another > point I
  wish to raise here that is far more important and that is.... flexibility.

Flexibility

JavaScript flexibility causes... different perspectives.

JavaScript is very flexible language. No? It is so flexible, to the point, that it can be squeezed out one hole and become a server(node.js), another and become a datbase (MongoDB), another and become MVC (backbone) and yet another and become a rich enterprise framework (ExtJS or jQuery)... and don't forget Mobile; phonegap, or Build: grunt. This is remarkable. It is like play-doh. Yes a toy-language indeed.

So now lets consider how JS exists in CoffeeScript, or GWT, Dart, or Windows 8. They are remarkably different beasts.

This comes full circle to the controversial point raised earlier that "functional programming" conversation might be "distracting".  In all respect, let me clarify, "functional programming", while it can be defined at wikipedia - has a very good chance of a spudo-philosophical meaning that ends up meaning something slightly different to all of us.

The fact is, JavaScript can be seen in so many different ways (paradigms), that
  we should, at some point, think about viewing it through different lenses.
  JS exists in many context domains, it is a point of significant growth, and will be even moreso in the future.

The problem here, with this, is us. Honesty is the best policy and here is my humble pie. The problem is that it is an 'invisible fruit'. Please bear with me, I have a point...

Invisible-Fruit

The notion is this: we all like our programmatic fruit. But code is, essentially invisible - because it cannot be consumed, digested, conceptualized... in a single glance or sitting. It must be consumed. So we tend to go... with what we know. This is primarily because, often times we bite into a pit, sometimes an orange-peel, and in the most unfortunate of occasions - a lump of coal.

It is for this reason that if some stranger hands you their invisible fruit, saying, check this out it is great... no matter what they may say - you are suspicious. Aren't you?

There are two options: 1 of agnosticism, 2 of aversion.

In order to intellectually consume the new programmatic paradigm, one must make a blind leap-of-faith and - "take a bite". Do you observe this is in practice?

So why the aversion?

Because sometimes we are biting into a lump of coal.

But more often than not, because we are biting-into a lump of code that is beneficial to another engineer in another context - but is just not beneficial to us.

Do you know what I mean?

Did you ever fervently consider the notion, which is better: jQuery, ExtJS, YUI, Dojo, MooTools, Backbone, Underscore, Require, etc...

****The take-away is this.****

JavaScript is so malleable (through the advanced code that begins with the namespace pattern) it can transcend technologies in a way that makes JS not really better or worse implementations, but just different tools for a different jobs. And some are a better fit than others. I still hear many conversations accidentally fall into this.

Perhaps, we can -eventually- begin to think about lowering our defenses. in this language of the web - this multi-paradigm, meta-morphing language, our old pal JavaScript - and see it through separate lenses.

Time and again we find, the solution depends on the context. But time
  and again we defend persistently- our minority experience.

JavaScript is larger than any one of us.

This is a good thing. "Enter the Dragon"

My apologies for length of perspective.
I hope this helps. All the best, Nash

...

Title: Functional Programming, JavaScript and UI - some neophyte questions

Body:
In the discussion here, the comments in the accepted answer suggest that I approach the given code from a functional perspective, which was new to me at the time. Wikipedia said, among other things, that FP "avoids state and mutable data", which includes according to the discussion global vars. Now, being that I am already pretty far along in my project I am not going to learn FP before I finish, but:

How is it possible to avoid global vars if, for instance, I have a UI whose entire functionality changes if a mousebutton is down? I have a number of things like this.

Why was there a strong negative reaction among some experienced coders to implementing FP in JS? When I brought up what seemed to me to be supportive comments by Crockford, people got even madder. Are there strong arguments against using fp in JS? What constitutes a "functional language" and why is JS "not it"?

Body:
In the post that you reference, first off, I agree fully with the advice of @lwburk
He writes a very nice answer.

Secondly, I'd like to quickly address the "functional programming" aspect, this may be distracting, potentially not what was originally intended, and is a good candidate for inviting comments that diverge from the core issue here.

So, I would like to expand on the advice of @lwburk, and on your follow-up question, as it is a valid Advanced JavaScript question:

How is it possible to avoid global vars?

At a high-level, what is being referenced here is a Design Pattern in JavaScript called (among other names) the Namespace pattern. It is fundamentally beneficial, but... as with any design pattern, it is possible to over-use, while uncommon, into an anti-pattern. Which sounds to me, like your counter-argument. So, let me explain... please hear me out.

The reasoning behind limiting global variables boils down to a simple purpose. We wish to avoid naming conflicts, collisions, or otherwise clobbering of variables as others come into scope... with the same name - at runtime. There are other reasons, but this is the primary one.

To me, this may be potentially simple, because if your environment has minimal change, and the chance of clobbering is minimal, then this pattern is, in some cases, not implemented for its intended purpose,

but... following this pattern uniformly has an upside of
  object-oriented encapsulation, and this reasoning is why it is
  commonly recommended for all environments.

Encapsulating data within an object makes it modular, in addition to protecting it from clobbering. Here is the pattern:

var app = app || {};

app.init = (function() {

  // Private vars and methods
  var foo; // ...

  // Methods in here are public
  return {
    method: function() {

    }
  };

}());

Now, just look at the app variable for the namespace, the internal part is an advanced topic called Closures and IIFE(Immediately invoked function execution)
at first it looks egyptian, but get used to it, soon it becomes an old friend.
It looks like this:

(function() {
    var x; //here
    function xy (){} //here

// do Stuff here.

}());

This is a really important pattern!

The reason is that it allows you to turn JS into an oozy play-doh like substance. What the heck do I mean? Encapsulate all your variables within a named object. Now they can maintain state and float around in your single global member "namespace". Why is this a flexible substance? I'll get to that in the answer to the second question, as they seem related. But for now realize that this pattern allows JS to become highly transient: once modular.

Be warned, this is the beginning of Advanced JavaScript - not the end. Allowing one object to communicate with another namespaced objects is, yet another, advanced topic.

Quick Tangent:

*To keep objects nicely modular and decoupled, send events between an intermediary not direct references (it is so easy to do so) between all objects. References become a maintenance-nightmare. Look up PubSub or Evented Views for this tangent.

Let me explain why flexibility may cause mixed-reaction.

Why was there a strong negative reaction?

Such a good question, worthy of a psychological or socialogical review. And we dont have time. More often than not, when speaking about Advanced JavaScript - for whatever reason... a strong negative reaction can occur. Have you observed this in practice, yes?

it may be that the original question is inflammatory,

however, I see here you are asking an honest question of serious
  intent. So let me please dismiss that speculation.

The other possibility is that, potentially, there is a negative reaction external to your question. Wait that is strange? What? Why?

There seems, an unspoken stigma. A misconception. Anyone know what I am talking about - have you observed this? Something, somehow, somewhere - there is a n embedded reaction... JS has a tangled history with naming, confused with Java,... misunderstood as a 'Toy-Language' and yadda yadda yadda,

(look up Enter the Dragon - Dmitry Baronovski) That said, there is another > point I
  wish to raise here that is far more important and that is.... flexibility.

Flexibility

JavaScript flexibility causes... different perspectives.

JavaScript is very flexible language. No? It is so flexible, to the point, that it can be squeezed out one hole and become a server(node.js), another and become a datbase (MongoDB), another and become MVC (backbone) and yet another and become a rich enterprise framework (ExtJS or jQuery)... and don't forget Mobile; phonegap, or Build: grunt. This is remarkable. It is like play-doh. Yes a toy-language indeed.

So now lets consider how JS exists in CoffeeScript, or GWT, Dart, or Windows 8. They are remarkably different beasts.

This comes full circle to the controversial point raised earlier that "functional programming" conversation might be "distracting".  In all respect, let me clarify, "functional programming", while it can be defined at wikipedia - has a very good chance of a spudo-philosophical meaning that ends up meaning something slightly different to all of us.

The fact is, JavaScript can be seen in so many different ways (paradigms), that
  we should, at some point, think about viewing it through different lenses.
  JS exists in many context domains, it is a point of significant growth, and will be even moreso in the future.

The problem here, with this, is us. Honesty is the best policy and here is my humble pie. The problem is that it is an 'invisible fruit'. Please bear with me, I have a point...

Invisible-Fruit

The notion is this: we all like our programmatic fruit. But code is, essentially invisible - because it cannot be consumed, digested, conceptualized... in a single glance or sitting. It must be consumed. So we tend to go... with what we know. This is primarily because, often times we bite into a pit, sometimes an orange-peel, and in the most unfortunate of occasions - a lump of coal.

It is for this reason that if some stranger hands you their invisible fruit, saying, check this out it is great... no matter what they may say - you are suspicious. Aren't you?

There are two options: 1 of agnosticism, 2 of aversion.

In order to intellectually consume the new programmatic paradigm, one must make a blind leap-of-faith and - "take a bite". Do you observe this is in practice?

So why the aversion?

Because sometimes we are biting into a lump of coal.

But more often than not, because we are biting-into a lump of code that is beneficial to another engineer in another context - but is just not beneficial to us.

Do you know what I mean?

Did you ever fervently consider the notion, which is better: jQuery, ExtJS, YUI, Dojo, MooTools, Backbone, Underscore, Require, etc...

****The take-away is this.****

JavaScript is so malleable (through the advanced code that begins with the namespace pattern) it can transcend technologies in a way that makes JS not really better or worse implementations, but just different tools for a different jobs. And some are a better fit than others. I still hear many conversations accidentally fall into this.

Perhaps, we can -eventually- begin to think about lowering our defenses. in this language of the web - this multi-paradigm, meta-morphing language, our old pal JavaScript - and see it through separate lenses.

Time and again we find, the solution depends on the context. But time
  and again we defend persistently- our minority experience.

JavaScript is larger than any one of us.

This is a good thing. "Enter the Dragon"

My apologies for length of perspective.
I hope this helps. All the best, Nash

...


答: If there's a docking station that you can attach monitor(s) to, then either would work. Working at a laptop for any sufficiently long period of time will wrench the heck out of your neck.</p>

Title: Company PC refresh, laptop or desktop?

Body:
My company is getting PC refreshes with a choice of to have a desktop or laptop.  Each one seems to have its pros and cons. Would you want the flexibility and freedom of the laptop but take the risk of working extra hours at home? Or a desktop limited to one place, but not having to worry about taking work home and disrupting home time?

I'm not asking what would be better for coding, but more for convenience and productivity.  I currently have a desktop and work about 8 to 9 hours a day, with only coming in on the weekends for when we get behind on major deadlines. I love developing but I also have quite a busy life after work. I feel that having a work laptop will only haze the line of work and home.


问:
Performance of concurrent software on multicore processors
Recently I have often read that, since the trend is to build processors with multiple cores, it will be increasingly important to have programming languages
that support concurrent and parallel programming in order to better exploit the parallelism offered by these processors (see e.g. this video for some background.).

In this respect, certain programming paradigms or models are considered well-suited for writing robust concurrent software:

Functional programming languages, e.g. Haskell, Scala, etc.

The actor model: Erlang, but also available for Scala / Java (Akka), C++ (Theron, Casablanca, ...), and other programming languages.

My questions:

What is the state of the art regarding the development of concurrent applications (e.g. using multi-threading) using the above languages / models? Is this area still being explored or are there well-established practices already?

Will it be more complex to program applications with a higher level of concurrency, or is it just a matter of learning new paradigms and practices?

How does the performance of highly concurrent software compare to the performance of more traditional software when executed on multiple core processors?

For example, has anyone implemented a desktop application using C++ / Theron, or Java / Akka? Was there a boost in performance on a multiple core processor due to higher parallelism?

EDIT

NOTE that I am not asking for your opinions or for debate but for concrete experiences or information. For example, has anyone written a Scala or Haskell program, compiled it with existing state-of-the-art compilers, and

Run it on an Intel Core i3 and measured a certain performance (e.g. 10 seconds on certain input data).

Run the same bytecode or binary on an Intel Core i5 and observed a performance boost (e.g. 6 seconds running time) due to the parallel computation of sub-expressions which is possible in functional code?

EDIT 2

SUMMARIZING.
Up to now making faster processors meant increasing the clock speed, and no changes in programming paradigm were needed. In the last few years making faster processor has meant adding more cores but this requires we write software differently. My question is whether software developers are starting to switch to new programming paradigms and whether this is bringing the expected performance boost on multiple-core processors.

答:
(This is not a full answer, but it seems too long to fit in a comment.)

There are many factors affecting the adoption rate of "Design for parallelism" in the software industry. Some of them had nothing to do with the benefits. For example, the skill sets and knowledge levels of developers, etc.

One of my observation is that the type of application determines its adoption rate of parallel paradigm. Each software product line (level) or component has one or more "natural domain / paradigm"; that is, the software would be much easier to develop and maintain if it was implemented in a particular paradigm.

If a paradigm switch is necessary in order to parallelize a certain application, chances are that software companies won't find that cost-effective to justify. If that particular paradigm is easily parallelizable, then what you see is that those software would have higher adoption rate for parallel programming.

Regarding the list of paradigms, I would like to add Dataflow. All tasks are declared up-front. Each task declares its inputs and outputs before execution. A task is started as soon as all of its input data is available.

Examples of Dataflow paradigm:

Intel Concurrent Collections (CnC)

Habanero

LabView

Answer 1:

Having one very successful paradigm is not enough. To bring up adoption rate of parallel programming, parallelism need to be introduced to other paradigms (including the "outdated" ones) as well.

I have seen others who successfully implemented parallelism in a Windows GUI program, by spawning one Windows dialog (each Windows dialog is housed in a thread) per computation task, and exchange data using Windows messages.

Answer 2:

This echoes my observation above: if the introduction of parallelism into an application requires that application to be rewritten in an unnatural paradigm, then the complexity of development and maintenance will be increased.

Answer 3:

For purely computationally-intensive tasks, the performance gain usually matches very closely with the prediction by Amdahl's Law, provided that all of the computation is done locally on a computer (i.e. not subject to the much slower network I/O traffic.)

That said, you will quickly find out there are non-parallelizable bottlenecks in your applications. Sometimes these bottlenecks are theoretically non-parallelizable, meaning there is no hope of finding a better algorithm.

Answer 4:

A personal story. I have written a simple parallelized program that decodes a JPEG file, resize it, and then save it into a custom image file format. Upon testing, I find that the program takes 1.6 seconds to finish, when tested using 3 threads or 4 threads. It turns out the JPEG decoding step is taking more than 25% of the time, making it the slowest non-parallelizable step.

In other words, Amdahl's law takes effect with just 3-4 CPU cores for my little program.

Sometimes these bottlenecks can be removed if you are allowed to change the software requirements (for example, if you could require your customers to not use a particular image format), but most of the time the requirements are set in stone.


问:
how to change the sequence used in planning poker
Is it possible to change the used sequence in Planning Poker, for some stories, it is thought that when the stories gets larger it contains more uncertainty but stories have nearly exact time estimations and these estimations don't drop into two bounds defined by Fibonacci series.</p>

答:
There is at least one more reason why you do not want to change the sequence: because it'll put too much emphasis on trying to get accurate forecasts instead of rough estimates, which is what story pointing should get you.

I'm a people manager and an early mistake we made was to put a lot of emphasis on points, velocity, etc. Our engineers, realizing that points were important to management, were incentivized to maximize said points such that we quickly entered into debates over them. That energy is a complete waste to the product development process and should be reduced/eliminated.

I don't believe points are terribly useful in trying to derive schedules over the short run. After a half-dozen or more sprints with the same team(s)? Then yes, management can extrapolate assuming there is a well groomed backlog, which is itself easier said than done.

Do you want engineers arguing over points or getting stuff done? Your choice based on what you choose to emphasize.

OwnerDisplayName: yesildal


问:
How to become a good team player?
I've been programming (obsessively) since I was 12.  I am fairly knowledgeable across the spectrum of languages out there, from assembly, to C++, to Javascript, to Haskell, Lisp, and Qi.  But all of my projects have been by myself.

I got my degree in chemical engineering, not CS or computer engineering, but for the first time this fall I'll be working on a large programming project with other people, and I have no clue how to prepare.  I've been using Windows all of my life, but this project is going to be very unix-y, so I purchased a Mac recently in the hopes of familiarizing myself with the environment.

I was fortunate to participate in a hackathon with some friends this past year -- both CS majors -- and excitingly enough, we won.  But I realized as I worked with them that their workflow was very different from mine.  They used Git for version control.  I had never used it at the time, but I've since learned all that I can about it.  They also used a lot of frameworks and libraries.  I had to learn what Rails was pretty much overnight for the hackathon (on the other hand, they didn't know what lexical scoping or closures were).  All of our code worked well, but they didn't understand mine, and I didn't understand theirs.

I hear references to things that real programmers do on a daily basis -- unit testing, code reviews, but I only have the vaguest sense of what these are.  I normally don't have many bugs in my little projects, so I have never needed a bug tracking system or tests for them.

And the last thing is that it takes me a long time to understand other people's code.  Variable naming conventions (that vary with each new language) are difficult (__mzkwpSomRidicAbbrev), and I find the loose coupling difficult.  That's not to say I don't loosely couple things -- I think I'm quite good at it for my own work, but when I download something like the Linux kernel or the Chromium source code to look at it, I spend hours trying to figure out how all of these oddly named directories and files connect.  It's a programming sin to reinvent the wheel, but I often find it's just quicker to write up the functionality myself than to spend hours dissecting some library.

Obviously, people who do this for a living don't have these problems, and I'll need to get to that point myself.

Question: What are some steps that I can take to begin "integrating" with everyone else?

Thanks!

答:
First, congratulations on being the kind of person who seems to genuinely enjoy programming.  However, programming isn't the beginning and end of delivering useful systems.  You are going to have a challenge in front of you and it's going to be up to you whether you go back to hobby programs or go on to a career where you can do what you love and get paid for it.

You are disadvantaged in that you do not have an education in building software.  In that education there are several things taught (not just how to program) that for CS grads and experienced software developers will be second nature.  Not that it comes up often in the work place (although it did for me, once) but NP-hard is an example of a term they may understand and you might not.  You probably lack any background in formal theory behind computation, but that's okay, as long as you're willing to learn about it.  Maybe a master's in CS in your future?  It sounds like some of your code may be idiomatic, in the sense that you have a style of programming that seems clear to you, but not to others.  Pay attention in code reviews and be willing to accept criticism and learn.  This is going to take work, and you may get frustrated, but stick with it.

What you have going for your is priceless.  You genuinely appear to enjoy programming.  I think you'll also enjoy the other aspects of developing systems, such as design, architecture, testing, optimization, etc.  Programming is one part of the puzzle and you will have to learn other skills to be a software developer.  Hackathons aside, a lot of the business involves communication, learning from each other, listening, and planning.  I've worked with many people who are CS grads and liked software development more than selling cars or painting houses, but didn't have a real love for it.

Title: How to become a good team player?


答: If you have a busy home/social life, don't get a laptop.</p>

Title: Company PC refresh, laptop or desktop?


问:
Oracle has some very helpful and free code...I think
I found that some of the code that Oracle uses is very useful so I don't have to re-invent the wheel.

Given this is at the top of the file where the code in question is:

```<code>/*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.  Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
</code>```

If I leave the text intact, put it in my C++ header, and credit oracle for each method, and package the source into a static library...is it still a no-no?

答:
If I leave the text intact, put it in my C++ header, and credit oracle for each method, and package the source into a static library...is it still a no-no?

You definitely need to leave the text intact.

For the rest, it is not possible to say without more specifics.  In particular, what code you are trying to embed, and how you are doing it.  Is it C++ code?  Java code?  A library module or class?  Are you modifying it or including it without modification?  Does the "static library" include other code that is not GPL'ed?

But you certainly can reuse the code if you follow the rules to the letter.