问:
Risks in giving out distribution cert/private key/provisioning profile to freelancer
Are there any risks in giving out distribution certification/private key/provisioning profile to a freelancer?

The freelancer needs to build the binary for me to submit (I am okay with this because I don't own the source code of the app), I just want to know if there is any risk involved in sending the distribution cert/private key/provisioning profile to him?

p.s. They don't have the iTunes connect/portal login.

Updated: The freelancer will build the binary for me, and I will upload for them.

答:
To upload an app from the freelancer's Xcode, you'll need to go into iTunes Connect and create the app/version setup. They'll then need your iTunes Connect login info to log into your account IN Xcode, so that Xcode can match up their binary with your app "slot". They might not log into iTunes Connect itself, but they'll need to give Xcode those same creds.

And yes, to compile and sign the binary, they'll need a developer key and provisioning profile that was created from inside your portal. Just giving him those shouldn't be any real risk, but that's not all they'll need.

The simplest thing, in my experience, is to give your developer your iTunes Connect credentials and turn them loose. I always need to take a couple shots at getting the certificates hooked up right. Much easier for him to do all that on his own.

And then yes, it's risky, because he now has access to all your banking stuff and everything else. If you are concerned about this person's reliability and trustworthiness... Well perhaps you should have hired somebody more like me. ;-)


问:
best practice when working with a MySQL database datadir directory
At the place I currently work they do some thing I consider strange in the way they work with the MySQL datadir. The directory in which the files that actually store the data are kept.

$ grep datadir /etc/mysql/my.cnf

  datadir = /var/lib/mysql

Where all the .frm .myd .myi files are found.

When moving data around on the network or doing client installs they copy these files directly out of the this directory and past them into which ever directory they have set up MySQL to use on the client side. They do the same thing at the office.

I was taught as a Database Administrator that you should work with the scripts. Export the data and structure of the database as a SQL script and import it as a SQL script when you want to start working with it. This is to protect the data integrity. As those files can be in a state inconstant with a working copy of the data. As caches may not have been written to the database files on the disk. I see that they stop the MySQL server when doing the copying and pasting so that should prevent the data becoming corrupt.

I was wandering what industry best practice is around this issue. It seams strange to me. Considering how they view security, concerning passwords and root access I think they have developed a bad practice and are doing it ignorantly. They don't have a strong understanding of some of the fundamentals of how database systems should work. Am I wrong, should I just go with the flow and not get involved with trying to change these practices.

答: Generally you will use the proper backup mechanism, mysqldump in the case of MySQL, along with testing that the backup can be successfully restored. It's better to pretend that every backup and restore is being audited by someone very official looking.</p>

ContentLicense: CC BY-SA 3.0


问:
In a web application backed by a database, how often should I validate data?

Possible Duplicate:

  Data input validation - Where? How much?

Given that I have a web application with a user facing form that will store information in a database (that will be used by other applications as well), it seems to me to be worthwhile to validate 3 times:

On the web client side via javascript to save postbacks to the server when the user enters bad data or forgets a field

On the server side because we can't trust the web client to have validated the data and saves calls to the database when the data is invalid

On the database side because this is the only way to ensure that the data stored in the database is valid.

On the one hand, this seems excessive and violates the DRY principle.  On the other hand, the performance would be noticeably different if I had to submit the request, send it to the database and return an error generated by the database for bad or missing user information.  What is a reasonable amount of validation?

答:
We use Ruby on Rails and the pattern most often seen is to validate on the server and not much else.

You can't trust client side validations anyway. At least to us a few extra posts don't matter. Though there may be situations where JavaScript can give better error messages. But I nearly never use it for that.

When the Model has validations and there are tests that ensure those validations work as expected, there is not exactly much need to validate on the database again. Not only wouldn't it be DRY, you would have to add extra logic in your code to handle any errors returned by the database. Errors that the Model should already have raised.

If you can't 'trust' your code, your problem is quality control, not where to place (or repeat) certain parts of it. Proper unit tests should make sure that such things work.


答:
Approach client side validation with the user experience in mind.

Server side validation should sufficiently prepare your data for storage in the database.

Title: In a web application backed by a database, how often should I validate data?

Body:
Possible Duplicate:

  Data input validation - Where? How much?

Given that I have a web application with a user facing form that will store information in a database (that will be used by other applications as well), it seems to me to be worthwhile to validate 3 times:

On the web client side via javascript to save postbacks to the server when the user enters bad data or forgets a field

On the server side because we can't trust the web client to have validated the data and saves calls to the database when the data is invalid

On the database side because this is the only way to ensure that the data stored in the database is valid.

On the one hand, this seems excessive and violates the DRY principle.  On the other hand, the performance would be noticeably different if I had to submit the request, send it to the database and return an error generated by the database for bad or missing user information.  What is a reasonable amount of validation?


答:
Usually when I've done this, I've done it all three times, but with a twist that adds value at each layer:

client side - checking for data errors that are so bad that they should never be sent to the server.  Formatting, an light reality checks (for example - there is no September 31).

server side - quick pass through data validation, add business logic checks.  Sometimes you can even reuse the same validation code, so you only have to write it once.  A must have is the security type checks - injection, overflows, etc.

database - generally, I have not used the database for the same type of data validation.  It's got minimal protections against format violations and size violations.  But not all the quality checks that the client and the server.  I don't generally presume that the database can't trust the server.  The database should be checking the data from an integrity standpoint, however, for example, the server should not be posting such that we have multiple, overlapping, conflicting write operations due to a lack of data refresh.

I think you can focus in on the closest/lowest level of validation (server and database) at the expense of usability.


问:
What features in Eclipse is not available in Visual Studio?
I have done much development in Java using Eclipse, and now I have started to use Visual Studio for .NET development. So far I find the IDEs to be able to do the same things, but just different.

What features in Eclipse isn't available in Visual Studio?

答:
Eclipse Quick Access is an amazing usability feature, in my opinion.

Short version:

Imagine a QuickSilver or Launchy inside the IDE!.

With Quick Access you can navigate to almost any part of the IDE using the keyboard. Yes, that can be done in Visual Studio also but you need to learn the shortcut to each view: Ctrl+Alt+J to go to the Object Browser; Ctrl+Alt+L for Solution Explorer, etc; or use generic window switching shortcuts (like Ctrl+F6 to go to next window one by one).

In Eclipse, you only need one shortcut: Ctrl+3 to open the Quick Access tool.

The Quick Access tool hat allows you to just start typing the name of any command, view, perspective, menu even source files! and it will auto-complete and suggest alternatives.

Quick Access:

Will remember abbreviations and your most frequent accessed items and progressively adapt to the way you use it.

Will also allow you type PascalCase abbreviations: You want to go to the Data Source Explorer view? type DSE and it will show up as the first option.

It will also show the keyboard shortcut for each item as a learning aid.

Read more:

http://eclipsenuggets.blogspot.com/2007/05/quick-access-ctrl3-is-bliss-are-you-one.html

http://eclipse.dzone.com/articles/eclipse-36-hidden-treasures

ContentLicense: CC BY-SA 2.5


答:
If they are setting up a duplicate of an existing db e.g. starting db state for an application AND the db they are copying is not under heavy use (ideally almost no use) - then this is a quick and simple method.

If the database is under even light use however, this is pretty poor as you risk various lock delays and it's difficult to know exactly what state you will be copying.

Title: best practice when working with a MySQL database datadir directory

Body:
At the place I currently work they do some thing I consider strange in the way they work with the MySQL datadir. The directory in which the files that actually store the data are kept.

$ grep datadir /etc/mysql/my.cnf

  datadir = /var/lib/mysql

Where all the .frm .myd .myi files are found.

When moving data around on the network or doing client installs they copy these files directly out of the this directory and past them into which ever directory they have set up MySQL to use on the client side. They do the same thing at the office.

I was taught as a Database Administrator that you should work with the scripts. Export the data and structure of the database as a SQL script and import it as a SQL script when you want to start working with it. This is to protect the data integrity. As those files can be in a state inconstant with a working copy of the data. As caches may not have been written to the database files on the disk. I see that they stop the MySQL server when doing the copying and pasting so that should prevent the data becoming corrupt.

I was wandering what industry best practice is around this issue. It seams strange to me. Considering how they view security, concerning passwords and root access I think they have developed a bad practice and are doing it ignorantly. They don't have a strong understanding of some of the fundamentals of how database systems should work. Am I wrong, should I just go with the flow and not get involved with trying to change these practices.


答:
The only place you HAVE to have validation is in the application. Validations in the client are, as you say, polite but unnecessary. Validations in the database should be "databasey"--ensuring uniqueness of unique keys, etc--and can mostly be set up as part of table definitions.

Just looking from the DRY concern... I've never really thought about this before, but it might be possible to use AJAX calls from your javascript to run validation routines on the server. Then you could reuse those same routines in the application.


问:
Is it acceptable to use lambda functions\methods in business software?
I've noticed posts on here demonstrating the use of delegates\lambda functions to solve the hole in the middle idea without a lot of repetition: http://www.markhneedham.com/blog/2009/04/04/functional-c-the-hole-in-the-middle-pattern/

The problem seems to be that junior developers and others don't necessarily understand what the function pointer\delegate\lambda function concept is, which seems to make reading (and possibly debugging) the code more difficult.

