答:
I think what you're suggesting is a variant of a turnkey project.

On the pro side, a turnkey project:

Can make it easier for a customer to get up and running quickly

Shields the customer from all of the necessary configurations

Can lower support costs because a standard image is used for the project

On the down side:

You'll now need to maintain updates to the OS and supporting tools within your master or golden image

You'll always have clients that want distro baz instead of the foo and bar that you already provide

Regarding protecting source code -- If the bulk of your company's intellectual property is encapsulated within the various configuration scripts, then this may be a decent approach to protecting that information.  You would:

copy the scripts on to the system that will be the master image

run the scripts to configure things

remove the scripts from the system

make copies of the master image and distribute.

This is probably only beneficial to you if there are a lot of configuration steps that have to be made.  If it's a trivial number of steps, then diligent customers can figure out exactly what your scripts set up for them.  There decision point for you is if there are enough configuration points so that the resource cost of recreating your scripts outweighs the financial cost of purchasing a system.

If you're hoping that you can provide a system and then keep control of the system account(s), I think you're going to have a harder time.  User privilege escalation exploits occur frequently across all operating systems, especially when someone already has log in access to the system.

In summary, I would only consider providing a turnkey system if you can remove all of the configuration scripts that you are concerned about prior to distribution.

Additional considerations

Any binary files you have would likely be safe from casual investigation.  Based upon the comments, it doesn't sound like you're worried about individuals with debuggers or reverse-engineering tools.

Database schemas will be exposed, and I don't think there's a lot you can do to protect those.  Whether or not the schema is meaningful to someone else is a different matter.  If the schema is large, obfuscation can be surprisingly effective at keeping prying eyes out of a database.

Title: Is virtual machine image a good protection for source code?

Body:
We have developed an application that is sold as an online service. After some time we realized that some of customers would need/prefer/require to have it installed locally on their intranet. However the application was developed using scripting language and we wouldn't want to allow clients to access the source code.

The question is: What are the technical downsides of distributing application as a virtual machine image?


问:
Alternatives to Perl/python scripts for find & replace
I'm working in a fairly old yet sufficiently unproductive code base that I need to create a(some) script(s) to  help me out.

For example:

we add a version # and timestamp at the header of the file (yes we use a CVS based sys but this is beyond my control).

we have duplicated layout code for different languages (this is pre-unicode era so we just duplicate things) and when a control's attribute changes in one language that change needs to be cascade to the other ones.

So, my first thoughts were a couple of perl or python scripts to do find & replace to solve those two issues. But I wanted to reach out and see if anyone else had a different approach.

答:
Adding a # and timestamp at each file header could be easily done by any scripting language with good text processing capabilities, if you are going to use Perl, Python, awk or sed   depends mainly of what you are used to, what you like best, and what is available in the environment your are working. Heck, I have implemented such things also in VBscript (using MS regexp) because I could safely assume that beeing already installed in our Windows environment.

Finding "attributes" in code, however, can work by textual search-and-replace, but there is always some risk that you destroy string literals or comments this way. If you think this is very unlikely in your environment,do it this way. But if you want to avoid that risk, you may have to invest more effort and build (or find) some kind of parser for the programming language your layout code is written in. For HTML, you should consider to use some kind of DOM parser like this one for Perl, or this one for Python.

ContentLicense: CC BY-SA 3.0


问:
Which one of the SOLID principles had the largest effect on your code?
Which if the SOLID principles introduced by "Uncle Bob" Martin had the largest effect on your day to day coding? Please give details!</p>

答:
I would say that the largest benefit I had is from preaching SRP to other developers on my team(s).

God objects and 10KLOC classes are a productivity killer even on a small team.

ContentLicense: CC BY-SA 2.5


问:
Does anyone else feel Scrum isn't agile?
I am a big fan of agile development and used XP on a very successful project a few years ago. I loved everything about it, the iterative development approach, writing code around a test, pair programming, having a customer on site to run things by. It was a highly productive work environment and I never felt like I was under pressure.

However the last few places I have worked use/used Scrum. I know it's the poster child for agile development these days but I'm not 100% convinced it is agile. Below are the two main reasons why it just doesn't feel agile to me.

Project Managers Love It

Project managers, who by their very nature are obsessed with timelines, all seem to love Scrum. In my experience they seem to use the Sprint Backlog as a means to track time requirements and keep a record of how much time was spent on a given task. Instead of using a whiteboard they all use an excel sheet, which each developer is required to fill out, religiously.

In my opinion this is way too much documentation/time tracking for an agile process. Why would I waste time estimating how long a task is going to take me when I can just get on with the task itself. Or similarly why would I waste time documenting how long a task took when I can move onto the next task at hand.

Standup Meetings

The standup meetings in the previous place I worked were a nightmare. Everyday we had to explain what we had done yesterday and what what we were going to do that day. If we went over on our time "estimate" for a task the project manager would kick up a stink, and reference the Sprint Backlog as a means of showing of incompetent you are for not adhering to the timeline.

Now I understand the need for communication but surely the tone of daily meetings should be lighthearted and focus on knowledge sharing. I don't think it should turn into a where's your homework style charade. Also surely the hole point of agile is that timelines change, they shouldn't be set in stone.

Conclusion

The idea of agile is to make the software better by making the developers life easier. Therefore in my opinion any agile process used by a team should be developer led. I don't think having a project manager use a process they have labeled "agile" to track a project has anything to do with agile development.

Thoughts anyone?

答:
scrum is a project management methodology

agile is a software development methodology(-ish)

scrum+agile works very well

scrum without agile...not so much


问:
Using jTransforms for a commercial (non-free) android application?
I am developing an application which is using JTransforms to compute FFT and InverseFFT.

I am planning to sell that application on Play Store.

The JTransforms Library is covered under MPL/LGPL/GPL tri-license.

Does that mean I have to disclose my application's source code to the community ?
Does that mean I cannot use an open-source library to sell non-free application ?

I found the following link in which the ScissDSP library is using JTransforms under LGPL license :

https://github.com/Sciss/ScissDSP/blob/master/licenses/JTransforms-License.txt

Does that mean MPL/LGPL/GPL is sort-of Pick 'n' Choose type of License ?

答:
Wikipedia Multi-license description says:

When software is multi-licensed, recipients can choose which terms under which they want to use or distribute the software. The distributor may or may not apply a fee to either option.

From my personal grasp on the subject (IANAL and I am very new to licensing):

I would use the library under the terms & conditions of the MPL license:

MPL is least restrictive; you can have static (and dynamic) linkage of the used library in your app you charge money for without having to disclose the source of your app. Static linkage means you can import the library however you please (you can import the library as a jar file; you can even copy & paste the java source files directly into your project). Dynamic linkage means you link to a jar-packed version of the library and users of your app must be able to replace that jar.

As long as you do not modify the source code of the (static/dynamic) linked library, you do not have to disclose source code (extending classes, interfaces or calling methods/constructors of the library are not modifications).

However, if you do modify the source code of the linked library, you should make the modified source code publically available under the same license. You do not have to disclose your full app's source code. Instead, you modify the library as you please, host a public version of it and import the modified library in your app. Notice how your modified library is actually a new MPL licensed library on its own.

I would just host a fork on github of the modified library and add a NOTICE file to the root of the project, acknowledging that this fork is a modified version of the library in question. It is even better if you submit a pull request containing your modifications against the original library: if the PR gets merged, you can now import the new version of the original library containing your modifications, delete your fork and the general public will benefit from your modifications in the future.

I would not use the library under the terms & conditions of the LGPL or GPL license:

LGPL is about dynamic linkage and the ability to replace the used library with another version. Considering that you will pack your app into one .apk file, how will the users be able to replace JTranforms?

GPL does not allow you to release your software under a proprietary license. You can charge money for it, but the app has to be GPL licensed and the full source code must be made publically available.

Conclusion:

Assuming you call JTrasnforms without modifying it, you could use JTransforms without worries; include an about page in your app where you acknowledge that you use JTransforms under the MPL conditions (include links to the original JTransforms copyright & license). That's it.

I am not 100% certain if my statements are correct: I would definitely contact the authors of JTransform directly and ask them if you can do this.


问:
Need an OOP pattern or strategy for "pluggable" property
I'm using OOP and MVVM in a WPF c# application. The goal is for the resulting object (data-bound to user interface) to accurately represent a product. One specific area of the product is highly configurable. For conceptual purposes, imagine a boat which can have various means of propulsion. A submerged prop motor or above water fan motor may be attached at the stern, and they would have very different properties.

At the model level, I could have an interface typed property for this PropulsionDevice, with the interface defining all the required information I need for pricing and weighting the finished product. How to assign this property based on user input is where I am unsure what to do. Creating an enumeration with an item for each class implementing my interface, and presenting it in a ComboBox seems clunky and naive (the disconnect between the enum item and the class seems wrong). But, I'm not sure if meta-programming with Custom Attributes or using Reflection would be a better option. Maybe there is another option?

Any suggestions on how to allow for flexibility in my c# classes, as well as how to present this in the UI?

答: I see no problem in using reflection to find each class that implements the desired interface and presenting it in a ComboBox. You could even use IoC to do this, so you don't have to worry about it yourself.


问:
Why should I use Bower?
I can fully appreciate the benefits of a package manager like Python's pip, Node's npm, or Ruby Gems since they're doing much more than adding files to your applications path.