Should we avoid or severely limit the use of this tool in writing business software, especially in small team or sole developer shops?

Or is it acceptable to use it with appropriate comments and expect that when I'm no longer around that the next developer will understand or learn about lambda functions?

答: Put a link to the msdn documentation in comments at the top of a block that uses it then go ahead. You shouldn't be scared to use new/complex technology, its part of a developers job to learn things they don't know. </p>


问:
Does Scrum turn active developers into passive developers?
I'm a web developer working in a team of three developers and one designer. It's now about five months that we've implemented the agile scrum software development methodology. But I have a weird feeling I just wanted to share in this site.

One important factor in human life is decision-making process. However, there is a big difference in decisions you make. Some decisions are just the outcome of an internal or external force, while other decisions are completely based on your free will, and some decisions are simply something in between. The more freedom you have in making decisions, the more self-driven your work would become. This seems to be a rule. Because we tend to shape our lives ourselves.

There is a big difference between you deciding what to do, or being told what to do.

Before scrum, I felt like having more freedom in making the decisions which were related to development, analysis, prioritizing implementation, etc. I had more feeling like I'm deciding what I'm doing.

However, due to the scrum methodology, now many decisions simply come from the product owner. He prioritizes PBIs, he analyzes how the software should work, even sometimes how the UI and functionality should be implemented. I know that this is part of the scrum methodology, and I also know that this may result in better sales of product in future. However, I now feel like I'm always getting told to do something, instead of deciding to do something. This syndrome now has made me more passive towards the work.

I tend to search less to find a better solution, approach, or technique

I don't wake up in the morning expecting to get to an enjoyable work. Rather, I feel like being forced to work in order to live

I have more hunger to work on my own hobby projects after work

I won't push the team anymore to get to the higher technological levels

I spend more time now on dinner, or tea-times and have less enthusiasm to get back to work

I'm now willing more for the work to finish sooner, so that I can get home

The big problem is, I see and diagnose this behavior in my colleagues too. Is it the outcome of scrum? Does scrum really makes the development team feel like they have no part in forming the overall software, thus making the passive to the project?
How can I overcome this feeling?

答: Are you getting user stories in the form of "As a --role--, I want --goal/desire-- so that --benefit--"?  It sounds like your Product Owner wants to do the design work, and he/she may not be the best person to do that.  Using the user story pattern can help ensure that the Product Owner is sticking to the business interest, and the software development is being done by the software developers.</p>


答:
If they're a sensible solution to your problem then you should use them.

Don't artificially restrict yourself - you're more likely to end up with poor quality code that's hard to maintain.

If the code is well written with appropriate comments then those following on should be able to learn from you.

Title: Is it acceptable to use lambda functions\methods in business software?

Body:
I've noticed posts on here demonstrating the use of delegates\lambda functions to solve the hole in the middle idea without a lot of repetition: http://www.markhneedham.com/blog/2009/04/04/functional-c-the-hole-in-the-middle-pattern/

The problem seems to be that junior developers and others don't necessarily understand what the function pointer\delegate\lambda function concept is, which seems to make reading (and possibly debugging) the code more difficult.

Should we avoid or severely limit the use of this tool in writing business software, especially in small team or sole developer shops?

Or is it acceptable to use it with appropriate comments and expect that when I'm no longer around that the next developer will understand or learn about lambda functions?


答:
You should use the right tool for the job. If there's a simpler, clearer way to solve the problem at hand, use that. If you need to get into something that you think might be an advanced topic for future maintainers, mark it clearly and include a pointer to documentation that explains the technique.

the function pointer\delegate\lambda function concept

It should be noted that those are three different things.


答:
This is where consistency can help a lot.  If you use it consistently with the same style, etc., then readers only have to learn it once, and then they recognize it everywhere.

Also, it might help to be explicit, at least at first.  For instance, these two are equivalent:

```<code>doSomething(() => someMethod());

doSomething(someMethod);

private void doSomething(Action someAction) { ... }
private void someMethod() { ... }
</code>```

... but in the first case, it's obvious, if you know the lambda syntax, what we're doing.  Even if you don't know the lambda syntax, it's obvious you're seeing something new, and you have to look it up.  In the second case, it kind of looks like you're passing a variable.

I know that ReSharper pushes you to change it to the second case, but I wonder if that's always a good idea.  In the second case, you have to know that doSomething takes an Action.

Body:
This is where consistency can help a lot.  If you use it consistently with the same style, etc., then readers only have to learn it once, and then they recognize it everywhere.

Also, it might help to be explicit, at least at first.  For instance, these two are equivalent:

doSomething(() => someMethod());

doSomething(someMethod);

private void doSomething(Action someAction) { ... }
private void someMethod() { ... }

... but in the first case, it's obvious, if you know the lambda syntax, what we're doing.  Even if you don't know the lambda syntax, it's obvious you're seeing something new, and you have to look it up.  In the second case, it kind of looks like you're passing a variable.

I know that ReSharper pushes you to change it to the second case, but I wonder if that's always a good idea.  In the second case, you have to know that doSomething takes an Action.


问:
Is it possible to create and boot a scratch-built Operating System for iTouch devices?
So, what would I need to write "Hello world" on the iPod Touch on boot? Make that the entire operating system? Which compiler would I use, how would the graphics be done...? Can this be done without too much effort? I know writing an Assembly boot loader isn't that hard...</p>

答:
For any OS, you'd want a cross compiler, I use gcc4. From there, it'll probably be your best bet to use C or if you're feeling a little frisky Pascal or C++.  You would also want to know some assembly for inline asm as well as writing the bootloader (if you decide to roll your own).  The OSDev Wiki is fantastic for a beginners guide to OS Development.

For an OS on a mobile device, I would believe that it will be slightly more difficult and a bit different.  The assembly will be slightly different on an ARM processor than an Intel or AMD one, the way that the system goes through its POST and internal Bios (if it has one) will also be different.  I'm sure there are people out there that have figured how to change boot-time properties on the iPods but I couldn't find anything with a quick scan.

As for graphics and everything else, it'd be just like creating graphics on a desktop, once you take care of all of the other lower level stuff (because you're going to have to write things like printf, malloc, realloc, dealloc, and everything else that you take for granted just to get it up and going).


问:
Windows Azure vs GAE vs AWS - for process based application
I am writing an application that will crawl web pages and analyze data, and I'm wondering if I can host this as a cloud-based service.

The main reason I'm looking at cloud hosting is that users may process thousands of pages at once, and I need to return data as quickly as possible. The user will have software installed on their computer that will communicate with this application.

If, for example, each page takes 10 seconds to process, is it possible to set up auto scaling so that a user can process 1, 10 or 10,000 pages in the same amount of time (ie: 10 seconds) by simply adding and removing instances as needed?
Note: Each process requires little RAM/CPU resources, so it will be possible to process multiple pages in a single instance but for this example, I'll simplified it to 1 instance per process.

If so, which cloud-based service is best suited for this task?

答:
The big difference you are going to find between the platforms is how the vendor abstracted the environment. It will determine how you are going to develop your application or services. You can think of that as the API (of sorts for the application). The servies that you use within each vendor's context is up to you.

AWS doesn't really abstract much at the platform level. You basically get a machine where you install your software. It is up to you to write all of the supporting code. The services include storage, etc.

Azure provides a framework for you to run your code as a background or web service. It takes over and scales out from that perspective. You do not need to create the supporting os software to run your application. The services include storage, etc.

I haven not personally used GAE (yes to AWS and Azure) but it look like Google provides another framework and does not allow AWS like machine level access. Their environment appears to be more like the one hosted by Azure. They do have an interesting URLFetch service but include standard storage services as well.

If so, which cloud-based service is best suited for this task?

That would depend on the level control you would like to have? AWS provides the most control but would require more work. Azure and GAE provide more infrastructure that comes with limitations such as development languages. Azure is .NET while GAE has Java, Python.

I would suggest thinking about designing the application first and then choosing an appropriate language for development. That should give you a direction. If you are going to mix and match toolsets then it appears that AWS would be the way to go.


答:
Yes, use them.

I am a junior developer, and I know/understand lambdas (and the other concepts you mentioned). There is nothing I could forsee preventing a junior developer from learning all of those concepts in a very short amount of time. Juniors may not have the same amount of experience/expertise when it comes to many gotchas of software development, however, concepts like lambdas can be just as easily understood by anyone with a basic understanding of programming and an internet connection. Also, it seems odd that you chose lambdas as the example, considering if you are using C# it is likely you do not even have that much of a head start on learning lambdas over the junior developers (they were only introduced in 2008, if I remember correctly).

In short, there is no need to dumb down your code for us neophytes. We will be just fine, and would actually prefer to work on the best possible implementation you can come up with. :)


问:
Custom vs. browser-native scrollbars
Including customizable, JavaScript-based scrollbars (and scrolling functionality in general, i.e. bind the control to the mouse scroll wheel) in your webapp can be a great temptation.

However all solutions I could find were developed by individuals (which can equal lack of formal or future support). In addition I fail to remember any mainstream site using them.

In my particular case, no-JavaScript or IE6/odd-browser environments are not intended to be supported.

Should custom scrollbars be avoided nowadays? If not, what's the best option one can choose?

答: Jacob Nielsen has a great entry on scrollbars and what you should do with them. He specifically recommends not using the OS's scrollbars and warns against horizontal scrolling.</p>

Title: Custom vs. browser-native scrollbars


问:
How do I deal with a slow and undedicated colleague in the team?
I have been working on a new project. The project works like this: The end user can access a webapp using a link and he can add multiple systems on his network and manage that particular systems details. My part involves the front end and the webserver, which is done in python. My python actually communicates with another project which is entirely done in c & c++. The c/c++ project is the main app which does all the functionality. My python sends the user request to it and displays the response from it to the user.

I am very familiar with my work and I will finish it soon. Since that's not much work in it. And I am a person who loves to work. I spends most of the time in office and only go home when I feel sleepy.

The c/c++ app is managed by another colleague who has 5+ year experience and can do things much faster than me, but he never does it. May be he doesn't like to do it. His app crashes often when my python communicate with it or returns wrong values. It's full of bugs. Since my app depends on it, I am having a hard time building it. Instead of fixing the bugs, he asks me to slow down my work. He asks me to tell manager that my work needs a lot of time. He is asking me to fool the manager and even forcing me to work slowly like him.

During project meeting, when manager asks him about the bugs he says that he fixed everything and it works fine. Since he is my colleague, I couldn't tell anything to the manager. I obviously need to have a good relationship with my colleagues more than my manager, since most of the time we will be with our colleagues, not with the manager.

I am not able to tell the manager anything regarding this, since if manager asks him why, then he may think I complained about him to the manager. And he keeps on lying in the meeting. And since he fixes the bug slowly, it even slows down my work. Now I thought of working on the front-end part of my app  and finishing it off so that in the mean time he can make his project stable. Now he is asking me to tell the manager that my front end part require a lot of work and I may need more and more time, simply so that he can drag the project down. And the sad thing is our actual manager has gone to the US, so we have a temporary manager and this guy doesn't know about the project much, so the c,c++ just fools him.

Can anyone suggest me how I deal with this?
I wanted to finish off the project soon. How can I make him work even by maintaining a good relationship with him?

Responses to comments:

If he's really deliberately misleading the company, you should report him to management.

I am new to this company and the other guy has been there for many years. And I have just started knowing my colleagues. If I directly go and complaint him, I don't think so I can make good relationship with my other colleagues. Even he has the power to mislead them. I am not telling he is a bad guy, he can do the work, but he is not doing it.

Doesn't your company have any kind of bug tracking system ?

Here actual bug tracking system isn't there. The company tries to finish off the project as soon as possible and gives it to the QA. And then fixes the bugs reported by QA.

This is why companies should give employees stock / options or some sort of ownership. That way you can literally tell the guy "You are costing me monetary growth... don't you want to make money also?".

The company has the stock options they have given me a 2500 share, mostly he too would have got some more.

Seniority does deserve some benefit of a doubt. You really need to speak to him first and try to understand the problem. He may be out of his depth, you may be able to help him, there could easily be variables you are unaware of. It may be hard now, but you could easily make the situation a lot worse by jumping the gun.

I even does it, first his app wasn't handling multiple requests at a time, he was using a queue to handle the requests I sent to him. I even suggested to him some of my ideas on it. He said he already had these ideas, and will be executing them. His explanations was: "Everything require certain time to do and this is a project which may need two years to complete and we are asked to finish it in two months". I used to have a hard time coding during first few weeks because of this bug. But now he fixed it. But he is using a single queue for a user requests and that is now slowing down the app, since it processes one request at a time.

What is QA doing this whole time? Why aren't they reporting/confirming the status of the project(s)?

The manager is the person who decides when to give to the QA. As of now it has not yet given to QA. He said we should give it by this month end.

答: Keep records. Document every error you get when communicating with his side, when you asked him to fix and when (if ever) he did it. That is the only way I know of dealing with this situation. So when your manager comes to you asking why things are not progressing you can clearly show without being seen as a whiner or a bad colleague.</p>


答:
The problem seems to be that junior developers and others don't
  necessarily understand what the function pointer\delegate\lambda
  function concept is

Quite frankly, that's their problem. That's what you ensure they have training for. You can't not use a good technique just because some people might not understand it. If they need help with it, they can come ask the author. More importantly, lambda functions are becoming extremely common language features.

Should we not use inheritance because some people don't understand it? Hell, some people refuse to believe in science or germs or any manner of ridiculous things. You have to be able to move on and not let the possibility that others won't be able to keep up with you stop you from writing the best code you can. Lambda functions are a great feature and greatly help in writing code, and you should take all the help you can get.

A developer should know how to use the language they're in- junior or not. If they don't, then fire them and find someone who does, or train them up so they do.


答:
If you want to be more DRY, you can try to have a declarative form of validation somewhere (in the business layer, but the declarations can either be in code only or else you can have metadata classes stored persistently) which is the basis of all validation code.  The validation code on the client probably won't exactly match the server (besides just being written in another language), but that's fine.  It's DRY if you send the declarations themselves to the client to be interpreted, or if you use them to generate more specific java script code from the server.

DB validation rules can't really be done this way unless you generate the database from a model, and that's more trouble than this is worth.


答:
One very important argument that is always convincing to me when it comes to usability is consistency. You may want to make all the handles in your site look the same, noble goal, but think about how someone uses your app or site. They're not just using yours, they're using loads. In fact, I have got 8 tabs of 6 different websites open right now. I can switch to any tab and still have the same scrollbar, looking the same, no matter where. I always know where I can scroll my content.

So if at all possible, and if it doesn't angry any graphic designer, stick with what people know :) Unless you have a brilliant new idea, which is going to be a new revolution in scrolling!

Title: Custom vs. browser-native scrollbars

Body:
Including customizable, JavaScript-based scrollbars (and scrolling functionality in general, i.e. bind the control to the mouse scroll wheel) in your webapp can be a great temptation.

However all solutions I could find were developed by individuals (which can equal lack of formal or future support). In addition I fail to remember any mainstream site using them.

In my particular case, no-JavaScript or IE6/odd-browser environments are not intended to be supported.

Should custom scrollbars be avoided nowadays? If not, what's the best option one can choose?


答:
```<code>itemsList.ForEach(item => DoAction(item));
...
public void DoAction(Item item) {
  //...do various things here...
}
</code>```

Now, maybe here we are calling DoAction because its body is too long to fit within the lambda itself. In that case, using the ForEach() extension method to List doesn't give us a lot of benefit over using the regular foreach loop, though it does save a couple lines of code, I suppose. But in this particular case, using ForEach() may have lulled us into doing something that's actually taking more code, and causing some extra thrashing on the stack than necessary;
The Argument Passed Does Not Need to Be a Lambda At All

You should simply call DoAction like this:

```<code>itemsList.ForEach(DoAction);
</code>```

No Lambda at all. The key is to remember what it is you are really passing when you create a lambda expression: something of a shortcut to define a delegate instance. Yes, it also has benefits such as closure, but one should not lose site of what the method call is expecting. In this case, it's expecting an address to a method that matches the signature of Action. DoAction is already such a method, so creating the lambda is just adding in a totally unnecessary method call.

Body:
itemsList.ForEach(item => DoAction(item));
...
public void DoAction(Item item) {
  //...do various things here...
}

Now, maybe here we are calling DoAction because its body is too long to fit within the lambda itself. In that case, using the ForEach() extension method to List doesn't give us a lot of benefit over using the regular foreach loop, though it does save a couple lines of code, I suppose. But in this particular case, using ForEach() may have lulled us into doing something that's actually taking more code, and causing some extra thrashing on the stack than necessary;
The Argument Passed Does Not Need to Be a Lambda At All

You should simply call DoAction like this:

itemsList.ForEach(DoAction);

No Lambda at all. The key is to remember what it is you are really passing when you create a lambda expression: something of a shortcut to define a delegate instance. Yes, it also has benefits such as closure, but one should not lose site of what the method call is expecting. In this case, it's expecting an address to a method that matches the signature of Action. DoAction is already such a method, so creating the lambda is just adding in a totally unnecessary method call.


答:
You're in a bad situation, I wouldn't want to be in your shoes. It's unlikely that you could to sort it out without getting into conflict with your colleague.

This is what I would do:

Don't become his partner in crime. Refuse to lie about the status of your project or his project.

Implement (in your spare time if necessary) bug reporting to your application, so all bugs are sent by email to your coworkers and to your manager. If the bug is caused by his application, make it visible in the email (put [XYZ APP BUG] in email subject or something).

Maintain a bug database (besides sending bugs by email). You can say that its primary purpose is tracking your bugs, when in fact you'll be tracking mostly his bugs. Among other things, it should track how long it takes to fix specific bug.

Have all inter-process communication with his app covered with tests ("when I sent you this, you should return me that" style). You could set up a cron task which runs these tests every day and if they fail, email is sent to everyone.

Basically, try not to waste your time arguing with him about bugs and focus on your work instead. If his app is broken and thus you can't work on your app and manager doesn't do anything with it - well, that's a management problem and you're covered with bug database, emails and test reports.

However, watch out and don't underestimate him. Long-time slacker like him might have a trick or two up his sleeve. He can turn whole team against you or something, but that depends on your specific situation and it's kinda out of scope of this question.