Maybe I'm missing the point, or I'm being obtuse, but here are the negatives I can see:

Separate step when building a project

Separate dependency to install via another package manager (yo dawg)

More clutter in the projects root with bower.json and / or .bowerrc

Reliance on the registry being up to date, correct, and available

Some imports / references to things like images won't work

Huge overlap with npm, and often unclear which resource to use, when

The positives I can see are these:

I don't have to download the dependencies manually

Optionally install packages as part of scaffolding based on user prompts or the like

I'd really like to know of any benefits I'm unaware of, and I should say I'm not trying to be provocative I genuinely want to know.

答:
From the README:

Bower is a package manager for the web. It offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. There are no system wide dependencies, no dependencies are shared between different apps, and the dependency tree is flat.

Bower runs over Git, and is package-agnostic. A packaged component can be made up of any type of asset, and use any type of transport (e.g., AMD, CommonJS, etc.).

Bower has many of the benefits of other dependency managers. I'm sure there are others, but the benefits I've noticed so far include:

Simplify what might be called declarative dependency management; i.e. you declare your dependencies in bower.json so that other things can determine them easily

No need to commit dependencies to version control

Semantic versioning is used to help define a range of acceptable versions for a dependency, which makes it easy to update to newer versions within the defined range

No need to locate various builds (debug, minified, etc)

Simple to use different builds of a dependency for dev vs. prod

You can distribute the bower.json file and everyone can get up to speed with a simple "bower install"

Title: Why should I use Bower?


问:
How should I validate code when there is no one to do code review?
I'm used to working in a large development environment where code is peer reviewed and tested by the client, who is usually an IT person themselves. I am now working at a very small company where I'm not just the only developer, but the only IT person at all.

I'm inclined to have my coworkers and/or boss take a look at my work every time I finish a agile story, so they can either accept it or reject it, as is the pattern I'm used to. However, too often my coworkers either don't understand my work well enough to judge it or they misunderstand it and accept bad code or reject good code based on surface looks alone, like the color of links.

So I'm wondering how I should decide when to accept/reject tests now? Should I try to assess my own code like an outside person? Should I just skip it and accept everything? Should I try to educate my coworkers a bit and get them to do proper tests?

答:
User stories should be written in conjunction with the customer.

Are you the customer?

If so, then accept your own stories. If not, schedule review/writing time with the customer.


问:
Over thinking development
I've been working as an app developer for a year and a half now (not long I know), and I've just been given my first big project.

Needless to say it didn't go very smoothly, so I sought advice from a senior programmer involved in the project about how to approach it.

He said that I had drastically been over thinking the task at hand, and that because I had never tackled a project of this scale before I'd been spending too much time over thinking design patterns. In his wise words, he told me "F*ck the future, build for now".

Is this a trend programmers typically follow when going about a project like this? For example, if you were asked to do a proof of concept model, is it a typical trend just to mash a workable example out as soon as possible?

Edit: In light of the debate this has sparked, I'd like to mention that this situation is fairly extreme: we have very tight deadlines due to factors beyond our control (i.e. the market we're aiming for will lose interest if we don't show them something) and his advice proved to be very effective for this particular task.

答:
There are a few good reasons to listen to advice to stop planning and start coding;

After only 18 months as a developer, it is unlikely that you can anticipate the future well enough to plan for it, no matter your college GPA. This is something that is extremely difficult for bright but inexperienced developers to grasp, since it's all about not knowing what you don't know. Old hands may have recognized this weakness in your vision, and wisely encouraged you to just get into it and do your best.

Young developers may become obsessed with perfecting the design before they begin coding. They may be covering a fear of writing the code (performance anxiety), or may have coder's block (like writers block). They dally in design because there is no required work output. The young dev will probably respond angrily to the suggestion that they are "afraid" of anything. Maybe at the end of the project they'll realize that they were. The advice to just don't worry and get coding constitutes the only known cure for coder's block. An old hand may wisely offer this advice.

In the presence of harsh schedule constraints, your chances of getting the project done at all are limited. Plan too long, and no matter how good the plan is, you can't execute it in time, and you never get to market. Start hacking away from the start, and maybe you'll get lucky and be right the first time. You deliver the product miraculously. Or, maybe you're not so lucky, and deliver a half-baked piece of slag but it gets into the market on time and you learn something. Or maybe you fail. But "maybe you fail" is still better odds than "never got to market" because you planned too long. The key understanding is that your chances are limited from the start, so you lose nothing by hacking. Your manager may know there's little chance of success, and assigned a junior resource just as a learning exercise. We learn better from failure than from success. Have you perhaps been asking, "When can I have a whole project?"

It takes a pretty introspective and ego-free developer to see their own imperfections, so meditate awhile before reading the rest of this, lest you give yourself excuses to overlook your own weaknesses...

Not every developer is particularly good at analysis, planning, and other tasks that require thought. Thought is hard and icky. It requires a kind of mental sweat that leaves you uncomfortable and wrung out after a days work. It's just not as fun as getting into flow-state with your two cans of Monster and your rock turned up loud and coding, coding, coding. Developers who don't like to think will resist the notion that planning is a good idea. They recommend dev methodologies that don't require up-front planning. They like companies and managers that don't emphasize planning. They gravitate to jobs where the cost of not planning is not too high. They value all night coding sessions and getting that hotfix out to customers whose whole business is down because of a bug. (And never mind that delivering broken code to a customer ought to be a capital crime).

Certain developers have even realized that getting something working well enough to demo means that making it work completely and under all circumstances can be deferred, and maybe even pushed off onto another developer, while they receive kudos for "getting the job done" initially.

There are managers who cannot themselves spot a trend until it is already breaking on facebook. Instead of finding a job managing a discount tire store, these managers make it your problem that they need the code running by Friday. They don't want to hear that you need to design the API or test whether your algorithm is scalable. This is just tech mumbo-jumbo to them. They will encourage you to code because it's all they understood about software back when they were writing perl scripts to help customers transfer their files. (They had the title 'software engineer' in their first sales job. Who knew software was going to be so boring and hard?)

Title: Over thinking development


问:
Programming PHP without MVC, classes or framework: rewrite or continue on new features?
I have been programming for several years now, and back then (learning PHP) I've didn't learn to program using classes, MVC-logic or using any frameworks. I found my self solving my problems very well using my own functions.

Eight months ago I was recruited to a start-up, to develop a huge social platform. I have been working there for several months now, and built up a huge website with various complicated features (+35k lines of code I guess), and I could see my self continue like this. Everything is coded without any framework, no classes or with MVC-logic, since I didn't have the time to learn it (we had to move fast).

I do write everything in functions, and put a lot of effort in well documenting/describing my code as well as organizing it beautifully and easy-to-read.

However, it is top of my list to learn Classes > MVC > Laravel (or any other) framework. But I just can't see my self stopping now, learning above list, and then rewrite all code. This would simply push us back in time, and in the start-up we're moving fast and have many deadlines for new features/ideas/development.

I've spoken with many people regarding this, and people say a lot of different things. Some say it's a matter of taste, and you'll be able to move on with it. Others say it's incredibly stupid, you're not scaleable, you're never get serious funding, you're the only one who ever be able to work on the project, you should stop and start learning it now, etc.

Am I doomed? I feel lost. My personal opinion on this is, that even though it is a huge system already, it is still a MVP and I guess at some point in the future we would rewrite the code anyways. This is, if we're at such a successful stage in our venture and growing very fast / getting funding / etc.

答:
This project in particular might be a tad too large to be completely rewritten, but consider it a lesson.

MVC frameworks have many purposes:

They handle a lot of the boilerplate (routing, templating etc)

They decouple the various steps between the request and the response, allowing you to inject all kinds of functionnality very easily.

They separate different concerns: views are separate from the model and the business logic, so you can completely redesign the site without coding skills.

This can be achieved without a framework, but there is no point in doing so. They usually save you a lot of time and effor, and you should absolutely consider them for your next project.

If your current project is maintainable, then you should not waste so much resources rewriting it and instead consider slowly migrating things as you touch them. Is it worth the investment? Only you know.


答:
It's probably a little too late to move wholesale to a MVC framework.  Particularly if you are still trying to get the project online.

What I would recommend you do is focus on learning OOP, and then starting to migrate your existing functionality into a class structure.  Then, if you do decide down the road to migrate to a 3rd party framework, you should be able to reuse a lot of the code.

Title: Programming PHP without MVC, classes or framework: rewrite or continue on new features?

Body:
I have been programming for several years now, and back then (learning PHP) I've didn't learn to program using classes, MVC-logic or using any frameworks. I found my self solving my problems very well using my own functions.

Eight months ago I was recruited to a start-up, to develop a huge social platform. I have been working there for several months now, and built up a huge website with various complicated features (+35k lines of code I guess), and I could see my self continue like this. Everything is coded without any framework, no classes or with MVC-logic, since I didn't have the time to learn it (we had to move fast).

I do write everything in functions, and put a lot of effort in well documenting/describing my code as well as organizing it beautifully and easy-to-read.

However, it is top of my list to learn Classes > MVC > Laravel (or any other) framework. But I just can't see my self stopping now, learning above list, and then rewrite all code. This would simply push us back in time, and in the start-up we're moving fast and have many deadlines for new features/ideas/development.