Title: How do I deal with a slow and undedicated colleague in the team?

Body:
I have been working on a new project. The project works like this: The end user can access a webapp using a link and he can add multiple systems on his network and manage that particular systems details. My part involves the front end and the webserver, which is done in python. My python actually communicates with another project which is entirely done in c & c++. The c/c++ project is the main app which does all the functionality. My python sends the user request to it and displays the response from it to the user.

I am very familiar with my work and I will finish it soon. Since that's not much work in it. And I am a person who loves to work. I spends most of the time in office and only go home when I feel sleepy.

The c/c++ app is managed by another colleague who has 5+ year experience and can do things much faster than me, but he never does it. May be he doesn't like to do it. His app crashes often when my python communicate with it or returns wrong values. It's full of bugs. Since my app depends on it, I am having a hard time building it. Instead of fixing the bugs, he asks me to slow down my work. He asks me to tell manager that my work needs a lot of time. He is asking me to fool the manager and even forcing me to work slowly like him.

During project meeting, when manager asks him about the bugs he says that he fixed everything and it works fine. Since he is my colleague, I couldn't tell anything to the manager. I obviously need to have a good relationship with my colleagues more than my manager, since most of the time we will be with our colleagues, not with the manager.

I am not able to tell the manager anything regarding this, since if manager asks him why, then he may think I complained about him to the manager. And he keeps on lying in the meeting. And since he fixes the bug slowly, it even slows down my work. Now I thought of working on the front-end part of my app  and finishing it off so that in the mean time he can make his project stable. Now he is asking me to tell the manager that my front end part require a lot of work and I may need more and more time, simply so that he can drag the project down. And the sad thing is our actual manager has gone to the US, so we have a temporary manager and this guy doesn't know about the project much, so the c,c++ just fools him.

Can anyone suggest me how I deal with this?
I wanted to finish off the project soon. How can I make him work even by maintaining a good relationship with him?

Responses to comments:

If he's really deliberately misleading the company, you should report him to management.

I am new to this company and the other guy has been there for many years. And I have just started knowing my colleagues. If I directly go and complaint him, I don't think so I can make good relationship with my other colleagues. Even he has the power to mislead them. I am not telling he is a bad guy, he can do the work, but he is not doing it.

Doesn't your company have any kind of bug tracking system ?

Here actual bug tracking system isn't there. The company tries to finish off the project as soon as possible and gives it to the QA. And then fixes the bugs reported by QA.

This is why companies should give employees stock / options or some sort of ownership. That way you can literally tell the guy "You are costing me monetary growth... don't you want to make money also?".

The company has the stock options they have given me a 2500 share, mostly he too would have got some more.

Seniority does deserve some benefit of a doubt. You really need to speak to him first and try to understand the problem. He may be out of his depth, you may be able to help him, there could easily be variables you are unaware of. It may be hard now, but you could easily make the situation a lot worse by jumping the gun.

I even does it, first his app wasn't handling multiple requests at a time, he was using a queue to handle the requests I sent to him. I even suggested to him some of my ideas on it. He said he already had these ideas, and will be executing them. His explanations was: "Everything require certain time to do and this is a project which may need two years to complete and we are asked to finish it in two months". I used to have a hard time coding during first few weeks because of this bug. But now he fixed it. But he is using a single queue for a user requests and that is now slowing down the app, since it processes one request at a time.

What is QA doing this whole time? Why aren't they reporting/confirming the status of the project(s)?

The manager is the person who decides when to give to the QA. As of now it has not yet given to QA. He said we should give it by this month end.


问:
What to do with a not well organized application?
I'm a newly graduate programmer and just got hired before my graduation. In the office, I used to create and revise modules of some applications developed by other programmers in our company. The problems I encountered with their applications are:

Unnormalized database at it's best, they've broken all the rules of database normalization, Codd must be angry.

50% of the content of the database is literally NULL (they should have default value I swear).

One stored procedure is used in all database transactions, full of "if-else" statements.

They are reinventing the application settings in .NET WinForms, they create their own file which contains everything they want. I think they are very fan of VB6 or maybe they don't study really, they're guessing how to achieve something.

No error handling! Clients sometimes report "Exceptions" which they shouldn't be seeing.

Web files and Windows Forms are not organized or grouped according to their use.

Naming convention, there are Camel case, pure lower case, with and without underscores and abbreviations.

Bad programming practices like database transaction in each iteration of a loop.

They developed website with SQL injection in mind, they welcome them.

HTML elements were not used according to their sematics.

CSS are not optimized for different browsers.

They include several versions of jQuery in one HTML!

.
.
.

N. Many more!

The worst thing is, I felt being blamed for it's fragility. I mean, when I add code, there are times that it ends up with error, sometimes because they did not create constraints or they allowed duplicate data. The system is so fragile and dependent to one another, it's like walking in a field with landmines! (THIS HAPPENS SOMETIMES, THIS IS NOT THE REAL ISSUE)

What should I do?

答:
And just to add my 5 cents - from something like 20 years of experience, working for different people (many) and having others worked for me as well (or my team, whatever).

I'm leaning towards what the nillls said.

a) if it's too chaotic, I guess you could quit the job - but that's  not the answer - you won't be finding too many 'ideal' companies or old-code, it's always problems, either people or code,

b) work with it, the code, and with them, the people - slowly, try to assert your 'standards' (or any standards in this case : ) - and explain, talk w/ them.

c) don't try overhauling everything - as you can as well quit the job. Usually ends up bad - or worse everything ends up your fault, even if they're susceptible - you don't want that much responsibility, especially being rookie

d) try to understand why it's like it is - often, there's a real reason why real-life code is too messy - too little time, too many programmers etc. It's best if you can work 'with the system', explain with arguments (that what you're doing is going to save the money, maintain etc.). Also real projects are never fun - and people actually investing money hate to get suggestions from someone interested in making things 'beautiful' - that's what their side looks like - you need to make your case - and basically good s/w is what saves money, short or on a long-run, so work in that direction.

e) forget about coding 'properly' or getting kicks out of it - look at it as the job - you obviously have the necessary tech background - try to learn the ropes w/ these jobs - real pains, dealing exactly w/ situations you're in right now,, that's what most jobs are about, at least what I've seen : )

f) and practical, coding advise -

do 'facade' your code - db or otherwise

separate parts that you're doing from their code

I've learned that and that oftne works nicely - you have to integrate some parts, but given C# and all you can easily separate things.

...so, if you don't like db code - do a small 'layer' that you'd be using - for start, just copy and change things slowly - but you'd be building it properly, structure, safe standards and all (not always possible, but most of the time)

...that way also, you'd be able to separate from the errors a bit

if it's not relaly your error - then you should be albe to make a case of it
actually use that in your advantage to show them why old code makes problems, while your new one is working perfect

with around db that's harder (inside the db, design) - but you can always try and aks for, change things slowly, field by field, index by index etc.

and so on in this direction

and btw. this isn't the worst job in the world, get the best out of it, you can set your own standards, make bigger impact, learn other things

Best


答:
If you add your own custom scroll bars, users will have to wait and process it in their minds for a couple of moments -- before they can use it. This isn't always good -- you already have content on your site for users to see and comprehend, let everything else come off as expected.

Always try to make you site EASY to navigate. Beauty should not demand (or activate) cognizance.

Title: Custom vs. browser-native scrollbars


答:
What you have is a political problem. First your manager's opinion is far, far more important than you seem to think. This guy is blaming you for the delays and you are letting him. You are the one who will get fired if someone is thrown under the bus. As far as the manager knows, you are the one who is incapable of doing the work in a timely manner.

Protect yourself in any way that you can, through bug tracking, emails etc, but DO NOT go along with pretending this is your delay not his. Never give the boss a fake status report, it will come back to bite you. Tell the boss the truth about the problems you have (and show proof) with his code not working.

This person who is asking you to slack so he doesn't look bad is a snake (well that's an insult to the snake community (subtle Firefly reference), sorry to all the actual snakes out there). He will do anything at all to throw you under the bus instead of him. Do not trust him.


答:
Perspectives

Notice how Visual Studio remembers the layout of the IDE (open windows, positions, etc) that you used the last time the debugger was running? And how it switches between that and the "non debugging" IDE layout automatically.

Eclipse does the same with Perspectives. Only that you can fully customize them not only for debugging and not debugging, but you can create several layout with different IDE configurations and switch between them with a simple click.

Want to go to the debugging layout while not debugging?. Just click the on the Debugging Perspective toolbar button.

Want to invent a new layout with no editors and only the Package Explorer and the Javadoc view are visible? Move your windows as you want and save it as a new perspective.

It is a great way of switching your IDE appropriately when your mind is also switching from one kind of task to another.

Eclipse Help - Perspectives

Title: What features in Eclipse is not available in Visual Studio?

Body:
I have done much development in Java using Eclipse, and now I have started to use Visual Studio for .NET development. So far I find the IDEs to be able to do the same things, but just different.

What features in Eclipse isn't available in Visual Studio?


答:
What bug tracking system are you using? I would have expected that at least to highlight where bugs are not getting fixed in due time. Where your code is waiting on input from the other layer, the delays should be highlighted in project tracking documentation. Is this not happening either?

It sounds to me like there is inadequate project management here. You need to a) track the bugs that are affecting you and b) follow up discussions in writing.

Your colleague should not be asking you to inflate your development time to cover his lack of will. At some point, this is something which will have to be addressed with your manager. As things stand, you are covering up for your colleague and that will almost certainly backfire.


答:
I'm going to throw in a slightly controversial view: You say that you are working as many hours as you can stay awake. So maybe he's not being particularly unfair to say "you're making me look bad and I'm actually working as many hours as I'm willing to." Maybe he's been there and done that and maybe he burned out. I promise you that you will if you keep that up.

Go out for a drink with him one night and see if you can't build a better personal relationship on which to base your professional. Maybe by his agreeing to put in a bit more and your agreeing to put in a bit less, you can both work together much better.

If I were you, I would also be very careful of this whole "my work, your work" attitude. Between the two of you, you have a product to get out there and this cannot possibly be good for that product, which in turn is not good for either the company or the customer and they pay for both of you to work.

However, I still agree with the other views that you need to revisit the importance of your relationship with your manager and you need to be careful of trusting your colleague. I'm just saying that maybe, just maybe, you need to look at your own actions as well as his.


答:
First and foremost:

Since he is my colleague, I couldn't tell anything to the manager.

You absolutely can and should make sure your manager knows the truth, even if your co-worker is lying to his face. If you don't want to say anything in a meeting with all 3 of you in the room, that's totally understandable. But you should at least pull your manager (the real one, not just the temp) aside and let them know that your work is almost done and is waiting on bug fixes from the other developer's end before the whole application is ready for prime-time. Don't accuse your co-worker of lying, but don't sit there and let your boss operate with incomplete information.

Report your statuses honestly. If your work is being held up by bugs on another developer's end, document that you've found bugs in the C/C++ and have reported them (please tell me you're using some form of documentation that leaves a paper trail).

In the meantime, go ahead and wrap up your work, and let your boss know when you're done. If your manager wants to know why the rest of the project isn't up and running yet, you can refer him to the other developer, and maybe mention that it's probably very complicated/large/requires a lot of testing/other developer is very busy/etc. If you know C/C++, you can offer to help on the main application logic to get things moving with that as well. Yes, you'll be doing the other guy's work, but it makes it clear that you're the employee working hard and being productive, and the other guy isn't, not to mention making you even more valuable to your boss. It may even put some pressure on the other developer to step things up and get them done quicker.


问:
How to you solve the problem of implicit locking and parallel execution?
Where the code is:

```<code>function A()
{
    lock()
    doSomething()
    unlock()
}
</code>```

We can call A safely from multiple threads, but it never be executed in parallel . For parallel execution, we have to evade all of this code.

But the problem is we never know the A is getting lock or not. If we have source code (maybe lucky case), we have to decode all code to know locking is happening or not. This sucks. But even worse is we normally have no source code. And about the case of the lock is exist on base library?

It's obvious this kind of hidden locks will become bottleneck of parallel execution even all the other parts are designed for parallel.

And also, (1) With locks, execution cannot be parallel. (2) And I can't know whether the locks are used or not in any code. (3) Defensively saying, I can't make parallel anything!

This facts drives me crazy. How do you solve this problem?

答:
If you call A concurrently from multiple threads, one of three things will happen:

1) The threads will not actually block each other because they won't try to acquire the lock at the same time. In this case, they will still run concurrently and there will be no problem.

2) The threads will conflict on the lock and one of the threads will no longer be ready to run. In this case, the operating system will schedule some other thread that doesn't require that lock, in which case those threads will still run concurrently and there will be no problem.

3) Once all the threads that don't need the lock are scheduled, there are still idle cores. Only a thread that requires the lock can be scheduled on that core. But this only happens when everything you need to do required calling that function.

In other words, you only need to worry about this in the 5%-10% of your code that's performance critical. And you have to know that code inside out anyway, for obvious reasons.


答:
The problem seems to be that junior developers and others don't necessarily understand what the function pointer\delegate\lambda function concept is

Then they need to learn them. Period.

This is not an esoteric corner of C#. You must understand them to make use of many .Net libraries.

This is not an esoteric language topic, in general. Virtually every language in popular usage today has some flavor of function pointer, and most have (or are soon getting, in the case of Java and C++) closures.

Just take a few minutes to explain it to them. It's not hard.


问:
Non-transactional Database and Integration Testing
One issue I think I am going to run into with my integration testing is having multiple tests accessing the same database.  While this is not a problem now, I know we have multiple applications here that access the same database and I am just trying to think of a way to prevent this issue before it happens.

An idea I have seen a lot is using transactions.  In the start up you start a transaction and then in the teardown you rollback the transaction.  This means that multiple tests accessing the same database tables and will not effect each other which is great.  The issue I have is that in my case, 85-95% of the tables I am working with in MySQL are MyISAM which don't support transactions.

Are there any ways to get around storage engines that don't support transaction but still allowing multiple test to access the same tables without them effecting each other?  From what I hear, the ruby on rails testing framework uses transactions in this way, how do they get around this issue (or do they)?

答: Even if you do not have "transactions", in the T-SQL sense, you should still strive to make your transactions (in the general sense of the term) atomic. The tests should not rely on eachother and they should be reversable. If you do not have any official rollback or transaction scope, then you might want to make your own. For example, you could have your unit tests perform a clean up, where they delete all the records that were created in the test. </p>


答:
I'd like to point out another possibility that hasn't been raised. You say that he wants you to slow down your work. Do you mean literally he is saying "work less hours" or that he is saying "write some tests, test this more, write some documentation" and other things you think will slow you down? I have seen new people run around writing code for 16 hours a day and then complain of bugs in the code they're calling when in fact they're passing invalid parameters, they're not checking return values, and so on. I can't rule out that your co-worker is thinking these things.

The next time you are in a meeting and he says all his code is fine, say "oh, good, the thing I told you about an hour ago, where it blows up when I call XYZ with a date that's not a working day, is fixed now?" One of three things will happen:

He will lie, and say there is no such problem, you will say "there is so! We discussed it! I emailed you!" and the whole thing will come to a manager's attention

He will tell you that in fact, that isn't a bug in his code, it's a bug in your code, because you're only supposed to pass working days, and you will soon find out what he's been thinking but not saying

He will say "no, that one you just told me about I'll deal with today, but everything else is good." If he says that, just thank him for now.

You may learn that your long days of fast coding are not producing good code, and someone (your manager maybe) might translate for the other developer to explain to you what the issue is. Or, you may learn that you are working with a lying snake who will make you look bad to protect his cushy position. Bringing things out into the open can't really make that worse. Or, you may just get enough movement from him that you can stand it, without getting caught up in the politics.


答:
Nothing wrong with sticking up for a collegue, but for someone to expect you to lie to your boss on a daily basis has to go. I could not respect him as a person and would have no desire to have this person as a casual acquaintance. He wants to be an enemy, bring it on.

How can you argue delays on the application layer because of the front end? That's why you do this so they can be separate. What's next, he has even more delays because someone wants to build a mobil front end?

Get your work done. Document any issues you're having with a failure on his app. And then GO HOME! I don't care if you're sleepy or not. Find some friends worth having.


问:
Implementing a machine learning algorithm to detect the region of an address
I have 10,000 addresses from a city, which all have a region field in the database.
When a new address is entered, then I want my software to automatically detect the region of the address .

I think it should be implemented with some sort of machine learning algorithm. How can I do this?

And with every newly inserted address, the machine should learn to detect the region of the new address.
Is there any library for machine-Learning algorithms (like aforge.net for neural networks)?

答:
If your addresses are poorly formed, like this extreme example:

```<code>    John Q. Public
    Lives on the coner of west and main
    The city 20 miles east of New York.. Sally is the mayor
</code>```

I would suggest looking into a natural language processing toolkit like OpenNLP.  Then, you could build up a corpus of these poorly formed addresses and train the algorithm on the corpus.

But in most cases, Falcon is right, and there's no need to involve AI.

Body:
If your addresses are poorly formed, like this extreme example:

    John Q. Public
    Lives on the coner of west and main
    The city 20 miles east of New York.. Sally is the mayor

I would suggest looking into a natural language processing toolkit like OpenNLP.  Then, you could build up a corpus of these poorly formed addresses and train the algorithm on the corpus.

But in most cases, Falcon is right, and there's no need to involve AI.


答:
Two possible scenarios:

a) Your colleagues (or most of them) are reasonably skilled. They need to learn lambdas, they're part of the language, and sometimes, they are exactly the right tool for the job. So when they are indeed the best tool, by all means, use them. Just avoid using them because you've only just learned about them yourself and you're all excited and think they're a silver bullet.

b) You colleagues (or most of them) are incompetent. There is no way they're ever going to fully understand lambdas, closures, function pointers, or any other similar meta-coding concept. They're probably struggling to understand pointers, references, and recursion already. In this situation, the best you can do is bite the bullet, use a clumsy, verbose, lambda-free solution, and brush up your cv, because you should be job-hunting.


问:
What happened to Borland Delphi?
I have the impression that Delphi isn't very popular anymore. But now at work I had to make some changes to an old Delphi program that we are still using. I used Borland Developer Studio 2006 and it was very pleasant and intuitive to work with, even though I had practically no previous exposure to it. Is Delphi still widely-used and I am simply not aware of it or are there other reasons for its decline? </p>