I've spoken with many people regarding this, and people say a lot of different things. Some say it's a matter of taste, and you'll be able to move on with it. Others say it's incredibly stupid, you're not scaleable, you're never get serious funding, you're the only one who ever be able to work on the project, you should stop and start learning it now, etc.

Am I doomed? I feel lost. My personal opinion on this is, that even though it is a huge system already, it is still a MVP and I guess at some point in the future we would rewrite the code anyways. This is, if we're at such a successful stage in our venture and growing very fast / getting funding / etc.


问:
In PHP, should I delete objects immediately after use?
I've read in PHP Advanced and Object Oriented Programming by Larry Ullman that it is good programming practice to delete object immediately after use but reason is given nowhere.

I am a student web developer and objects in web applications are deleted automatically as soon as the script finishes. So, there seems no good reason to delete them manually.

So, my question is what are the good reasons to delete unnecessary objects after use other that blindly following a convention?

答:
No, you do not need to delete an object after its use in PHP.  Let PHP's garbage collection take care of it for you.

There may be some obscure performance reasons to unset an object after you are done with it in very specific situations.  But such cases are not everyday events, and they will be clear when you see them.


答:
Learning OOP is definitely worth it. Passionate hireable developers are always willing to learn to expand their knowledge, specially when you can save time in the long run. I would agree more with the second group of people:

Others say it's incredibly stupid, you're not scaleable, you're never
  get serious funding, you're the only one who ever be able to work on
  the project, you should stop and start learning it now, etc.

That's a bit harsh, but the reality is, the more you know, the more you scale. Serious funding is often surrounded by hype, and procedural code is unfortunately not cool enough. OOP and frameworks are.

Am I doomed? I feel lost. My personal opinion on this is, that even
  though it is a huge system already, it is still a MVP and I guess at
  some point in the future we would rewrite the code anyways [...]

Large procedural code bases are not uncommon, see WordPress. OOP really helps to abstract and organize your code without relying on procedural conventions (although MVC frameworks have a whole different set of conventions). WordPress started a migration process, that's still going on today. With such large projects all you can do is upgrade your system, step by step, testing that nothing breaks, and keep re-factoring, forever, as you'd introduce new features that will need refactoring later on.

But no, you're not doomed, just a little bit late to the whole process. Learn what you can when you can; less is better than nothing. The learning curve when learning new programming paradigms, or languages, is often steep at first, but after that first hiccup it'll be smooth sailing, and you'll start to really appreciate the difference it can make on your code, and the difference it will make when others read your code.

Edit: Just to clarify, I'm not suggesting the current system needs to be OOP, or that it needs to be built from scratch. Any system is going to be re-factored, at some point, and you may need to break compatibility with previous system, and that's fine if the project requires it; you can have a deprecation cycle as well. What I'm suggesting is to slowly introduce OOP as you refactor your current code, namespaces, etc.


答:
(Moved from Stack Overflow following question closure).

I think it depends. If the code is modular already, and markup/logic is well separated, it may be better not to port to a completely different system. You need to consider the impact on the existing business, and whether taking devs off new feature projects is worth it in your case.

A better way to do it may be to find a bolt-on library that separates logic from code, and use that initially just for your new code. Then, as you find time, start porting your old screens to it, and get each one live as you finish it. The result then is that you iteratively improve, rather than trying to do it in a "big bang", and thus is less risky.

I work on a large PHP system where it has been quite hard to make a business card to move to any decent MVC-like system. We'd like to, but it would be 6-12 months of development work, and although I tend to personally view the cost/benefit favourably, the client does not, and of course it's clients/managers that make these decisions!

The solution in my case has been to write a trivially simple object-based controller system, which we tend to use for new development going forward. It's not as nice as Symfony2 or Laravel, but it's a significant step towards modularity and maintainability, and is good enough.

That all said, if you're not using objects at all, I'd say that was quite unusual. They are a very natural and useful mechanism to organise your application, and would suggest that this should be your first port of call when deciding how to improve your codebase.


答:
If you are developing an online system for your company, that would imply that somebody besides you must have an idea of how it supposed to work at least at the UI level.  So that would be the level at which your work can be reviewed by others within the company.

Unfortunately, that means that there is nobody to review your code. One possibility is that you can review your own code. It may be helpful to go back and look at your code a week or so after you finish it, and see if you can still understand it. Alternatively, you can try to get your company to hire another developer.

Title: How should I validate code when there is no one to do code review?

Body:
I'm used to working in a large development environment where code is peer reviewed and tested by the client, who is usually an IT person themselves. I am now working at a very small company where I'm not just the only developer, but the only IT person at all.

I'm inclined to have my coworkers and/or boss take a look at my work every time I finish a agile story, so they can either accept it or reject it, as is the pattern I'm used to. However, too often my coworkers either don't understand my work well enough to judge it or they misunderstand it and accept bad code or reject good code based on surface looks alone, like the color of links.

So I'm wondering how I should decide when to accept/reject tests now? Should I try to assess my own code like an outside person? Should I just skip it and accept everything? Should I try to educate my coworkers a bit and get them to do proper tests?


答:
Welcome to the world of micro-management.

The place where the boss lose money, and the technicians made coffee for others

Most of the agile development techniques that you have learned up to now, in this moment become non-applicable. The main problem is that in the absence of a development team, what remains is perhaps "extreme programming". My advice is to make it clear to the company (no matter the size of this one), this situation is sustainable only if the software is developed to an amateur level. This has nothing to do with your role, you can continue to develop by applying all the techniques you know, but only at the level of software design and development. Continue, perhaps, to develop using TDD, drawing use cases in UML, etc.. But a product, it needs more members to be developed, debugged, tuned, deployed, advertised...

Do not forget that the development of a product, must pass through a strong criticism, survive this, and then have its path of continuous integration. as programmers, we do not digest well the criticism of others and we often need a brilliant idea from others, BUT when they are not there, we become omnipotent and all the errors becomes ours.

I believe that the boss (as defined), has a rejection to the explanation of a technical, these normally lead to the need to spend money, and in a company where there is not a defined budget for the technical department, this can generate conflicts between administrators and technical.

My advice is to invest in training managers, without giving much explanation and even in small projects, organize your work ready to welcome new members in the development team.

Some tips

Always use repositories, maybe a nice project on github, with your code organized as Super Project

Spend your time in at least define what are the milestones of the requests that are made to you;

Organize your milestone in simple online spreadsheets, now you do not need great project managers, Gantt diagrams, resource control, money flows, etc.

Always communicate the progress of your work via e-mail, and attach the status of your milestone in PDF;

I think the method that you choose today, must show what you do, and how much time do you spend on.

last consideration

if you show to a Boss, 10 milestone, 3 of these were writing code, and the other divided between, debug, design, install, test, at that moment you have a great tool for dialogue with the administration...

at that time, you speak their language.


问:
When do rounding problems become a real problem? Is the least significant digit being one off really a big deal?
If I do .1 + .1 + .1 in Python, I get 0.30000000000000004. (I am not asking about Python in particular, and do not want Python specific answers.)

The only problem I can see with this is 0.30000000000000004 != 0.3, so I need to take care in how I compare floats. Are there any other problems I need to be aware of with float rounding?

I can't imagine that last digit being much of a problem in real life. For example, if I ask for a "0.30000000000000004 meter metal rod", I'm not going to later complain that "this rod is 0.00000000000000004 meters too long!" (I can just cut the extra off, right? :)

Even with a lot of float calculations going on, I can't imagine the rounding getting so far off that it matters. Am I missing something? When do floating point rounding errors really matter?

答:
Even with a lot of float calculations going on, I can't imagine the rounding getting so far off that it matters. Am I missing something? When do floating point rounding errors really matter?

The biggest problems arise with addition and subtraction. Given two numbers that are very close to one another in terms of magnitude, the difference or sum can lose precision (sometimes a lot), depending on whether they have the same or opposite signs. Given two numbers that are very far from one another in terms of magnitude, the smaller term can vanish into the bit noise.

This wreaks havoc with numerical techniques for solving initial value problems (aka numerical integration). Use a lousy technique such as Euler's method and those double precision truncation errors mean the best you can do is a relative error of 10-8 to 10-6 -- and that's only if the interval of interest is small. Use a very good technique and you are lucky if see a relative error of 10-14 to 10-12, and once again that's only if the interval of interest is small. Propagate the planets for millions of years and all bets are off, even with the very best of techniques. You need to use quad precision for those very long intervals of interest.


答:
Variances in the "least significant digit" can cause the entire number to be rounded in the wrong direction.

Lets take an item that costs $0.705 - the half cent is from discount, or tax or something, or this is a 10% discount on something that is $7.05.  Whatever the case... three of them and we're computing the price (or discount).  The total price is $2.115 and you need to round it appropriately to $2.12 (half up).

public class Round {
    public static void main(String[] args) {
        double item = 0.705;
        double subtotal = item * 3;
        System.out.println(subtotal);
        double rounded = Math.round(subtotal * 100.0)/100.0;
        System.out.println(rounded);

        subtotal = 2.115;   // what the subtotal *should* be
        rounded = Math.round(subtotal * 100.0)/100.0;
        System.out.println(rounded);
    }
}
```

<p>However, the output of this program is:</p>

```
2.1149999999999998
2.11
2.12
```

And there, we're off by a penny because of something that happened in the least significant digit of a floating point calculation.

Having previously worked on point of sales code that frighteningly had doubles scattered through them (I spent months converting them to an arbitrary fixed point system - I'm confident that I fixed that problem - at least in all the code I was looking at...), I can assure you that they are a real problem and the least significant digit being off by one is a big deal.

At first, this will be a "oh, its only a penny" but in this software, its about money... and people get very touchy about money being off.  There are two parts to that - first is the confidence that the customer has when they see $0.705 * 3 = $2.11 when they know it should be $2.12.  The other part is that money adds up and over the course of days or weeks or months, it adds up to possibly sizable amounts when it isn't being calculated properly.  This often happens in tax calculations (thats an easy way to get awkward fractions) and the agencies that collect said taxes are much less sympathetic than the customer who is off by a cent... and can do nasty things like audits.

Title: When do rounding problems become a real problem? Is the least significant digit being one off really a big deal?

Body:
If I do .1 + .1 + .1 in Python, I get 0.30000000000000004. (I am not asking about Python in particular, and do not want Python specific answers.)

The only problem I can see with this is 0.30000000000000004 != 0.3, so I need to take care in how I compare floats. Are there any other problems I need to be aware of with float rounding?

I can't imagine that last digit being much of a problem in real life. For example, if I ask for a "0.30000000000000004 meter metal rod", I'm not going to later complain that "this rod is 0.00000000000000004 meters too long!" (I can just cut the extra off, right? :)

Even with a lot of float calculations going on, I can't imagine the rounding getting so far off that it matters. Am I missing something? When do floating point rounding errors really matter?

Body:
Variances in the "least significant digit" can cause the entire number to be rounded in the wrong direction.

Lets take an item that costs $0.705 - the half cent is from discount, or tax or something, or this is a 10% discount on something that is $7.05.  Whatever the case... three of them and we're computing the price (or discount).  The total price is $2.115 and you need to round it appropriately to $2.12 (half up).

public class Round {
    public static void main(String[] args) {
        double item = 0.705;
        double subtotal = item * 3;
        System.out.println(subtotal);
        double rounded = Math.round(subtotal * 100.0)/100.0;
        System.out.println(rounded);

        subtotal = 2.115;   // what the subtotal *should* be
        rounded = Math.round(subtotal * 100.0)/100.0;
        System.out.println(rounded);
    }
}

However, the output of this program is:

2.1149999999999998
2.11
2.12

And there, we're off by a penny because of something that happened in the least significant digit of a floating point calculation.

Having previously worked on point of sales code that frighteningly had doubles scattered through them (I spent months converting them to an arbitrary fixed point system - I'm confident that I fixed that problem - at least in all the code I was looking at...), I can assure you that they are a real problem and the least significant digit being off by one is a big deal.

At first, this will be a "oh, its only a penny" but in this software, its about money... and people get very touchy about money being off.  There are two parts to that - first is the confidence that the customer has when they see $0.705 * 3 = $2.11 when they know it should be $2.12.  The other part is that money adds up and over the course of days or weeks or months, it adds up to possibly sizable amounts when it isn't being calculated properly.  This often happens in tax calculations (thats an easy way to get awkward fractions) and the agencies that collect said taxes are much less sympathetic than the customer who is off by a cent... and can do nasty things like audits.


答:
When you are dealing with things that are measured (speed, distance, weight etc.) rounding is OK as the accuracy of the original measurement is probably less than the accuracy of you calculation, and, users accept that the final number is still an estimate even if its a good estimate.

When you are dealing with things that are counted (money, people , ICBMs) rounding errors are a disaster. There is always an arithmetically correct answer, and, often the accuracy of this answer is enshrined in regulation, treaties and tax law. Providing a slightly wrong number gets you a free ticket into the Kafkaesque world of auditors, tax collectors and government inspectors; you may never escape with you sanity intact.


问:
How to name arrays or list when the nouns are both singular and plural?
Generally variables are named in the singular Car car; and arrays and list with the pluras: List<Car> cars; or Car[] cars; But what about nouns like fish or media* that are already plural?

*already lost the battle to have the class called Medium.

答:
I think names like List<Fish> fish are perfectly fine. We use "fish" as both singular an plural in writing; why not do the same in code?

If you want a singular Fish fish in the same scope, say for iterating, can always switch to List<Fish> fishList or List<Fish> listOfFish.


问:
Question about moving to embedded systems
I currently work as a .net developer and have coming up to 3 years experience in the industry as well as a degree in computer science specifically software engineering (I know that means nothing but just wanted to explain that I'm not your general back bedroom programmer).

When I finished Uni, I started contracting for a company. I wont mention their name but some of you may have heard of them just by the description. Basically they take in fresh graduates and in return for training and contracting experience you have to go to the clients they say for a minimum of two years. I cant say this was great but I do feel I know more than people with the same years of experience as me.

The problem is that I've now started heading down the route of web development because of the lack of choice in clients.

How difficult is it to change from a .net field to embedded/low level programming? I have the enthusiasm for it and the strive but I'm not quite sure how to go about moving. Unlike application development, knowing the language and having some business etiquette doesn't seem to be enough.

For example hardware wise I can set-up a computer but wouldn't know how to manually attached wires and program these systems. Is this kind of knowledge necessary?

Thank you in advance. Also if anyone has similar experience of swapping, should I?

tl;dr

Developer that doesn't know how to get from web development roles into embedded systems.

Edit::
Thank you all for the advice.

答:
Get a simulator, they are free, qemu, dosbox, among others (I would recommend non-x86, but whatever, in no way does it have to match the platform you are on or hardware you own).  Gazillions of examples out there, just go learn, all free tools, all free software, you just have to put in the time.

When you are ready you can then buy the hardware, wire it up (which at first means just plug it in, usb, etc) and have at it, blink some leds, whatever.  Same deal, zillions of platforms out there, ready to just plug in, sandboxes to play in so you dont get hurt, and then when the time is ready, climb out of the sand box and give it a try.  if you take the simulator path first then that step should be a lot easier and with more confidence.

there are embedded .net systems so you could just transition over, but I would recommend learning C and a little assembly, those remain the foundation of embedded and will give you the most choices as you hop around platforms and learn.


问:
Summary of C# naming conventions (official Microsoft conventions)
I am struggling with naming convetions in C# I do not know when to use PascalCase or camelCase. I have read Microsoft's naming convention, but I got lost ther http://msdn.microsoft.com/en-us/library/ms229045(v=vs.110).aspx

As far as I know this is correct:

```<code>public int Number;
private int number;
public void Method();
private void method();
int number;//for any local variable
</code>```

But in context of that above how should I name components in XAML: x:Name="Button" or x:Name="button". They seems to be private field so I should use camelCase, but on the other hand everywhere on the examples I see PascalCase for x:Name

I do not ask about one's habits, but orthodoxic/official/C# guru style.

答:
I read the MS standards, a long time ago. All I remember and use is:

UpperCamelCase for public methods and properties

lowerCamelCase for protected/private methods and properties, also parameters

At the time, there was no XAML, but I don't expect precise consistency across languages.

In the end, no one's standards matter but your own. Or your team's. Or your boss's. But mostly your own.


问:
Is it good or bad practice to provide separate classes for an object: one to build it, and one to use it?
Suppose I'm writing some C++ code to visualize "Foo" objects. I have two ways of getting a "Foo": computing it from data, or from taking the pieces of a precomputed "Foo" and building a new "Foo".

Now, once a "Foo" is computed it's guaranteed to be good for visualization, but changing it may break this assumption. Therefore, I've decided to represent "Foos" in my code by a Foo class that has no mutating methods: once it is constructed and initialized, it doesn't change.

But there's a second way to make a "Foo": build it from a precomputed "Foo"'s components. I've come up with several methods of building a Foo from precomputed data:

Method 1: Constructor/Static methods

Perhaps the most obvious method would be to add a new constructor or a static method to Foo, call itfromPrecomputed, that would read the components of the precomputed Foo and make a new Foo object, checking that it is valid. To explain why I'd like to shy away from this, I have to complicate my example: Let's say that one component of a "Foo" is a collection of "Bars". Now, in terms of implementation, sometimes a "Bar" is represented as a std::vector<std::vector<Bar> >, sometimes as a Bar array[][2], sometimes as a std::vector<std::pair<Bar,Bar> >, and so on... I could have the user reorganize their data into a standardized form and have a single constructor for this standard, but this might require the user to perform an extra copy. I don't want to provide a static method for each format: readPrecomputedFormatA, readPrecomputedFormatB, and so on: this clutters the API.

Method 2: Make Foo mutable

If I exposed the addBar(Bar) method of Foo, then I could allow the user to iterate over their collection of "Bars" in their own way. This, however, makes Foo mutable. So I could compute a Foo that makes sense for visualization, then use addBar to add a Bar that makes the Foo no longer a "Foo". Not good.

Method 3: Make a friend "builder" class

I make a class called FooBuilder which has the addBar(Bar) method exposed. I make FooBuilder a friend of Foo and add a constructor to Foo that takes a FooBuilder. On calling this constructor, it checks to make sure that FooBuilder contains a valid "Foo" object, then swaps its empty representation of a Foo with what is inside the FooBuilder. Everybody is happy.

The only "messiness" about method #3 is that it requires a friendship, but it's worth it to maintain encapsulation I think. But this has got me thinking: is this an established pattern? Or is there another, better way of doing this that I don't know about?

答:
What you consider FooBuilder and Foo is actually part of a well-established Builder pattern.  The other approach you mention with creating a Foo instance based on an existing instance is called a Prototype pattern.  Both of these are well-known object creation alternatives and several books (most notably "Design Patterns", aka GoF) have been written describing them.  (not sure I'm clear on your second mutable example, so comparing #1 to #3 here)

Each pattern obviously has its own advantages and drawbacks and only you can decide which one is better for your specific situation. For example, I would typically use builders when there's a lot of different ways of initializing Foo.  For example, right now I'm working on a query builder class and many clients use it differently to build query objects. Different clients want different fields to be returned, some clients want only last 10 rows, some want sorting while others don't.  Builder is perfect as it can look something like this:

```<code>qb = QueryBuilder()
query = qb.fields("name", "address")
          .sort("zip", "asc")
          .limit(10)
          .build()