答:
I have used Delphi since Version 1, and introduced it to my workplace. At the time, we were using Visual Basic 3 for most of our Windows development, and I found that Delphi was head and shoulders above VB 3 for our needs.

When it came time to move from 16 to 32-bits, our development team took the opportunity to change the architecture of our product and separate the UI from the calculation engine. It was at this time that we switched from VB to 100% Delphi.

What has caused Delphi's decline over time? I think that many of the posts have covered several of the facets involved: Borland ne' Inprise ne' Borland's loss of focus on their core supporters. Later on, it was widely known that Borland was attempting to sell Delphi to an outside company, which never inspires confidence in your users.

After CodeGear acquired it, I think that the lack of a 64-bit compiler may have hampered it's adoption. I eventually gave up waiting on a 64-bit version of the compiler from CodeGear, and ported our company's calculation engine to the Free Pascal Compiler (FPC) so that we now support the 64-bit Windows as well as 32/64-bit Linux platforms.

I am really looking forward to the upcoming Delphi XE2. With support for 64-bit Windows AND OSX and iOS platforms (iOS support is due to FPC), it is the first Delphi release I have been excited about in quite some time.

Title: What happened to Borland Delphi?


答:
I think it should be implemented with some sort of machine learning
  algorithm.

Nope

How can I do this?

Use a shapefile with polylines of the regions (they are more or less files full of coordinate pairs with a bit of metadata associated). Use something like the Google Maps Geocoding API to geocode the address (you send an address, and it sends back a coordinate pair). Write a simple algrithm* to determine which polygon from the shapefile the geocoded coordinates lie within. You can find shapefiles all over the web, especially from government agencies such as NOAA. The USGS has a decent collection too. I believe this solves the problem without breaking any of the laws of robotics, so I would not even bother with an AI-oriented solution. :)

*I would start here for a good reference to get you started. Also, do not forget that the earth is curved, so distance calculations work a bit different than on flat plane (think radians).

Title: Implementing a machine learning algorithm to detect the region of an address

Body:
I have 10,000 addresses from a city, which all have a region field in the database.
When a new address is entered, then I want my software to automatically detect the region of the address .

I think it should be implemented with some sort of machine learning algorithm. How can I do this?

And with every newly inserted address, the machine should learn to detect the region of the new address.
Is there any library for machine-Learning algorithms (like aforge.net for neural networks)?


答: I think that replacing scroll bars is not a good idea. When you are used to an os and browser - scrolling does not require much input from your brain. Having nicely designed ones is awesome but you will confuse your customers. Is the added value enough to offset the annoynance for the fist few times they use it. </p>

Title: Custom vs. browser-native scrollbars


问:
What's so bad about creative coding?
I was watching Bob Ross paint some "happy trees" tonight, and I've figured out what's been stressing me out about my code lately.

The community of folks here and on Stack Overflow seem to reject any whiff of imperfection.  My goal is to write respectable (and therefore maintainable and functioning) code, by improving my skills.  Yet, I code creatively.

Let me explain what I mean by "coding creatively":

My first steps in a project are often to sit down and bash out some code.  For bigger things, I plan a bit out here and there, but mostly I just dive in.

I don't diagram any of my classes, unless I'm working with others who are creating other pieces in the project.  Even then, it certainly isn't the first thing I do.  I don't typically work on huge projects, and I don't find the visual very useful.

The first round of code I write will get rewritten many, many times as I test, simplify, redo, and transform the original hack into something reusable, logical, and efficient.

During this process, I am always cleaning.  I remove unused code, and comment anything that isn't obvious.  I test constantly.

My process seems to go against the grain of what is acceptable in the professional developer community, and I would like to understand why.