</code>```

So multiple setters, each returning instance of the builder itself so you can daisy-chain basically serve as a very flexible constructor.  Making one class a friend of another class has it's time and a place and potentially this could be one of those places.

Alternatively, you could define Foo as having one constructor that takes a rather complex set of params, or potentially you could define another class FooData, that FooBuilder could initialize and pass into Foo creation.  Then again, maybe Foo and FooBuilder being friends in this case isn't such a bad thing. Just keep in mind that when one class is a friend of another one, you are expanding encapsulation boundary, which could be just as bad as putting more and more code all within one class (i.e. more code knows about internals)

At the end of the day, you could be thinking and considering all these different options and it will all boil down to 60/40. If there's no clear winner, you can always let a coin pick the winner and just go with it.  Most likely either one of the design choices would work just fine and by going through the motions and seeing your code in action you will learn valuable lesson for future.  Sometimes when I have design decisions and can't decide between A and B, I could end up picking B and then if I ever come across a similar situation I would intentionally pick the other choice.  The work in either case gets done and I get the software to do what I want, but you get a ton of benefit of actually seeing your decisions in action and being able to compare the two working approaches, rather than just discussing and thinking about them.

Body:
What you consider FooBuilder and Foo is actually part of a well-established Builder pattern.  The other approach you mention with creating a Foo instance based on an existing instance is called a Prototype pattern.  Both of these are well-known object creation alternatives and several books (most notably "Design Patterns", aka GoF) have been written describing them.  (not sure I'm clear on your second mutable example, so comparing #1 to #3 here)

Each pattern obviously has its own advantages and drawbacks and only you can decide which one is better for your specific situation. For example, I would typically use builders when there's a lot of different ways of initializing Foo.  For example, right now I'm working on a query builder class and many clients use it differently to build query objects. Different clients want different fields to be returned, some clients want only last 10 rows, some want sorting while others don't.  Builder is perfect as it can look something like this:

qb = QueryBuilder()
query = qb.fields("name", "address")
          .sort("zip", "asc")
          .limit(10)
          .build()

So multiple setters, each returning instance of the builder itself so you can daisy-chain basically serve as a very flexible constructor.  Making one class a friend of another class has it's time and a place and potentially this could be one of those places.

Alternatively, you could define Foo as having one constructor that takes a rather complex set of params, or potentially you could define another class FooData, that FooBuilder could initialize and pass into Foo creation.  Then again, maybe Foo and FooBuilder being friends in this case isn't such a bad thing. Just keep in mind that when one class is a friend of another one, you are expanding encapsulation boundary, which could be just as bad as putting more and more code all within one class (i.e. more code knows about internals)

At the end of the day, you could be thinking and considering all these different options and it will all boil down to 60/40. If there's no clear winner, you can always let a coin pick the winner and just go with it.  Most likely either one of the design choices would work just fine and by going through the motions and seeing your code in action you will learn valuable lesson for future.  Sometimes when I have design decisions and can't decide between A and B, I could end up picking B and then if I ever come across a similar situation I would intentionally pick the other choice.  The work in either case gets done and I get the software to do what I want, but you get a ton of benefit of actually seeing your decisions in action and being able to compare the two working approaches, rather than just discussing and thinking about them.


问:
Difference between the two enums
I came across an enum definition :-

```<code>typedef enum NSInteger {
    kBorderTypeNone   = 0,
    kBorderTypeLeft   = 1 << 0,
    kBorderTypeRight  = 1 << 1,
    kBorderTypeTop    = 1 << 2,
    kBorderTypeBottom = 1 << 3
} BorderType;
</code>```

and also (possibly) it can be equivalent to

```<code>typedef enum NSInteger {
    kBorderTypeNone   = 0,
    kBorderTypeLeft   = 1 ,
    kBorderTypeRight  = 2,
    kBorderTypeTop    = 4,
    kBorderTypeBottom = 8
} BorderType;
</code>```

What are the internal differences(if any)? Is there any advantage of one over the other? Which one is recommended?

If both are same then how compiler handles it? In which phase of compiler is it reduced to same set of instructions?

答:
These are both identical and different purely in programmer's style.  If you are looking at compiled code, it'll be byte-by-byte the same.

Not sure how much compiler theory you are looking to get into, but at a very simple level compilers generally have two phases:

tokenize the file and builds a parse tree

convert parse tree into lower level instructions

The simplification could theorically occur at either one of the stages.  When parse tree is assembled, if objects are detected to be [const] [op] [const], at that point the compiler has enough information to simply create one constant that represents the result of the operation.  Or I guess it could blindly put the operation as part of the parse tree and let second step do simplification.

I've had the pleasure of writing a simple compiler as part of a Computer Science degree (that was a long time ago, but I'd like to think I remember something from college) and in my case, I found it simpler to do simplification on the spot (i.e. first step) and put the resulting constant as part of the parse tree.  That way various places could deal with this constant uniformly (i.e. if-statement vs. switch statements vs. while loops).  By the time you have to act on what each language construct has to do, all those various places wouldn't have to worry about performing the "1 << 3" calculation because by that point it would already be a simple integer.

Title: Difference between the two enums


答:
They will be compiled to same code and the only difference is readability. All modern compiler should be able to deduce the value of a constant expression and compute them at compile time.

It is very clear to me that first enum is used as flag. e.g. type = kBorderTypeLeft|kBorderTypeRight

But not clear for second version of enum. Also if you have many types, it can be hard to get the right value for every enum and some people may think the value is kind of "magic number".

Title: Difference between the two enums

Body:
I came across an enum definition :-

```<code>typedef enum NSInteger {
    kBorderTypeNone   = 0,
    kBorderTypeLeft   = 1 << 0,
    kBorderTypeRight  = 1 << 1,
    kBorderTypeTop    = 1 << 2,
    kBorderTypeBottom = 1 << 3
} BorderType;
</code>```

and also (possibly) it can be equivalent to

```<code>typedef enum NSInteger {
    kBorderTypeNone   = 0,
    kBorderTypeLeft   = 1 ,
    kBorderTypeRight  = 2,
    kBorderTypeTop    = 4,
    kBorderTypeBottom = 8
} BorderType;
</code>```

What are the internal differences(if any)? Is there any advantage of one over the other? Which one is recommended?

If both are same then how compiler handles it? In which phase of compiler is it reduced to same set of instructions?


问:
What happens during "loading" screens?
I'm from the AS3, JavaScript, and similar "web languages" where loading means the code is being downloaded from the server, and can't run reliably until enough has been fetched to the user's computer.

However, what happens during a loading screen in software and games in which all the information already exists on the user's computer? (especially now that the information can be stored on a "quick to read and write" harddrive, rather than slow floppies or CDs)

Does this differ from the loading pauses that sometimes may occur in the middle of a game?

答:
Hard-drives are still too slow to run complicated calculations directly off of. When games load, they are pulling information into your memory. As in RAM.

Random Access Memory loads hundreds of times faster then most hard-drives. So when a games is loading, it is puling all the information it'll need off of the hard-drive, formatting it to make it useful for the software to use and storing it in ram.

Unfortunately, most people's RAM is still limited. Only 8gb to maybe 32gb. For some games, that isn't enough to load everything into (especially since your operating system and other programs are using some). The end result: the game only loads some of the information into RAM. When you need more, you get a loading screen.

Title: What happens during "loading" screens?


问:
Interpreting Date formats
Let's say I have a DatePicker control and I allow my US clients to type something like
"1/1" in it and hit tab go to next control. So I will parse that date for them as "01/01/2014" and some more similar patterns. But they are all US-based so they are

```<code>"MM/dd/yyyy"
</code>```

Now my question is about other formats? What If I want to support a country format that is like "yyyy/mm/dd" . How do those countries interpret such patterns?

答: I don't believe there is any standard way of how this should work, but I think you can assume if they are only entering two parts of the date those parts are the day and month (unless the system has a specific requirement otherwise). But you need to put a bit of intelligence in there, for example date format might be yyyy.mm.dd. You algorithm should ideally be generic based on locale.</p>

Title: Interpreting Date formats


答:
You can use culture related format provider or directly use custom format when translating DateTime to String.

If you use VS 2010 and above, read this in MSDN Library starting from DateTime documentation:

http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.100%29.aspx

And also this for custom date and time format:

http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.100%29.aspx

Title: Interpreting Date formats

Body:
Let's say I have a DatePicker control and I allow my US clients to type something like
"1/1" in it and hit tab go to next control. So I will parse that date for them as "01/01/2014" and some more similar patterns. But they are all US-based so they are

```<code>"MM/dd/yyyy"
</code>```

Now my question is about other formats? What If I want to support a country format that is like "yyyy/mm/dd" . How do those countries interpret such patterns?


答:
There are several things what a program might process during the loading screen.
Bring primarily an AS3 developer myself, I can surely say that it's not limited to any specific platform in general. AS3 developers need to do it too.

Here's a small list of what a typical app does during the Loading stage:

Pre-calculation. A very broad explanation, but usually it's calculating paths for pathfinding, rendering vector graphics into the raster, saving pre-calculated (baked) byte data to a local storage path, loading data from local storage into memory (RAM).

Initialization. Larger apps need to create more objects than smaller apps before they can start. It's even slower when some frameworks with large footprint are being used. The application is heavily loaded at that time and isn't responsive. For that reason, it's better to show a loading screen that outputs some info on why the app isn't working yet.

Object pooling. Similar to Initialization process, a set of objects that are going to be reused are created. Since there are a lot of these objects, it may take some time to create them all. Better to do that on a loading screen to avoid lag.

Downloading external data. Some apps require assets, such as sounds, art, data (text translations, level info, prices etc). If these assets are subject to change or new ones can be added it makes sense to keep them on the server and download them when needed.

Garbage collection. Since resources are limited, unused memory needs to be released to create new objects in its place. But garbage collection is a very heavy CPU time-consuming process. Better to do that on a loading screen to avoid lag.

This list is not complete by any means. There are some specifics to each platform, API, programming language even. Just a rule of thumb - if something takes a lot of processing time - put it on the loading screen.

Title: What happens during "loading" screens?

Body:
I'm from the AS3, JavaScript, and similar "web languages" where loading means the code is being downloaded from the server, and can't run reliably until enough has been fetched to the user's computer.

However, what happens during a loading screen in software and games in which all the information already exists on the user's computer? (especially now that the information can be stored on a "quick to read and write" harddrive, rather than slow floppies or CDs)

Does this differ from the loading pauses that sometimes may occur in the middle of a game?


答:
Readability

The first form indicates to the maintainer that the values of that enum may represent bit positions in a multiple flag variable and can be used as:

```<code>myCellBorders = kBorderTypeLeft | kBorderTypeTop | kBorderTypeBottom;
</code>```

It also indicates that all possible values are already reserved and that you cannot define other values for that enum, for instance:

```<code>kBorderTypeHalfSizedCenteredBottom = 3
</code>```

The second form implies that the maintainer is aware that successive powers of 2 are 1, 2, 4, 8..., that she has noticed this specificity, and that it matches the coder's intention.

Title: Difference between the two enums

Body:
Readability

The first form indicates to the maintainer that the values of that enum may represent bit positions in a multiple flag variable and can be used as:

myCellBorders = kBorderTypeLeft | kBorderTypeTop | kBorderTypeBottom;

It also indicates that all possible values are already reserved and that you cannot define other values for that enum, for instance:

kBorderTypeHalfSizedCenteredBottom = 3

The second form implies that the maintainer is aware that successive powers of 2 are 1, 2, 4, 8..., that she has noticed this specificity, and that it matches the coder's intention.


问:
Should I fork a fork (on Github)?
On Github, I've run across a pull request which it implements a feature I like but feel isn't quite intuitive and could be better. The maintainers of the original repo have so far declined to accept it (or explain why). It was requested 3 months ago so I suspect they won't take it without changes.

I'd like to improve upon this contributor's code but don't know the etiquette: should I fork this fork? Or do I fork the main repo and add the other fork as another upstream source? If the latter, how do ensure credit is given where due? What implications does either option have for pull requests?

EDIT: While I appreciate hearing opinions and did ask about etiquette, I'm more interested in knowing about whether there is any technical or pragmatic reason to fork off the main project and add the creator of the 'cool feature' PR as an upstream versus just forking the branch of the 'cool feature' PR.

Based on jan-hudec's answer I'm inclined to fork main + add new upstream. I suspect it'd be easier to keep my fork up-to-date and not reliant on this other contributor to incorporate upstream changes.

答:
If you want your own copy of the project you want to modify - fork it. That's why that feature exists.

About giving credit to original authors or the recently forked project authors - look at the license of that project. If it states that you need to keep the credits text file - do so. If there's nothing like that - it's totally up to you weather to or not to mention the original source of that project.

Title: Should I fork a fork (on Github)?


问:
Neural network input preprocessing
It's clear that the effectiveness of a neural network depends strongly on the format you give it to work with.  You want to pre-process it into the most convenient form you can algorithmically get to, so that the neural network doesn't have to account for that itself.

I'm working on a little project that is going to be using neural networks.  My future goal is to eventually use NEAT, which I'm really excited about.  Anyway, one of my ideas involves moving entities in continuous 2D space, from a top-down perspective (this would be a really cool game AI).  Of course, unless these guys are blind, they're going to be able to see the world around them.

There's a lot of different ways this information could be fed into the network.  One interesting but expensive way is to simply render a top-down "view" of things, with the entities as dots on the picture, and feed that in.  I was hoping for something much simpler to use (at least at first), such as a list of the x (maybe 7 or so) nearest entities and their position in relative polar coordinates, orientation, health, etc., but I'm trying to think of the best way to do it.

My first instinct was to order them by distance, which would inherently also train the neural network to consider those more "important".  However, I was thinking- what if there's two entities that are nearly the same distance away? They could easily alternate indexes in that list, confusing the network.

My question is, is there a better way of representing this?  Essentially, the issue is the network needs a good way of keeping track of who's who, while knowing (by being input) relevant information about the list of entities it can see.

Thanks!

答:
Entities that are far apart don't need to consider each other in the same way you don't think about the car three streets over. You might not even consider cars behind you until they are tailgating. Inputs should be limited to entities only within a specific threshold.

In any case, rendering data and then deriving it from the rendered data is never going to be as efficient as generating data and then rendering the result.

Title: Neural network input preprocessing


答:
There is no difference between fork from upstream with the other fork as additional source and fork from the other fork with upstream as additional source. And when the pull request is merged upstream, it retains absolutely no information about from where it was merged anyway.

Git has separate "author" and "committer" headers for a commit, but it does not have multiple authors. So the only way to give the credit is giving it in the commit comment. If the project uses the Signed-Off-By pseudo-headers in the commit comment, you definitely have to maintain those.

Plus keep any entries added to AUTHORS file, of course.

For the rest, try to discuss the changes in appropriate channel (many projects that existed before github or are done by people used to it have mailing list and prefer discussing things there)

Title: Should I fork a fork (on Github)?

Body:
On Github, I've run across a pull request which it implements a feature I like but feel isn't quite intuitive and could be better. The maintainers of the original repo have so far declined to accept it (or explain why). It was requested 3 months ago so I suspect they won't take it without changes.

I'd like to improve upon this contributor's code but don't know the etiquette: should I fork this fork? Or do I fork the main repo and add the other fork as another upstream source? If the latter, how do ensure credit is given where due? What implications does either option have for pull requests?

EDIT: While I appreciate hearing opinions and did ask about etiquette, I'm more interested in knowing about whether there is any technical or pragmatic reason to fork off the main project and add the creator of the 'cool feature' PR as an upstream versus just forking the branch of the 'cool feature' PR.

Based on jan-hudec's answer I'm inclined to fork main + add new upstream. I suspect it'd be easier to keep my fork up-to-date and not reliant on this other contributor to incorporate upstream changes.


问:
Parser and interpreter knowledge as a way to gauge programmer ability
This is only anecdotal evidence but from my past encounters with programmers at various workplaces the programmers that understand the fundamentals of parsing and interpreting seem to be overall better programmers. They also tend to be less religious about their tools. My subjective experience indicates they tend to write better code as well. I've mostly worked with application programmers and I know this is a very limited sub-discipline of programming in general so take my limited experience for what it is and nothing more.

What are some other foundational components of CS that tend to be correlated with programming skill and ability? I'm assuming some basic understanding of basic data structures so that's a given.

答:
I think that parser and interpreter knowledge may correlate with skill simply because most people who are very interested in programming, and thus more likely to have higher skills in programming, have at some point written a parser themselves or taken at least a compiler course in higher education.

This of course assumes that interest in programming leads to higher skill in programming, which I think it does. But then you could likely say that most other advanced programming topics correlate with programmer skill.


答:
I think it. depends on your environment. For example I work in banking and finance. The most productive programmers there are those who are numerate, i.e. can look at numbers and understand what they mean. Understanding parsers etc but not understanding the numbers will not help you as much.

Those who understand parsers are more likely to have undergone extra training in computer science and so understand more things in computing.

Title: Parser and interpreter knowledge as a way to gauge programmer ability

Body:
This is only anecdotal evidence but from my past encounters with programmers at various workplaces the programmers that understand the fundamentals of parsing and interpreting seem to be overall better programmers. They also tend to be less religious about their tools. My subjective experience indicates they tend to write better code as well. I've mostly worked with application programmers and I know this is a very limited sub-discipline of programming in general so take my limited experience for what it is and nothing more.

What are some other foundational components of CS that tend to be correlated with programming skill and ability? I'm assuming some basic understanding of basic data structures so that's a given.


答:
The conventions I use are

```<code>//non-private variable
variableName

//private variable
_variableName

//methods
MethodName

//parameters
parameterName

//Properties
PropertyName
</code>```

These are standard MS c# conventions. There is a list here.
If you want something to help you keep nice clean code following conventions, consider Resharper add-on for Visual Studio

Title: Summary of C# naming conventions (official Microsoft conventions)

Body:
I am struggling with naming convetions in C# I do not know when to use PascalCase or camelCase. I have read Microsoft's naming convention, but I got lost ther http://msdn.microsoft.com/en-us/library/ms229045(v=vs.110).aspx

As far as I know this is correct:

```<code>public int Number;
private int number;
public void Method();
private void method();
int number;//for any local variable
</code>```

But in context of that above how should I name components in XAML: x:Name="Button" or x:Name="button". They seems to be private field so I should use camelCase, but on the other hand everywhere on the examples I see PascalCase for x:Name

I do not ask about one's habits, but orthodoxic/official/C# guru style.

Body:
The conventions I use are

//non-private variable
variableName

//private variable
_variableName

//methods
MethodName

//parameters
parameterName

//Properties
PropertyName

These are standard MS c# conventions. There is a list here.
If you want something to help you keep nice clean code following conventions, consider Resharper add-on for Visual Studio


答:
As the sole developer, I think you just have to let go (hopefully temporarily) of some of of the professional techniques bigger teams has. But you CAN make some substitutes!

You should always use repositories. You should probably make more tests than before (since there is no other person who can catch mistakes).

If you are able, make each feature or addition a separate changeset / shelveset (or branch in git), so that you can create some feature, test it and then ignore it for 1-2 weeks(longer is probably better). Then read through the entire shelveset. Now: If you have no problems understanding every line of code immediately, consider it acceptably code reviewed(as 1 person I think this is the best you can do). If there are parts of the code where you do not immediately understand every aspect of the code, spend some extra time to see if you can make it simpler, or more understandable.

Better than everything above is to get your boss to hire another programmer and peer review each others code.

Good luck!


问:
How to introduce Scrum in a company accustomed to Scrumbutt or Scrumfall?
A colleague of mine works as a consultant. He is recently asked to help a software development company to improve their processes. The company is aware of some of the issues, like the number of bugs or the fact that they can't release their lead product more often than once per year, but nobody there knows what to do.

My colleague identified that they have a primitive in-house process which they call Scrum, but which isn't.

My colleague wants to suggest moving to “the real Scrum”. If he does that, he will encounter two issues:

Managers will reply that they already use Agile, and that it wasn't helpful.

It would be particularly tricky¹ to explain both to the managers and to the CEO of the company that it was not the real Scrum which was used until now, but rather a mix between Scrumfall and Scrumbutt.

What to do?

¹ In this company, two of the three managers claim they know perfectly well Agile and Scrum and apply it flawlessly to their respective teams. Claiming that they know nothing about any of those two subjects would create a hard to handle situation. My colleague's role is also not only to give his opinion, but to apply the “good” methodology for the next three months within this company. Starting by claiming that managers are incompetent in this context is not a solution.

答:
Two suggestions:

Either pick an Agile method different from Scrum, such as XP, without mentioning Scrum and avoiding talking about it or comparing it to XP.

Or, if he's convinced that Scrum is more appropriate than any other method, apply Scrum without naming it.

Avoiding to talk about Scrum would help avoiding arguments, and especially two risks:

The risk that one of the managers starts to argue that he knows Scrum better and that according to his deep knowledge, for example, it's the Scrum master who assigns work to team members.

The risk for the team to take negatively every suggestion of the consultant. “We already tried Scrum, it failed, so why do you bother us with it again?”.


答:
First: Going from .NET to embedded development through the conventional route is likely to be difficult, given the propensity of HR departments to throw away any resume that doesn't have all the buzzwords the hiring managers say they want to see.

The way you work around this is you get active in the local electronics and computing hobby communities, talk to EVERYONE, while learning the craft.  You'll hear about opportunities this way.  You hang out at the local MakerSpaces.  You get involved in other things.  (I heard about one project that was DESPERATE for software help, when I went to a talk at a ham radio convention.  Some hams in Texas were setting up an intercity packet radio network.  They could handle the radio stuff and the electronics stuff, but they knew nothing about how to write the necessary software.)

For the simple mechanics of learning basic embedded system development, you start by learning basics of making things happen in the real world.

Arduino is a surprisingly capable board for small embedded projects, with a development environment that was designed from the ground up to be usable by non-programmers who were willing to learn basics of programming.  There are lots of tutorials, that cover both basics of embedded programming AND how to hook up basic hardware.

Teensy 3.0 is a 32-bit ARM board with similar goals to Arduino.  It is not nearly as widely used as Arduino.  Tutorials exist.

Both are quite inexpensive.  Arduino has a much larger ecosystem of available peripheral boards ("shields").

There are Sagans ("billions and billions") of PIC boards out there, and Sagans of PIC tutorials, for hardware and software.

All of these things do require you to learn some basic electronics.  It won't kill you.  You are going to have to invest some money in tools.  The good news is that most of the tools you need are amazingly affordable these days, if you are willing to buy secondhand.

Title: Question about moving to embedded systems

Body:
I currently work as a .net developer and have coming up to 3 years experience in the industry as well as a degree in computer science specifically software engineering (I know that means nothing but just wanted to explain that I'm not your general back bedroom programmer).

When I finished Uni, I started contracting for a company. I wont mention their name but some of you may have heard of them just by the description. Basically they take in fresh graduates and in return for training and contracting experience you have to go to the clients they say for a minimum of two years. I cant say this was great but I do feel I know more than people with the same years of experience as me.

The problem is that I've now started heading down the route of web development because of the lack of choice in clients.

How difficult is it to change from a .net field to embedded/low level programming? I have the enthusiasm for it and the strive but I'm not quite sure how to go about moving. Unlike application development, knowing the language and having some business etiquette doesn't seem to be enough.

For example hardware wise I can set-up a computer but wouldn't know how to manually attached wires and program these systems. Is this kind of knowledge necessary?

Thank you in advance. Also if anyone has similar experience of swapping, should I?

tl;dr

Developer that doesn't know how to get from web development roles into embedded systems.

Edit::
Thank you all for the advice.


问:
What kind of object relational mapping is appropriate here?
In my database I have a table that looks like this  Master(ID, Name, Attr1...). Every ID will have at least 1 entry in additional tables that have additional attributes. Those tables specialize the master table.

Spec1(MasterID, Attr2,...)

Spec2(MasterID, Attr3,...)

...

So, not sure how to map this to object oriented design. If every ID could have just one specialization then it would be easy, master would be abstract class and specializations would be concrete inherited classes but in this scenario, single ID can have all specializations and they could be added or removed during his lifetime in the database. Each specialization has unique business rules ofc.

答:
In most cases it not very useful to make modeling decisions with names like "Master" or "Spec1" (one has to see the actual names and have a notion about their intended semantics). But in your case it seems pretty obvious that you are looking for an aggregate relationship between the class/table "Master" and the classes/tables "Spec1", "Spec2". It may be either a "1 to {0,1}" or a "1 to {0,n}" relationship, which depends on how many Spec records/objects you want to allow per Master record/object.

Dont' try to use "inheritance" for such cases. Inheritance is for static forms of specialization, not for specializations which can change at run time.


答:
It depends on how low-level you want to go.

Of course going to a level where you solder together your own PC is to say the least; not very probable.

If you want to get to writing C and Assembler on customizable hardware, I'd suggest starting with RaspberryPi.  In addition to it being fun you can use it together with some JavaLibs to get into the basics of hardware interfacing, RS232, and the like. After you're through with that you can exdand upon these things with a platform like arduino,  that is closer to "real" C programming. After that you probably have a good base of knowledge to develop the way you want and make informed decisions.

I describe it like this because I did it the other way around. I learnt some basics of java an then assembler and C and moved from almost pure hardware and self designed circuits and drivers to arduino, to RbPi and then to .NET.

As for "how to put together a PC, hardwarewise": There is tons of tutorials for all these things. Just see SE.

Only difference to now is that you cannot copy paste a solution to a hardware-problem ;)


答:
Don't fight them on a systemic level. What they are doing is what Scrum means to them, so using the word Scrum to mean anything but what they're doing will not make any sense to them.

Don't even fight the system. Some of the things they do might be working for them, even if they're not Scrum. Scrum is not a one-size fits all solution; I haven't even read two books on Scrum that can agree on all the details. It's all just advice, which may or may not work in the context of any given company.

As a consultant, the job is to sit down and take stock of all the things that are going wrong and find the solutions. You can pull those solutions from Scrum or XP or Kanban or you can just make them up. It doesn't matter.

But don't try to teach them something they believe they already know. Don't tell them that they're flat-out wrong, even if they are. Just figure out what they're doing wrong -- by which I mean, very specifically, what isn't working for them -- and teach them to do it right.

For example, why can't they release monthly, weekly or whenever they choose? Do they need a better (D)VCS? Do they need a continuous delivery system? Do they need to improve their deployment process? Teach them how to do those things, rather than pushing a single label on them for their entire development process.

Title: How to introduce Scrum in a company accustomed to Scrumbutt or Scrumfall?

Body:
A colleague of mine works as a consultant. He is recently asked to help a software development company to improve their processes. The company is aware of some of the issues, like the number of bugs or the fact that they can't release their lead product more often than once per year, but nobody there knows what to do.

My colleague identified that they have a primitive in-house process which they call Scrum, but which isn't.

My colleague wants to suggest moving to “the real Scrum”. If he does that, he will encounter two issues:

Managers will reply that they already use Agile, and that it wasn't helpful.

It would be particularly tricky¹ to explain both to the managers and to the CEO of the company that it was not the real Scrum which was used until now, but rather a mix between Scrumfall and Scrumbutt.

What to do?

¹ In this company, two of the three managers claim they know perfectly well Agile and Scrum and apply it flawlessly to their respective teams. Claiming that they know nothing about any of those two subjects would create a hard to handle situation. My colleague's role is also not only to give his opinion, but to apply the “good” methodology for the next three months within this company. Starting by claiming that managers are incompetent in this context is not a solution.


问:
Should content be distributed with applications using Open Source license?
I have been developing a database-driven web application with extensive contents. The application is set to release using a GNU GPL v3 license. Whereas the content would be licensed using a Creative Commons license. To provide a brief context, this is an e-learning site, where I provide some kind of learning materials.

Additionally, I am planning to provide a database dump along with the source code. The reason being, one would be able to setup and actually use the application given the contents. I have two questions in this regard:

Should I actually include the database dump along with the source code? If I don't, a user would require to create everything by his own, which is not desirable.

If the above answer is "yes", what license is applicable to the physical file containing the database contents?

Please note that it is not possible to use any other type of licenses for the code and content, and both are to be licensed.

P.S.: In case this question seems off-topic, could you please point to a more relevant site?

答:
If you can (re-)build the application without the database dump, then there is no requirement to distribute the dump along with the source code.

Depending on the language that your application is written in, I would provide 2 or 3 downloadable packages:

A package with the application itself. This contains the application in the form used to execute the application, which would be a binary format if it is written in a non-scripting language. This package will be released with the GPL license.

A package with the dump of the database. This package should not be strictly needed to use the application, but might make it easier to get it up and running. As the database dump is noting more than a representation of the content, this package should use the CC license of the content.

A package with the source code of the application. This package is only needed in the first package contains binaries and is intended for those users that might want to make modifications to the application. This package also uses the GPL license.

OwnerDisplayName: Barun


问:
Refactor an old model of a LastUser Modification on every Object?
I have a software requirement, that needs to store the user that made the last modification to another object, for every object (assume that all objects are already mapped and into a BD).

So we have the ParamBase an object that holds the basic data for every object, this will be a super class, every other parameter in the system will Inherit this class, (Using @MappedSuperClass)

```<code>@MappedSuperclass
ParamBase {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Version
    private Long version;

    @Temporal(value = TemporalType.TIMESTAMP)
    private Date timeStampLastModification;

    @Column
    private User userOfLastModification;
    //constructors, getter setters, other stuff, etc
}
</code>```

The User object, this will represent the user, also mapped into a BD, for now is just simple Object mapped as Entity, all other Parameters will have to store this User into a field.

```<code>@Entity
User {
   //User stuff, cons, get, seters, etc
}