I know that most of the griping about bad code is that someone got stuck with a former employee's mess, and it cost a lot of time and money to fix.  That I understand.  What I don't understand is how my process is wrong, given that the end result is similar to what you would get with planning everything from the start.  (Or at least, that's what I have found.)

My anxiety over the issue has been so bad lately that I have stopped coding until I know everything there is about every method for solving the particular problem I am working on.  In other words, I have mostly stopped coding altogether.

I sincerely appreciate your input, no matter what your opinions are on the issue.

Edit:  Thank you all for your answers.  I have learned something from each of them.  You have all been most helpful.

答:
Two perspectives:

Nobody has to maintain a painting.

Anyone who has ever watched Bob Ross paint a painting knows that paintings have structure. If you were going to take one lesson away from Bob Ross, it'd be that planning ahead and working in an organized manner makes the process go smoothly and look simple.

Title: What's so bad about creative coding?


问:
What exactly undefined means in JavaScript? Why it's there? What usages it has? How it could be useful?
In JavaScript, we have something called undefined. I said something, because I really don't know if it's a base class, or a built-in variable, or a keyword, or anything else. I just know that it's there.

To see it in action, you can simply write:

```<code>undefined;
typeof undefined;
</code>```

Can anyone please explain to me why this thing has been inserted into JavaScript? We have null value in this language, thus it shouldn't be something like null. In other languages, when we don't know the value of a property or variable, we simply set it to null. Here we can do the same thing.

How we can use this thing in JavaScript?

答:
There is a global variable undefined, which is set to the undefined value. Evil people may set it to something else, so it's probably best not to trust it.

The undefined value is the return value of a function that does not return a value.

The undefined value is the value of a variable that has not been assigned.

The undefined value is the value of a parameter that has not been passed.

The undefined value is the value of a property that has not been assigned.

'undefined' is the type of an undeclared variable. (typeof undeclaredVariable == 'undefined'. trying to read the value of an underfined variable will get you a thrown ReferenceError.)

null is subtly broken, because typeof null == 'object'. I don't know why we have undefined and null, probably some historical accident.


问:
What non-programming books should a programmer read to help develop programming/thinking skills?
There are a lot of questions about what programming books should be on the programmer's bookshelf. How about non-programming related books that can help you become a better programmer or developer? It would also be interesting to know why they would help.

My first choice would be Sun Tzu's "Art of War" (however cliché), because it made it obvious that the success of any project depends on the strength of its weakest link (and warfare is a big project).

答:
The Back of the Napkin, by Dan Roam.

The Back of the Napkin http://www.coverbrowser.com/image/bestsellers-2008/302-7.jpg

A great book about visual thinking techniques.  There is also an expanded edition now.  I can't speak to that version, as I do not own it; yet.


问:
How do I partially add PHP namespacing to a library without breaking existing code?
My company has created a modular PHP framework over the years, beginning long before PHP 5.3 added namespaces. Recently, we decided to start using namespaces in our library's new code, and we intend to namespace old code eventually. However, we have a few issues we are trying to work out to determine if adding namespaces to a pre-v5.3 codebase is just not a good idea:

Can I namespace a class but also import (use) the global namespace so all global classes do not need a \ prefix?

If we namespace an existing class in our library, how can we prevent all existing projects from breaking as soon as the framework upgrades? For example, can the library change the name of class ThemeEngine to \module\theme\ThemeEngine, but the existing websites call ThemeEngine without any code modification? If so, what would that code look like?

答:
You can't 'use' namespaces at all, sadly, only classes: http://www.php.net/manual/en/language.namespaces.importing.php.
Edit: You can import classes from the global namespace, like they did with the ArrayObject in one of the examples.

You could have a global section of use statements so that all pre-existing classes, which are in the global namespace as well, theoretically should find the classes just fine. Theoretically...

We are in the same boat as you, sort of. We have some old code that doesn't use namespaces, but does use the _ namespace faker (like Zend_Db_Table...) and we have some older code that doesn't even fake namespaces. We're probably going to take the same route, but we still need to test if it's possible at all. Good luck!


问:
How old is "too old"?
I've been told that to be taken seriously as a job applicant, I should drop years of relevant experience off my résumé, remove the year I got my degree, or both. Or not even bother applying, because no one wants to hire programmers older than them.1

Or that I should found a company, not because I want to, or because I have a product I care about, but because that way I can get a job if/when my company is acquired.

Or that I should focus more on management jobs (which I've successfully done in the past) because… well, they couldn't really explain this one, except the implication was that over a certain age you're a loser if you're still writing code. But I like writing code.

Have you seen this? Is this only a local (Northern California) issue?

If you've ever hired programmers:2

Of the résumés you've received, how old was the eldest applicant?

What was the age of the oldest person you've interviewed?

How old (when hired) was the oldest person you hired?

How old is "too old" to employed as a programmer?

1 I'm assuming all applicants have equivalent applicable experience. This isn't about someone with three decades of COBOL applying for a Java guru job.

2 Yes, I know that (at least in the US) you aren't supposed to ask how old an applicant is. In my experience, though, you can get a general idea from a résumé.

答: The average age of developers where I work is 50. Some of the best programmers I know are way over 50. I've seen that kind of stupidity in other countries (not naming names here) but here so far so good (fingers crossed).</p>

Title: How old is "too old"?


问:
Why do so many libraries have no/poor documentation?
In a similar vein as the How can open source projects be successful without documentation about their design or architecture? question, I'm curious: Why are so many libraries so lacking in end user documentation?

My view is this:

Most everyone agrees that reading source code is more difficult than writing source code.

Without documentation, one must read the library's source code in order to use that library.

Therefore, using the undocumented library is more work than just recreating the library from scratch.

As a result, if you want to have people use your library, you'd damn well better make sure it's documented.

I know lots of developers don't like writing docs, and I'll agree it can be tedious work. But it's essential work. I'd even say it's more important that a library have good documentation than have the best programmer's interface in the world. (People use shitty libraries all the time; few use undocumented libraries)

Oh, note that when I say documentation, I mean real documentation. Not Sandcastle/Javadoc/Doxygen boilerplate.

答:
The person who is best qualified to write documentation is also the person who has the least motivation for doing so:

he (or she) is:

primarily a maintainer of the library, rather than a user. So the smaller and simpler the library is, the easier his job. Maintaining half a novel in addition to the code only makes his job harder,

he knows the library inside out, so he doesn't need the documentation,

he's a programmer, he wants to write code, not documentation.

I can't think of anyone who's less likely to go "Hmm, I really should spend a few hours writing some proper documentation for this". Why would he?

And of course, it probably doesn't help that there's this urban legend going around that autogenerated doxygen-style comments are all you need in terms of documentation.

So even in the rare cases where a developer is actually willing to write documentation, it's a 50/50 chance that the developer has been brainwashed by this cult into thinking that all that is needed is filling out a few such comments, telling you gems like that "the function Foo getFoo() returns an object of type Foo, and it is used to get the Foo object".


问:
Why do websites have to ask language and country when the browser can tell them that?
So, why do websites have to ask (spoken) language and country when the browser can tell them that?

Edit:
Specifically, I mean why not use the accept-language section in the http header, set by the language settings in the browser, not based on the IP address.  This question focuses the websites that put up a wall, forcing the user to select a language before using the website, that should instead make available an easily accessible setting.

Edit:
This is a user experience question, focused on the point that the user should have set the language settings in the browser when they first set up their computer (if the user is smart enough, or can ask someone smart enough).

答: Right now I am browsing this website through my company's VPN which gives me an English IP. While I am in fact a native Hungarian, working physically from Hungary. Is this a good enough example? ;-)</p>


答:
Documentation? We don't need no stinkin' documentation!

I know how the code works, so why would I spend time documenting my code? Besides that, I've got to have this project done by Friday and I'm barely going to make it as it is ...

Title: Why do so many libraries have no/poor documentation?

Body:
In a similar vein as the How can open source projects be successful without documentation about their design or architecture? question, I'm curious: Why are so many libraries so lacking in end user documentation?

My view is this:

Most everyone agrees that reading source code is more difficult than writing source code.

Without documentation, one must read the library's source code in order to use that library.

Therefore, using the undocumented library is more work than just recreating the library from scratch.

As a result, if you want to have people use your library, you'd damn well better make sure it's documented.

I know lots of developers don't like writing docs, and I'll agree it can be tedious work. But it's essential work. I'd even say it's more important that a library have good documentation than have the best programmer's interface in the world. (People use shitty libraries all the time; few use undocumented libraries)

Oh, note that when I say documentation, I mean real documentation. Not Sandcastle/Javadoc/Doxygen boilerplate.


问:
Charging for a project where you retain the IP for the end product
I have read up on quite a few of these questions asked on here regarding "how much should I charge for..." such as:

How should I charge for programming things which take two minutes to fix?

https://softwareengineering.stackexchange.com/questions/52954/how-much-should-i-charge-for-a-web-app

https://softwareengineering.stackexchange.com/questions/27947/how-much-can-i-charge-for-this-a-little-job/27956#27956

and these are fine for freelance projects dealing with specific clients for a specific product. My situation has a bit of a curve-ball to it, and this is: how much should I charge a company to develop a product where I retain the 'Intellectual Property' of the final product.

I am working with a company to create a web application that will help with some administrative processes. The idea for this project had originated between me and an employee of the company outside of business hours. Thus the product idea was then presented to the company and they are very interested in me developing this idea  for them.

The CFO of the company wants to pay me for my time to develop this product, yet I would also like to own the IP of this product and resell it to other companies when it is completed.

When we do meet to discuss fair wages, what would be the best way to position myself? Presumably in the future with a completed product this would be a 'fee for service' software platform, wherein a company would purchase seats (monthly or annually). But I am unsure of how I should treat this development 'partner'. Their contributions would include helping me tailor the product to fit their needs specifically, along with debugging and testing.. So should I charge an hourly rate? A lump sum? Or start out right away with a monthly subscription type?

This project is done on the side, I still have a day-job.. But will be investing a lot of time into this project since it has a lot of potential. (if that factors into any of it)

答:
I don't know if there is a standard for this, it's pretty rare, but I've seen either hourly or fixed price (I suggest hourly if they offer - you won't spend your time arguing about what was included in the price), but at a lower rate to make up for the IP.  Also I've seen giving the client a percentage of revenue from the software for a while, to give them some interest in the product as a whole and as something to exchange for retaining the IP.

But I think everything is negotiable, and you may not need to offer any of that (they may only care about the IP in terms of being able to use the software themselves).  Mostly your goal is like any contract: to get the contract, limit your liability, limit your scope of future commitment to something reasonable, make everyone's responsibilities clear, etc.  In this case you also want their help in developing and promoting the product, and to make sure your rights to the IP are clear.

I don't think the plans for future pricing model have to influence the immediate pricing model.  I think hourly rate cuts the risk of you committing to more work than you are paid for.  You probably can't charge by the hour for development plus charge your original client a fee for service, but you can and should charge for your expenses in time and/or hosting costs so that you don't have an open ended unpaid commitment.


答:
Several reasons:

The person using the browser may not speak the language that the browser uses. (Say, someone who is French on an English machine...)

The location/language information may not be accurate (for any number of reasons: VPN, proxy, etc.)

You could call it laziness on the part of the developer(s), EXCEPT that it is always best not to ASSUME, and that I might very well be interested in a country / language other than the one my browser is in.

Title: Why do websites have to ask language and country when the browser can tell them that?

Body:
So, why do websites have to ask (spoken) language and country when the browser can tell them that?

Edit:
Specifically, I mean why not use the accept-language section in the http header, set by the language settings in the browser, not based on the IP address.  This question focuses the websites that put up a wall, forcing the user to select a language before using the website, that should instead make available an easily accessible setting.

Edit:
This is a user experience question, focused on the point that the user should have set the language settings in the browser when they first set up their computer (if the user is smart enough, or can ask someone smart enough).


答:
No.

This perception comes from programming having a huge surge of new entrants over the 1990s and onwards. Until the 1980s it was a fairly small, niche profession, but then suddenly in the last 20 years it exploded - and barring some older career changers - most people who went into it were young.

So basically: the average age of programmers will go up as this initial bulge of 1990s+ entrants to programming gets older. Obviously some will move on to management or change careers, but not enough to prevent this inevitable demographics shift. Also: after the dot com bust fewer young people were studying programming, which means that the entry of young blood slowed down somewhat.

Think of it like the demographics of a developing country: huge birth rates, high death rates, huge bulge of young population. When the country gets more developed, people start living longer and generally having fewer children.

So anyway, if you are 35 now, by the time you're 40, 45, 50, etc - the average age of programmers will have followed you up towards these levels as well. It's a temporary demographic blip, not a permanent fixture of programming as a profession.

Title: How old is "too old"?

Body:
I've been told that to be taken seriously as a job applicant, I should drop years of relevant experience off my résumé, remove the year I got my degree, or both. Or not even bother applying, because no one wants to hire programmers older than them.1

Or that I should found a company, not because I want to, or because I have a product I care about, but because that way I can get a job if/when my company is acquired.

Or that I should focus more on management jobs (which I've successfully done in the past) because… well, they couldn't really explain this one, except the implication was that over a certain age you're a loser if you're still writing code. But I like writing code.

Have you seen this? Is this only a local (Northern California) issue?

If you've ever hired programmers:2

Of the résumés you've received, how old was the eldest applicant?

What was the age of the oldest person you've interviewed?

How old (when hired) was the oldest person you hired?

How old is "too old" to employed as a programmer?

1 I'm assuming all applicants have equivalent applicable experience. This isn't about someone with three decades of COBOL applying for a Java guru job.

2 Yes, I know that (at least in the US) you aren't supposed to ask how old an applicant is. In my experience, though, you can get a general idea from a résumé.


问:
When would someone be considered a bad programmer?
How would you consider that a programmer is bad at what he or she is doing?

If possible... How should he/she improve?

答:
I am moving my answer to here from a closed duplicate topic that asked Can you recognise if you are a bad programmer?  The other topic was being closed as I was composing my response.  My answer more directly addresses the question as it was phrased by the other asker and will read better if you understand that.

Sigh!  Part of me didn't want to add to this already busy topic, but the other part of me won!  Why did it win; why am I bothering to add yet more words to this particular multilogue?  Well, because, to some degree, I may have a slightly different take on this than the many previous commentators.

Binary works great in computers:  it's '1' or '0', "on" or "off."  We can abstract and encode a lot of information using those famous two states.  But, it doesn't tend to work so well for human matters:  "good" or "bad," "sane" or "insane," "good" or "evil," "smart" or "stupid," "fat" or "thin," "alive" or "dead?"  These kinds of polarized evaluations have always left the caring human being part of me terribly unsatisfied.  By whatever measurement schemes I choose to apply, I usually find that the answers to such stark contrasts actually lie somewhere along a continuum between one such pole and the other, not at either end.

I have fought with this tendency towards polarization for quite some time, now, and my personal solution is that I find it far more useful to apply three words to any such evaluation:  "to what degree!"

So, my answer to your question is to suggest that you rephrase it and to ask yourself this:  "To what degree am I a bad programmer?"  Or, even better, to ask it in the other direction: "To what degree am I a good programmer?"  If you pursue truth, you will probably locate yourself somewhere along a continuum between being a "bad" programmer and a "good" one.  Then, once you manage to locate approximately where you are along this path, you can probably identify a point somewhat closer to the "good" end—a point where you would like to find yourself in the near future.

If you do not set that point too far away, you can probably get your hind end in gear and start moving it in that direction.  If you manage to iterate this rather simple heuristic algorithm several times, you may soon find yourself too busy programming to need to ask this question again!  Oh, and you'll probably make faster progress if you start pounding code on a keyboard as quickly and often as you can; and, if you take a little break now and then, read some high quality code written by your peers!  In these days of dynamic Open Source development, you have no shortage of free and exquisite code to learn from!

So, I strongly recommend to you that you try my three little words, "to what degree," and see how far in a good direction they can take you!


答:
The browser can have conflicting information though.  What if the IP is in one country but the accept-language is something else?  For example, while I am in Alberta, Canada, I am very used to seeing computers being set to "en-US" so that the US will load even though I am in Canada.  Which piece of data should trump the other?

While it may be trivial, if you can't give the algorithm to determine which country is right then that is why the site has to ask as it can't determine the answer with any confidence.  It is just as simple to take a new PC in any country and wonder if it defaults to US English for a language though I wouldn't say that I've tried that outside of Canada.


答:
When in doubt, ask.

Among other things, the browser does not always get the information right. My locale on my computer is set to the United States but the language on my computer is German.

I regularly use two different browsers at the same time. One seems to go by my set locale and the other goes by the language I use.


问:
Influences on the design of Dynamic objects by Alan Kay
Alan kay in his paper, The power of Context pdf link, page 8, enumerates some of his motivations for dynamic objects. Some of the influences like Paper on lisp, early paper on the design of functional computers, Moleculer biology of the gene (he envisioned objects as biological cells) are somewhat clear and I see the point. However, some of the influences like

Paul Halmos, Finite-dimensional Vector Spaces,(Clue: Algebra in the Large, he says). I want to know how has algebra influenced dynamic objects?
Are there any examples of algebraic structure in the objects?

Carnap, Rudolf, Meaning and Necessity, A Study in Semantics and Modal Logic. How's modal logic helpful in defining dynamic objects. How was this work helpful?

Kleinrock, Leonard, Communication Nets: stochastic message flow and delay. It seems like this work influenced early implementations of smalltalk. Has it git something to do with analogy between messages. Any explanation would be really helpful.

In short, I want to understand how these works influenced design of dynamic objects as envisioned by Alan Kay. I'd really appreciate any help on this.
I understand that viewpoints are highly subjective,but I'd also appreciate new insights/guesses as to how you think these works would have helped.

答:
here's my take on that.

Vector space well to start with, vectors are all different but share same attributes and operations which makes me think of instances of some class. Also, there are linear maps and transformations which somehow bring to mind an image of an object changing its state while keeping its identity.

Modal logic that one seems tough. Best I can come up with is probably mapping modals qualifying the truth of a judgment to subclass-superclass concept. Judgement "John is happy" maps to superclass API "isHappy": John.isHappy() returns "somehow". isHappy can be qualified in subclass with modality "usually" ParticularKindOfJohn.isHappy() returns "usually". In other subclass, it can be qualified using other modality:  OtherParticularKindOfJohn.isHappy() returns "never"

Communication Nets: stochastic message flow and delay that one almost immediately clicked with the concept of Smalltalk objects exchanging messages

YMMV


答: A programmer who just copies and pastes code from other places, and doesn't understand how the code actually works, is known as a bad programmer! I typically see this with javascript.</p>

Title: When would someone be considered a bad programmer?

Body:
How would you consider that a programmer is bad at what he or she is doing?

If possible... How should he/she improve?


答:
Adding to the other answers, because in some countries people don't speak the same languages (think about Switzerland where some people speak French, others German, others Italian).

Also, if you are in Vatican City, should pages be displayed in Latin? :P


问:
Synonyms for operators
In the case of a newly designed functional language, consider e.g. the not equals operator, spelled /= as is common among functional languages.

Of course this operator is also known as != in C family languages, and <> in SQL et al. It would be easy to make the parser accept these as synonyms, in the hope of cutting down on the number of things for someone not very familiar with the language to trip over. But on balance is this a useful thing to do, or would it just add more confusion than it's worth?

Most mainstream languages don't provide synonyms, probably on the basis that they're designed for programmers who are familiar with the syntax.

But what if you're designing a scripting language, for scenarios in which many users will not be very familiar with it, and may be specialists in something other than programming? Does that tip the balance in favor of providing synonyms to make things easier for newbies?

答: Pick one and stick with it. There are a number of things one has to get used to when switching languages. Compared to the other things you will need to deal with, this is one of the smaller ones. Having synonyms will just lead to confusion when two people normally use different symbols but end up on the same project. It is easier to change to knowing X means Y rather than being able to use my normal Y, but remembering that X and Z could also be used in it's place.</p>

Title: Synonyms for operators


答:
I have pondered much the same thing in the past.  While learning Haskell, I simply could not remember that /= didn't mean "divide by and assign back to".  But, you make the mistake... compile, curse the language, recompile, rinse, repeat, until... suddenly, one day, you aren't cursing the compiler anymore - or making the mistake.  Now, I only get confused when I've been working in C all day.

In the end, if your language FORCES the programmer to do things a certain way, then that's how they will do it - and if it means that users curse your name while they're learning, then I would humbly submit that this is better than those users cursing the names of everyone they're working with, while their in the room with them, because they all used different operators for their code.  Talk about a lousy code review.

Title: Synonyms for operators

Body:
In the case of a newly designed functional language, consider e.g. the not equals operator, spelled /= as is common among functional languages.

Of course this operator is also known as != in C family languages, and <> in SQL et al. It would be easy to make the parser accept these as synonyms, in the hope of cutting down on the number of things for someone not very familiar with the language to trip over. But on balance is this a useful thing to do, or would it just add more confusion than it's worth?

Most mainstream languages don't provide synonyms, probably on the basis that they're designed for programmers who are familiar with the syntax.

But what if you're designing a scripting language, for scenarios in which many users will not be very familiar with it, and may be specialists in something other than programming? Does that tip the balance in favor of providing synonyms to make things easier for newbies?


答:
I believe that when learning a language, the biggest issue is not learning the operators. This is (usually) only a fairly small part of the syntax, which in itself is the smaller part of the whole task. Most competent programmers can write syntactically correct code in a new language after a couple of hours or days. However, the more difficult part is to understand and experience the inner logic of the language, to be able to produce elegant and simple solutions, to use the language constructs the way they were meant to, rather than abusing the language by trying to make it work like another, more familiar one.

And having many (any) imaginable versions of operators in a language has drawbacks too:

it makes the grammar more complex, thus making the task of compiler / interpreter writers more difficult (which means they will have less time to develop new features for us),

the same operator symbol may mean different things in different languages, e.g. your example /= would mean "divide and assign" to a programmer grown up on the C family,

using different notations to mean the same thing makes programs more difficult to read, and consequently, to maintain. One's brain just needs to use some extra capacity to map between those different representations (and a little extra work many times over can add up to significant amounts...), so less capacity remains for the really important stuff.

Title: Synonyms for operators


问:
Is it a good idea to use Header("Content-Type [...]"); in the core file of a CMS?
I have been working on content management systems for about 7 years. 2 years ago created my own. Currently building a newew, better and bigger version.

However, fell into dilemma. I have a core file, that gets included to all pages. Core file makes sure of adding functions, config, mysql connection etc. I also have added Header("Content-Type: text/html; charset=UTF-8"); on the top of the code in the core file.

Recently I had to make a xml-generator, with Header("content-type: text/xml; charset=UTF-8");. First, of course I couldn't get the xml working, because I forgot about my content-type setting in the core file.. Later I just added the content-type: text/xml after the core file include..

Basically everything works, but I wish polish this project to the finest.

So I'm thinking now, is adding the "content-type: text/html" in the core file, a good idea?

I had an idea, to include the core file like this: include($rootpath . 'inc/core.php?content-type=xml');, then in the core file, the header will be set based on the $_GET['content-type'].. Is that a good solution?

答:
Instead of having the include() implicitly produce a bunch of stuff including header(), you could have it provide a startResponse() function which can take an array of extra headers to provide (useful if you also want to add e.g. cache-control, content-disposition, etc. at some point).

If you want to get really fancy you could probably have the include also call ob_start, have startResponse() call ob_end_flush() after it emits the headers, and then have an object (constructed in the include) have its __destruct call startResponse() if it hasn't been called already.