@Entity
Country extends ParamBase {
    //This class extends ParamBase so will have a field to hold the
    //userOfLastModification
}
</code>```

In an EJB I have business logic that will work with several operations and objects, when in this case a parameter is updated, the userSession (assigned at login) will update the userOfLastModification field.

THE PROBLEM:
All of the objects will have a relation with User, so all other Objects have a mapped field userOfLastModification_id, this creates a massive dependency of all clases to User.
To give you an idea, just picture on an Entity Relation diagram ER, all tables related to one single User Table, it's a mess!!!

THE REFACTOR!:
I think this model is wrong, I think breaks the equilibrium of software design  I don't think you need to create a relation between all the tables/object to one table (User) to accomplish this requirement, I will like some feedback or ides on how to:
1. Explain the design error, if there is one? (I always think that I can be wrong, and there's no problem with that)

Is there a better way to do this?

Thanks for your help!

答:
From a database design perspective, there is nothing wrong whatsoever with tracking your users with a single table via a common reference field where applicable.  You may want to not have a computed index on each and every table, but that's an implementation detail rather than a design requirement.

On the Java side, however, your intuition is correct.  You probably do not want each and every object to contain a full reference to user.  Instead, include a standard field with a common naming convention, and treat the user reference simply as text.  So, instead of

```<code>@MappedSuperclass
ParamBase {
    private User userOfLastModification;
}
</code>```

you would do something like:

```<code>@MappedSuperclass
ParamBase {
    private String userOfLastModification;
}
</code>```

You'd only spool up an actual User object when you need its various data points, such as if you're translating a user's internal key to a display name.

Body:
From a database design perspective, there is nothing wrong whatsoever with tracking your users with a single table via a common reference field where applicable.  You may want to not have a computed index on each and every table, but that's an implementation detail rather than a design requirement.

On the Java side, however, your intuition is correct.  You probably do not want each and every object to contain a full reference to user.  Instead, include a standard field with a common naming convention, and treat the user reference simply as text.  So, instead of

@MappedSuperclass
ParamBase {
    private User userOfLastModification;
}

you would do something like:

@MappedSuperclass
ParamBase {
    private String userOfLastModification;
}

You'd only spool up an actual User object when you need its various data points, such as if you're translating a user's internal key to a display name.


答: If I was in the same situation I would ask if they would like to hear what they wanted to hear or the unpleasant truth. If they want the truth, just give it straight up. If they don't want to hear it, it's their choice. Just walk away. But they probably expect him to be honest. Giving them the choice is a fair thing to do. </p>


问:
Is this a design pattern?
I have following C# code. It helped me to avoid some code repetition in a good way.

The ExecuteQueryGenericApproach<T> method receives a Func generic delegate as argument. The delegated method has a parameter which receives IDataRecord as argument.  That is, the  ExecuteQueryGenericApproach<T> method provides the required IDataRecord to the functions passed to it.

QUESTIONS

What is the name of this pattern? (Based on GoF design patterns)

Is there any other scenario where this pattern is used?

Note: Knowing the name of this pattern will help me to better research on this and find opportunities to use it.

CommonDAL

```<code>public class CommonDAL
{
    public static IEnumerable<T> ExecuteQueryGenericApproach<T>(string commandText, List<SqlParameter> commandParameters, Func<IDataRecord, T> methodToExecute)
    {
        string connectionString = @"Server=XXXX;Database=AS400_Source;User Id=dxxx;Password=xxxx5";

        //Action, Func and Predicate are pre-defined Generic delegates.
        //So as delegate they can point to functions with specified signature.

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = connection;
                command.CommandType = CommandType.Text;
                command.CommandText = commandText;
                command.CommandTimeout = 0;

                if (commandParameters != null)
                {
                    command.Parameters.AddRange(commandParameters.ToArray());
                }

                connection.Open();
                using (var rdr = command.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        yield return methodToExecute(rdr);
                    }
                    rdr.Close();
                }
            }
        }
    }
}
</code>```

EmployeeDAL

```<code> public class EmployeeRepositoryDAL
    {
        public static List<Employee> GetEmployees()
        {
            string commandText = @"SELECT E.EmployeeID,E.EmployeeName,R.RoleID,R.RoleName FROM dbo.EmployeeRole ER
                                    INNER JOIN dbo.Employee E  ON E.EmployeeID= ER.EmployeeID
                                    INNER JOIN dbo.[Role] R ON R.RoleID= Er.RoleID ";

            //IEnumerable<Employee> employees = MyCommonDAL.ExecuteQueryGenericApproach<Employee>(commandText, commandParameters, Employee.EmployeeFactory);

            //Group By is needed for listing all the roles for an employee.
            IEnumerable<Employee> employees = CommonDAL.ExecuteQueryGenericApproach<Employee>(commandText, null, Employee.EmployeeCreator)
                                                    .GroupBy(x => new { x.EmployeeID, x.EmployeeName },
                                                            (key, group) =>
                                                                            new Employee
                                                                            {
                                                                                EmployeeID = key.EmployeeID,
                                                                                EmployeeName = key.EmployeeName,
                                                                                Roles = group.SelectMany(v => v.Roles).ToList()
                                                                            }
                                                            ).ToList();

            return employees.ToList();
        }

    }
</code>```

Entity

```<code>public class Employee
{
    public int EmployeeID { get; set; }
    public string EmployeeName { get; set; }
    public List<Role> Roles { get; set; }

    //IDataRecord Provides access to the column values within each row for a DataReader
    //IDataRecord is implemented by .NET Framework data providers that access relational databases.

    //Static Method
    public static Employee EmployeeCreator(IDataRecord record)
    {
        var employee = new Employee
        {
            EmployeeID = (int)record[0],
            EmployeeName = (string)record[1],
            Roles = new List<Role>()
        };

        employee.Roles.Add(new Role { RoleID = (int)record[2], RoleName = (string)record[3] });
        return employee;

    }
}
</code>```

答:
I don't really think this is a design pattern. First reason is that GoF design patterns were are OOP with zero knowledge of first-class functions or generics. Both which are used in your example.

One important thing to remember: Not everything is a design pattern. Just because something saved you some time doesn't make it a design pattern. If you follow a proper design principles, you can create a good, extensible code without even knowing a single design pattern. Design patterns are only good if you want to communicate what the code does to someone else.

Title: Is this a design pattern?