问:
What the correct algorithm to invert italics in a mixed text?
The question motivations was depicted in the section below.
There are many ways to make text italic,
so, perhaps, there are more than one good
"swap italics algorithm".
The problem reveals some aditional
dificulties in a XHTML code, and using the  tag, that must to be balanced.
Example:

Several more Homo sapiens fossils were discovered.

Several more Homo sapiens fossils were discovered.

```

<p>So, looks like this,</p>

<ol>
<li><p><em>Several more</em> Homo sapiens <em>fossils were discovered</em>.</p></li>
<li><p>Several more <em>Homo sapiens</em> fossils were discovered.</p></li>
</ol>

<hr>

<h1>Algoritms introduction and discussion</h1>

<p>For "<strong>layout solution</strong>", the simplest algorithm is checking the <code>font-style</code> CSS-property of all text blocks,
and invert them with jQuery:</p>

<pre class="lang-js prettyprint-override"><code>$('#myFragment *').each(function(){
   if ($(this).css('font-style')=='italic')
       $(this).css('font-style','normal')
    else
       $(this).css('font-style','italic')
});
</code>```

But this algorithm not survive to a little more complex test,

FRAGMENT <big>with italics and </big> withOUT.

```

<p>The second simplest algorithm is for a <strong>concrete solution</strong>, and was used in the "Examples" section. Have two steps:</p>

<ol>
<li>enclose the XHTML fragment into italics;</li>
<li>invert open/close italic tags (ex. <code></i></code> to <code><i></code>).</li>
</ol>

<p>That is, writing with Javascript,</p>

<pre class="lang-js prettyprint-override"><code>var s = '... a fragment of XHTML content ...';
s = '<i>'+
   s.replace(/<(\/?)i>/mg,
          function (m,p1){
              return p1? '<i>': '</i>';
          }
   ) +
   '</i>';
</code>```

But also not survive to the second test, losting balance of tags...
The "corrected" algorithm runs (!), but is  not portable, neither fast or elegant. It is  demonstred here, and at the example section below.

The point!

So the question is,

there are a simple, good and generic (usable in any browser and portable to another languages) algorithm?
You know another "swap italics algorithm"?

PS: "generic" in the sense that I even translate your algorithm to XSLT. The algorithm must produce directally balanced XHTML code (without a intermediary blackbox like Tidy).

Motivations

I need to port the "swap italics algorithm" to text editors, server parsers, etc. In all cases I can "normalize input" (and output) by standard XHTML and  tag.

I am parsing XHTML text of prose books and scientific articles, exported from different origins and styles... The most texts are exported as "normal text", but a lot of titles (ex. article title, chapter title), and, sometimes, a full chapter or a full text-box (ex. article abstract) are stylized with italics. All these "stylized with italics" must be inverted.
Typical cases:

Transform the original "all chapter italics" into "all chapter normal text": see this case, where in a roughly 300-page book, 8 of the 25 chapters need to be inverted.

Italicized quotation marks, abstracts, etc. See this example. Need change back to normal, but without lost the emphasis words.

Writing binomial names of species, in Scientific texts, are usually typeset in italics (or inverted, in a font different from that used for "normal text"). Hundreds of italicized titles (of articles and of article-sections) of XHTML-exported  articles must be inverted at my work place. PS: see the example of the beginning of the question ("Several more Homo sapiens ...").

I need also translate the generic algorithm (of your answer!) to a XSLT library, where no "tag balancing correction" not exists.

Examples

Implementing in Javascript and PHP a non-generic "Swap italics algorithm".
A generic one need a general "XML interleaving algorithm"... Here I use browser's (DOM) and Tidy corrections, as an alternative to "interleaving".

Javascript

It runs with complex inputs (!). Illustrating, by an jQuery implementation:

 var s = $('#sample1').html(); // get original html text fragment

 // INVERSION ALGORITHM: add and remove italics.
 s = ""+
     s.replace(/<(\/?)i>/mg,
               function (m,p1){
                   return p1? '': '';
               }
     ) +
     "";  // a not-well-formed-XHTML, but it is ok...
 $('#inverted').html(s); // ...the DOM do all rigth!
 // minor corrections, for clean empties:
 s = $('#inverted').html();
 s = s.replace(/<([a-z]+)>(\s*)<\/\1>/mg,'$2'); // clean
 s = s.replace(/<([a-z]+)>(\s*)<\/\1>/mg,'$2'); // clean remain
 $('#inverted').html(s);
 // END ALGORITHM

 alert(s);
```

<h3>PHP, with Tidy</h3>

<p>The same of Javascript, "translated" to  PHP — the natural translation is using <code>DOMDocument()</code> class and <code>loadHTML</code>/<code>saveXML</code> methodos, but what  have the same behaviour than browser's correspondents is the <code>tidy</code> class. Shows the same results (!) </p>

<pre class="lang-php prettyprint-override"><code> $sample1='<b><i>O</i>RIGINAL <big><i>with italics</i> and </big> withOUT</b>';
 $inverted = '... inverted will be here ...';
 echo $sample1;
 // Tidy correction
 $s = $sample1; // get original html text fragment
  // INVERSION ALGORITHM: add and remove italics.
  $s = "<i>".
      preg_replace_callback('/<(\/?)i>/s', function ($m){
       return $m[1]? '<i>': '</i>';}, $s) .
      "</i>";  // a not-well-formed-XHTML, but it is ok...
  $config = array('show-body-only'=>true,'output-xhtml'=>true);
  $tidy = new tidy;
  $tidy->parseString($s, $config, 'utf8');
  $s = $tidy;  // ... because Tidy corrects!
  // minor corrections, for clean empties:
  $s = preg_replace('/<([a-z]+)>(\s*)<\/\1>/s', '$2', $s); // clean
  $s = preg_replace('/<([a-z]+)>(\s*)<\/\1>/s', '$2', $s); // clean remain
  // END ALGORITHM
  echo "\n\n$s";
</code>```

答:
Updating (Jun 18 '13): using this answer to explain algorithms and summarize conclusions.

About jQuery traversing and "layout solution" workarounds.

After @Wilbert comment I adapted the "simplest algorithm", to avoid the dynamic behaviour of the check .prop(), that changes with .each() iteration, removing the else. After all iteration, a "parent italicizer" resolves. See here or the code below.

$('#myFragment *').each(function(){
   if ($(this).css('font-style')=='italic')
       $(this).css('font-style','normal');
});
$('#myFragment').parent().css('font-style','italic');
```

<p>Another way to deal with the dynamic behaviour, is checking a static property, by <code>prop('tagName')</code>, that not changes.  See here or the code below.</p>

<pre class="lang-js prettyprint-override"><code>$('#myFragment').parent().css('font-style','italic');
$('#myFragment *').each(function(){
   if ($(this).prop('tagName')=='I')  // not changes with parent
       $(this).css('font-style','normal');
});
</code>```

It need more tests, and needs a final parsing to change style properties to concrete  tags.  For apply the algorithm twice, we need some care.

Layout solution

This is not a solution for the present question, but produce some good clues, and is the best (at least the smallest!) solution for the "layout problem"!

The toggleClass() method can be used to swap from a "italicized class" to a "normal-text class".
See here or the code below.

 $('#myFragment *').each(function(){
     $(this).toggleClass( "original change");
 });
```

<p>And we can apply this little algorithm twice, and so many times as we want... It is a good solution! But it is not an "rewrite XML algorithm", the <strong>CSS is a  key here</strong>:</p>

<pre class="lang-css prettyprint-override"><code> .original { font-style:normal; } /* use class="original" in your XHTML fragment */
i.original { font-style:italic; }

 .change { font-style:italic; }
i.change{ font-style:normal; }
</code>```

... So, for an algorithm that transforms  tags, the problem is still open...

Concrete solution

A "100% solution, in pure XSLT1" (tested with many cases!) based on an adaptation of @DanielHaley's. It is an effective  tags transform.

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="p"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="i">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()[not(ancestor::i)]">
    <xsl:copy-of select="."/>
</xsl:template>
 </xsl:stylesheet>
```

Outlining as an "drive by event algorithm" in a copy process:

remove i tags: copy any thing of  " thing " as " thing ".

include i tags: copy any text as " text ", when the text is not into a context of italic parents. PS: text is a terminal node of the DOM tree.

Conclusions

"Layout solutions" are good for text editors, but they use some  tricks and non-rigorous solutions (no matter about overlaps, performance, etc.). For XML process we need to deal with  tags transform... So de natural languages to express the algorithm are XSLT or xQuery.

The algorithm implemented with XSLT is shows the framework necessities:

the ancestor (parent, grandparent, etc.) selector, for check if it is or not a "italic context";

the text-node (DOM text()) access;

remove and include the i tag.

So, we can see the problems with each framework.

DOM (the W3C standard framework): the DOMDocument::renameNode(), for item 3, is not yet implemented (see PHP, Javascript, etc.).

jQuery: doesn't have a convenient function for item 2, see this answer.

XSLT: the best for express the algorithm, but not is available in any context like Javascript.

I (or you plase!) will try to express the XSLT algorithm with "pure DOM2" methods. That DOM version will be the "generic algorithm"... Well: if the translation is valid only for DOM3 (using renameNode and other tricks) the conclusion for now, is that "there are NO generic/translatable algorithm".

Body:
Updating (Jun 18 '13): using this answer to explain algorithms and summarize conclusions.

About jQuery traversing and "layout solution" workarounds.

After @Wilbert comment I adapted the "simplest algorithm", to avoid the dynamic behaviour of the check .prop(), that changes with .each() iteration, removing the else. After all iteration, a "parent italicizer" resolves. See here or the code below.

$('#myFragment *').each(function(){
   if ($(this).css('font-style')=='italic')
       $(this).css('font-style','normal');
});
$('#myFragment').parent().css('font-style','italic');

Another way to deal with the dynamic behaviour, is checking a static property, by prop('tagName'), that not changes.  See here or the code below.

$('#myFragment').parent().css('font-style','italic');
$('#myFragment *').each(function(){
   if ($(this).prop('tagName')=='I')  // not changes with parent
       $(this).css('font-style','normal');
});

It need more tests, and needs a final parsing to change style properties to concrete <i> tags.  For apply the algorithm twice, we need some care.

Layout solution

This is not a solution for the present question, but produce some good clues, and is the best (at least the smallest!) solution for the "layout problem"!

The toggleClass() method can be used to swap from a "italicized class" to a "normal-text class".
See here or the code below.

 $('#myFragment *').each(function(){
     $(this).toggleClass( "original change");
 });

And we can apply this little algorithm twice, and so many times as we want... It is a good solution! But it is not an "rewrite XML algorithm", the CSS is a  key here:

 .original { font-style:normal; } /* use class="original" in your XHTML fragment */
i.original { font-style:italic; }

 .change { font-style:italic; }
i.change{ font-style:normal; }

... So, for an algorithm that transforms <i> tags, the problem is still open...

Concrete solution

A "100% solution, in pure XSLT1" (tested with many cases!) based on an adaptation of @DanielHaley's. It is an effective <i> tags transform.

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="p"/>

<xsl:template match="@*|node()"> <!-- copy all -->
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="i"> <!-- remove tag i -->
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()[not(ancestor::i)]"> <!-- inlcude tag i -->
    <i><xsl:copy-of select="."/></i>
</xsl:template>
 </xsl:stylesheet>

Outlining as an "drive by event algorithm" in a copy process:

remove i tags: copy any thing of  "<i> thing </i>" as " thing ".

include i tags: copy any text as "<i> text </i>", when the text is not into a context of italic parents. PS: text is a terminal node of the DOM tree.

Conclusions

"Layout solutions" are good for text editors, but they use some  tricks and non-rigorous solutions (no matter about overlaps, performance, etc.). For XML process we need to deal with <i> tags transform... So de natural languages to express the algorithm are XSLT or xQuery.

The algorithm implemented with XSLT is shows the framework necessities:

the ancestor (parent, grandparent, etc.) selector, for check if it is or not a "italic context";

the text-node (DOM text()) access;

remove and include the i tag.

So, we can see the problems with each framework.

DOM (the W3C standard framework): the DOMDocument::renameNode(), for item 3, is not yet implemented (see PHP, Javascript, etc.).

jQuery: doesn't have a convenient function for item 2, see this answer.

XSLT: the best for express the algorithm, but not is available in any context like Javascript.

I (or you plase!) will try to express the XSLT algorithm with "pure DOM2" methods. That DOM version will be the "generic algorithm"... Well: if the translation is valid only for DOM3 (using renameNode and other tricks) the conclusion for now, is that "there are NO generic/translatable algorithm".


问:
Perform operations in the entry-script, or create a class which just instantiates and calls methods?
I'm building a perl application which does the following operations:

Copy a bunch of files (class fileFetcher )

Parse each file (class fileParser)

Store some data from each file in a database (class dbHelper)

Now, should I, in my main.pl (entry point of the script), construct an instance of each of these and call the appropriate methods?
or is it better practice to have a separate "Application" class that does all the instantiations and method calls, and let the main script just have a call like Application.run(args)?

The class, would exist just to instantiate and call methods on things, and doesn't seem right.

答:
Keep It Simple

Don't create a separate Application class it's not necessary. Nothing bothers me more than having to turn over rock after rock after rock to understand what's going.

ContentLicense: CC BY-SA 3.0


问:
How can I salvage my internship?
I'm currently working as an intern at a very large, non-software development company.  The position I applied for wasn't specifically a development position, but the team that hired me wanted a CS major to help try to develop some internal projects for them.  I've been here for four weeks and the initial bewilderment is starting to wear off.  However, I'm the only CS major in the entire office -- no one on my team, in the building, or even in the neighboring locations has any background in software development. The best I've got is a database manager, and their department is too busy to support me with my projects.  My teammates are helping me learn how they do their jobs (which is important for me to do my job), but there's no one to help my do my job i.e.  development.

The projects they've given me are larger in scope than anything I've done in school.  That, combined with the fact that I'm working alone, trying to develop applications from scratch with no form of guidance or even clearly defined goals, has me very worried about my ability to be successful.  I barely know where I should be begin, and now I have probably less than two months remaining.

I feel like I should be learning the software development process, but right now it's like I'm feeling my way through the dark.  This is especially troubling for me since I'm not very confident with my development skills in the first place.  I've been researching and teaching myself, but I'm only getting bits and pieces.  They have high expectations from me, but I'm unsure of my ability to deliver.  Obviously, I need to sit down and talk with my managers about the position I'm in and I intend to do that as soon as possible (they're often travelling and out of the office).

How should I deal with this?  This internship will be over before I know it, and I don't want to leave with nothing to show for my time here.  They don't want that either, and they're always available to help me but without knowledge of programming there's only so much they can do.  I'm afraid to tell them that I'm incapable of producing what they want.  How should I relate this to them?  I see the engineering interns getting help from other engineers, learning how to do their jobs, and I feel like I'm just sitting here biding my time.  Any advice on how to rectify my situation would be greatly appreciated.

Update

I appreciate all the helpful feedback from everyone, it's helped put my mind at ease. The first thing I did was meet with my managers and supervisors. We discussed what was expected from my time here. They understand that I don't have that much time as an intern, and this helped put a scope on the type of framework we want to accomplish, which will allow future interns or employees to hopefully build off of what I leave. I also addressed my concerns regarding my capabilities with the allotted time, which they understood and expected.

I received a call from the database administrator at another location - my manager talked with his supervisor and they're going to support my project, which will now give me a resource to use so I'm not sitting around with no idea what I'm doing. That's only one half though. Out of all the possible projects, we narrowed it down to the two most important to work on. As for my other project, as someone mentioned I'm essentially the lead software architect which is a unique situation for an intern. If things go at least semi-successfully, I think I'll have gained a good deal of knowledge and experience that can help me with future employers. For now, I think I have some solid footing to start researching and developing my projects. Thanks again for the responses from everyone!

答:
I've got some bad news for you bhamlin:

You aren't an intern. Rather, you are an unpaid/cheap employee.

An internship is a unpaid or low-paid position where you can practice your newly aquired skills in a safe, (usually) relaxed environment, and get a chance to observe 'real' professionals in your field doing 'real' work, while getting feedback on the pieces that they allow you to modify (usually under supervision and/or approval).

What your company wanted, was not in fact, an intern, but rather a free/cheap source of software development. This is fairly common, in my opinion. I live in a college town, and at my last place of work, managers were often heard saying "Hey, the IT dept is too busy to do Project X, lets see if we can get some interns in from the University to write it for free/cheap!"  We would grumble and groan and gnash our teeth to the heavens, but this was the reality of the place, and I could understand why the managers would suggest such a thing. Sadly, the results weren't great: the software delivered by the interns was never cohesive/scaleable/clean/etc (but to be honest, neither was the stuff the IT dept put out anyway...)

Its up to you what you do. My advice is to just develop whatever you can (sometimes pressure is a great motivator), BUT you should also plan to taking on a 'real' internship elsewhere when this one is over if possible.

So don't blame yourself, but what you walked into was NOT a real internship.

Title: How can I salvage my internship?


问:
What are the pros and cons of HTML5, native and hybrid mobile app approaches?
I want to develop a mobile application. I recently read an article on Telerik Forum, which compares among three types of mobile application and I don't know which one should I select to begin with. Here is an image describing the pros and cons of different mobile design choices

To decide between these design choices, I would like to better understand the pros and cons of each architecture choice listed in the diagram.  What are the pros and cons of each architecture approach?

答:
First check this survey to know what is going on !

comparison between the three types:
Understanding Your Mobile Application Development Options

Comparisons between native and hyprid:

HTML5 vs Native

HTML5 vs Native App : Which to choose ??

This one is really good :
HTML5 v native apps: key considerations for your mobile strategy

Comments:

You can go for one of them depends on what you have (skills) and what you can get(look and feel,performance ,functionality ,...)

Every mobile app developer should have a clear vision/requirements about the application he is about develop for the first versions and the future ones ! just to ensure that the option he would use will not limit him at some point.

There is nothing like having a real experience with the three ways and being up to date at the same time, this will give you the sense and the ability to take right decision.


问:
What are non-programming mistakes that a programmer should avoid?
People make mistakes, even in the real life... Which should we, geeky programmers, avoid?</p>

答: Treating everyone else you meet like a programmer.   You have to understand that not everyone around you cares about computers as much as you do.  It's a hard pill to swallow, but unfortunately, a very real one.</p>

ContentLicense: CC BY-SA 2.5


问:
How can I quickly weed out "copy & paste" coders?
I need a way to filter out resumes of folks who just copy-and-paste code then hope it works, and check it in if it does.  All this happens without having an understanding (or care) to understand the rest of the code in the system.

Sure I know that copying and pasting code is part of learning a new object, control, etc... but how can one tell if that accounts for 70% (or more) of their development career?

I've come across some senior level guys perhaps whose skills are so outdated or irrelevant for the project, that all they do is google, copy-then-paste some code without thinking about the solution as a whole.  As a result we have a mismash of JSON, AJAX, callbacks, ASMX, WCF and postbacks in the same project.  It is clear there is no consistency or logic behind where each technology is being used.

In the worst case, this type of developer creates security issues and vectors for attack.

Question

How would you recommend I filter out people who have a poor programming background?  Can I do it at the resume level?  If not, how do I do this during the interview.

答:
I would suggest FizzBuzz that Jeff Atwood mentions in the post at http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html.

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".


答:
As a CS major you have problem solving skills at your disposal. It's unclear what type of projects they want to develop. If I had to guess they probably want you to help automate some of the internal processes. I'd start by trying to get a big picture diagram of what processes are currently in place and the dependencies between departments for each of these processes.

Next, I'd look for some low hanging fruit that could be automated or at least streamlined.

Foolproof Way of Documenting Any Process

Ask these questions in the following order:

What is the output? (Get as specific an answer as possible)

What are the inputs?

Are there enough inputs to create the output?

If the answer to number 3 is NO, then go get the missing pieces. This could be formulas or business rules or whatever.

If the output from step one is too complicated then break it down into manageable chunks and attack each chunk as a separate process.

Document what you have discovered. Identify potential single point of failures. Identify weaknesses or scarce dependencies.

I know it sounds overwhelming but you have the skill set. Just turn it into bite size chunks. If you can learn how to explain "geek stuff" using "non-geek speak" then you will be worth your weight in gold.

Title: How can I salvage my internship?

Body:
I'm currently working as an intern at a very large, non-software development company.  The position I applied for wasn't specifically a development position, but the team that hired me wanted a CS major to help try to develop some internal projects for them.  I've been here for four weeks and the initial bewilderment is starting to wear off.  However, I'm the only CS major in the entire office -- no one on my team, in the building, or even in the neighboring locations has any background in software development. The best I've got is a database manager, and their department is too busy to support me with my projects.  My teammates are helping me learn how they do their jobs (which is important for me to do my job), but there's no one to help my do my job i.e.  development.

The projects they've given me are larger in scope than anything I've done in school.  That, combined with the fact that I'm working alone, trying to develop applications from scratch with no form of guidance or even clearly defined goals, has me very worried about my ability to be successful.  I barely know where I should be begin, and now I have probably less than two months remaining.

I feel like I should be learning the software development process, but right now it's like I'm feeling my way through the dark.  This is especially troubling for me since I'm not very confident with my development skills in the first place.  I've been researching and teaching myself, but I'm only getting bits and pieces.  They have high expectations from me, but I'm unsure of my ability to deliver.  Obviously, I need to sit down and talk with my managers about the position I'm in and I intend to do that as soon as possible (they're often travelling and out of the office).

How should I deal with this?  This internship will be over before I know it, and I don't want to leave with nothing to show for my time here.  They don't want that either, and they're always available to help me but without knowledge of programming there's only so much they can do.  I'm afraid to tell them that I'm incapable of producing what they want.  How should I relate this to them?  I see the engineering interns getting help from other engineers, learning how to do their jobs, and I feel like I'm just sitting here biding my time.  Any advice on how to rectify my situation would be greatly appreciated.

Update

I appreciate all the helpful feedback from everyone, it's helped put my mind at ease. The first thing I did was meet with my managers and supervisors. We discussed what was expected from my time here. They understand that I don't have that much time as an intern, and this helped put a scope on the type of framework we want to accomplish, which will allow future interns or employees to hopefully build off of what I leave. I also addressed my concerns regarding my capabilities with the allotted time, which they understood and expected.

I received a call from the database administrator at another location - my manager talked with his supervisor and they're going to support my project, which will now give me a resource to use so I'm not sitting around with no idea what I'm doing. That's only one half though. Out of all the possible projects, we narrowed it down to the two most important to work on. As for my other project, as someone mentioned I'm essentially the lead software architect which is a unique situation for an intern. If things go at least semi-successfully, I think I'll have gained a good deal of knowledge and experience that can help me with future employers. For now, I think I have some solid footing to start researching and developing my projects. Thanks again for the responses from everyone!


答:
Here's my take on this whole situation: They are asking for more than you can reasonably accomplish, not giving you any feedback or guidance, and generally making your job not so pleasant. But there is a silver lining to this cloud You're learning something.

Particularly, you're learning the sort of environment you DON'T want to work in when you get your degree. You're also learning how to deal with a project that is too large for you to feasibly accomplish. Both of these are important pieces of knowledge to hold on to, as no one is going to give you a job that they think is below your ability. They will always ask for more than what you can give, and it's your job to work with them to manage expectations and deliver something that they want.

On to what you can do in the here and now. I would start by keeping a journal of everything that you do in each and every day. This gives you accountability. Even a simple end of day "this is what I worked on today" will give you something to fall back on when they don't get what they want and come looking for answers.

I would also talk to your immediate superior and see if there is any way to break down one of these larger projects. If you don't feel comfortable doing the whole thing, maybe they'll just have you do research and the architecture for the project, and maybe have another intern later implement it. Just be clear what you think you can reasonably accomplish in the time you have left in the internship, and make that your goal. That way you are still delivering something relevant to your employer at the end of the day.

Finally, see if you can join the engineering interns. I'm going to assume that these interns are also developing software, and I see no reason why what you're doing and what they're doing are so far separated that you can't learn from each other. I work with electrical engineers, software engineers, computer engineers and computer scientists alike on my projects, and each person brings their own strengths to the team. Identify where your strengths lie in development, and try to make a case for why those abilities would lend themselves well to the engineering team.

Title: How can I salvage my internship?


答:
I would Simply:

Convert all  to s

Convert all  to s

add an  to the beginning

add an  to the end

So

```<code> <p id="p1"><i>Several more</i> Homo sapiens <i>fossils were discovered</i>.</p>
 <!-- converts to: -->
 <i><p id="p2">Several more </i>Homo sapiens<i> fossils were discovered.</p></i>
</code>```

Title: What the correct algorithm to invert italics in a mixed text?

Body:
The question motivations was depicted in the section below.
There are many ways to make text italic,
so, perhaps, there are more than one good
"swap italics algorithm".
The problem reveals some aditional
dificulties in a XHTML code, and using the  tag, that must to be balanced.
Example:

Several more Homo sapiens fossils were discovered.

Several more Homo sapiens fossils were discovered.

```

<p>So, looks like this,</p>

<ol>
<li><p><em>Several more</em> Homo sapiens <em>fossils were discovered</em>.</p></li>
<li><p>Several more <em>Homo sapiens</em> fossils were discovered.</p></li>
</ol>

<hr>

<h1>Algoritms introduction and discussion</h1>

<p>For "<strong>layout solution</strong>", the simplest algorithm is checking the <code>font-style</code> CSS-property of all text blocks,
and invert them with jQuery:</p>

<pre class="lang-js prettyprint-override"><code>$('#myFragment *').each(function(){
   if ($(this).css('font-style')=='italic')
       $(this).css('font-style','normal')
    else
       $(this).css('font-style','italic')
});
</code>```

But this algorithm not survive to a little more complex test,

FRAGMENT <big>with italics and </big> withOUT.

```

<p>The second simplest algorithm is for a <strong>concrete solution</strong>, and was used in the "Examples" section. Have two steps:</p>

<ol>
<li>enclose the XHTML fragment into italics;</li>
<li>invert open/close italic tags (ex. <code></i></code> to <code><i></code>).</li>
</ol>

<p>That is, writing with Javascript,</p>

<pre class="lang-js prettyprint-override"><code>var s = '... a fragment of XHTML content ...';
s = '<i>'+
   s.replace(/<(\/?)i>/mg,
          function (m,p1){
              return p1? '<i>': '</i>';
          }
   ) +
   '</i>';
</code>```

But also not survive to the second test, losting balance of tags...
The "corrected" algorithm runs (!), but is  not portable, neither fast or elegant. It is  demonstred here, and at the example section below.

The point!

So the question is,

there are a simple, good and generic (usable in any browser and portable to another languages) algorithm?
You know another "swap italics algorithm"?

PS: "generic" in the sense that I even translate your algorithm to XSLT. The algorithm must produce directally balanced XHTML code (without a intermediary blackbox like Tidy).

Motivations

I need to port the "swap italics algorithm" to text editors, server parsers, etc. In all cases I can "normalize input" (and output) by standard XHTML and  tag.

I am parsing XHTML text of prose books and scientific articles, exported from different origins and styles... The most texts are exported as "normal text", but a lot of titles (ex. article title, chapter title), and, sometimes, a full chapter or a full text-box (ex. article abstract) are stylized with italics. All these "stylized with italics" must be inverted.
Typical cases:

Transform the original "all chapter italics" into "all chapter normal text": see this case, where in a roughly 300-page book, 8 of the 25 chapters need to be inverted.

Italicized quotation marks, abstracts, etc. See this example. Need change back to normal, but without lost the emphasis words.

Writing binomial names of species, in Scientific texts, are usually typeset in italics (or inverted, in a font different from that used for "normal text"). Hundreds of italicized titles (of articles and of article-sections) of XHTML-exported  articles must be inverted at my work place. PS: see the example of the beginning of the question ("Several more Homo sapiens ...").

I need also translate the generic algorithm (of your answer!) to a XSLT library, where no "tag balancing correction" not exists.

Examples

Implementing in Javascript and PHP a non-generic "Swap italics algorithm".
A generic one need a general "XML interleaving algorithm"... Here I use browser's (DOM) and Tidy corrections, as an alternative to "interleaving".

Javascript

It runs with complex inputs (!). Illustrating, by an jQuery implementation:

 var s = $('#sample1').html(); // get original html text fragment

 // INVERSION ALGORITHM: add and remove italics.
 s = ""+
     s.replace(/<(\/?)i>/mg,
               function (m,p1){
                   return p1? '': '';
               }
     ) +
     "";  // a not-well-formed-XHTML, but it is ok...
 $('#inverted').html(s); // ...the DOM do all rigth!
 // minor corrections, for clean empties:
 s = $('#inverted').html();
 s = s.replace(/<([a-z]+)>(\s*)<\/\1>/mg,'$2'); // clean
 s = s.replace(/<([a-z]+)>(\s*)<\/\1>/mg,'$2'); // clean remain
 $('#inverted').html(s);
 // END ALGORITHM

 alert(s);
```

<h3>PHP, with Tidy</h3>

<p>The same of Javascript, "translated" to  PHP — the natural translation is using <code>DOMDocument()</code> class and <code>loadHTML</code>/<code>saveXML</code> methodos, but what  have the same behaviour than browser's correspondents is the <code>tidy</code> class. Shows the same results (!) </p>

<pre class="lang-php prettyprint-override"><code> $sample1='<b><i>O</i>RIGINAL <big><i>with italics</i> and </big> withOUT</b>';
 $inverted = '... inverted will be here ...';
 echo $sample1;
 // Tidy correction
 $s = $sample1; // get original html text fragment
  // INVERSION ALGORITHM: add and remove italics.
  $s = "<i>".
      preg_replace_callback('/<(\/?)i>/s', function ($m){
       return $m[1]? '<i>': '</i>';}, $s) .
      "</i>";  // a not-well-formed-XHTML, but it is ok...
  $config = array('show-body-only'=>true,'output-xhtml'=>true);
  $tidy = new tidy;
  $tidy->parseString($s, $config, 'utf8');
  $s = $tidy;  // ... because Tidy corrects!
  // minor corrections, for clean empties:
  $s = preg_replace('/<([a-z]+)>(\s*)<\/\1>/s', '$2', $s); // clean
  $s = preg_replace('/<([a-z]+)>(\s*)<\/\1>/s', '$2', $s); // clean remain
  // END ALGORITHM
  echo "\n\n$s";
</code>```

Body:
I would Simply:

Convert all <i> to </i>s

Convert all </i> to <i>s

add an <i> to the beginning

add an </i> to the end

So

 <p id="p1"><i>Several more</i> Homo sapiens <i>fossils were discovered</i>.</p>
 <!-- converts to: -->
 <i><p id="p2">Several more </i>Homo sapiens<i> fossils were discovered.</p></i>


答:
I don't think it's necessary in this case, but I also don't think it's necessarily a bad decision -- but if you do, your name is.  It's not Application, that is effectively what your main is.  What it is, is a workflow or a process. Application doesn't need to be an object and doesn't benefit from being an object.  Your process might.

If you think it possible or likely that your process may be incorporated into a larger process, then go ahead and make it a class, until then, I'd leave it as it is.

Title: Perform operations in the entry-script, or create a class which just instantiates and calls methods?

Body:
I'm building a perl application which does the following operations:

Copy a bunch of files (class fileFetcher )

Parse each file (class fileParser)

Store some data from each file in a database (class dbHelper)

Now, should I, in my main.pl (entry point of the script), construct an instance of each of these and call the appropriate methods?
or is it better practice to have a separate "Application" class that does all the instantiations and method calls, and let the main script just have a call like Application.run(args)?

The class, would exist just to instantiate and call methods on things, and doesn't seem right.


问:
Is using subprocedures to logically separate my code a bad idea for structured programming?
Most of my programming experience is in OOP where I have fully embraced the concepts thereof including encapsulation.  Now I'm back to structured programming where I have a tendency to logicaly seperate my code using subprocedures.  For example, if I have a large switch case (30 cases or more), I'll put that in it's own procedure so the main method looks a little "neater".  Generally, subprocedures are used to help keep things DRY, but in some instances these logical seperations I create usually amount to being used only once.

Some of my code was being reviewed, and it was mentioned that this is a bad idea.  His backing to this claim is that it muddies the water and "unecessarily hides" code.  Instead, he insists that a subprocedure MUST be used more than once to merit making a subprocedure out of a section of code.  While this idea of "hiding code" is a common place in OOP, he does admit to having little to no understanding of OOP concepts and has only ever worked with structured programming.

Is there any backing to his claim or is this merely programming dogma?

答:
Encapsulation, Data Hiding, Abstraction, Writing Readable Code etc. are nothing that is unique to OOP. In fact, all of those were invented long before OOP. Really, the only difference between OOP and other paradigms is the mechanism of Data Abstraction: OOP uses Procedural Abstraction, others typically use Abstract Data Types.

Breaking up Subroutines such that every statement (or top-level expression in the case of languages that don't have statements) is on the same level of abstraction and organizing them so that the code tells a coherent story, is a universal principle, completely unrelated to any particular paradigm.


答: "Unnecessarily hiding code" is sometimes called information hiding. It is much older than object-orientation, and in Code Complete (first edition) it was described as one of the most important improvements in programmer productivity in history. </p>

Title: Is using subprocedures to logically separate my code a bad idea for structured programming?

Body:
Most of my programming experience is in OOP where I have fully embraced the concepts thereof including encapsulation.  Now I'm back to structured programming where I have a tendency to logicaly seperate my code using subprocedures.  For example, if I have a large switch case (30 cases or more), I'll put that in it's own procedure so the main method looks a little "neater".  Generally, subprocedures are used to help keep things DRY, but in some instances these logical seperations I create usually amount to being used only once.

Some of my code was being reviewed, and it was mentioned that this is a bad idea.  His backing to this claim is that it muddies the water and "unecessarily hides" code.  Instead, he insists that a subprocedure MUST be used more than once to merit making a subprocedure out of a section of code.  While this idea of "hiding code" is a common place in OOP, he does admit to having little to no understanding of OOP concepts and has only ever worked with structured programming.

Is there any backing to his claim or is this merely programming dogma?


答:
I would say dogma, but to me that implies adherence to a separate standard, and while he may not be totally alone on this, I don't think there is a large body that agrees with him.

Sub-procedures shouldn't be a single command, but turning a 5 case switch statement with blocks of 10-20 lines, into 5 subroutines and a switch statement that is 5 lines long, is going to make the code more readable.


问:
What document should describe usage of a third party library in a project?
A customer of my employer has recently requested new features for some legacy code, and since the authors of the program are no longer here, I've been assigned to implement the new features.

I've been provided with some high-level documents that are mostly from early stages of the project: the project definition, black-box testing procedures, research analysis of the initial phase of the project, and so on - nothing at a technical level.

The code makes extensive use of a third party library (Lemur Indri) for indexing and retrieval of indexed materials, but there's no documentation of how we use this library, or why it was chosen. I've spent a lot of time just learning about the library itself and how we use it; I feel like this is wasted time.

During a meeting with my supervisor I mentioned that it would have been nice if the developers of our system had written some documentation about the library and how we use it. I told him that it would have saved a lot of time for me, but I couldn't convince him that this type of thing is essential.

I think writing such documentation helps future developers to get a grip on the system and perform modification faster. If there should be such document, what would it be called, or should it be included in one of the design documents?

答:
All the above answers are fine. One missing item, though, is the information necessary to track (at the very least) security updates and bug fixes in the library:

Any possible contact information (mailing lists and web sites).

End-of-life constraints (if any).

Specific instructions on validating the library's results and performance in your environment after an upstream update (numerical results may change either because of regressions or bugfixes/performance shifts - you have to know which test cases to update and which should stay the same).


问:
Are there any good reasons to use, learn, or recommend XSLT?
I am a developer for the last 8 years. We used XSLT primarily to transform XML into HTML. We also used it for XML to XML transformation.

But we have replacement for everything now. HTML can be comfortably created through programming languages such as ASP.Net. XML can be read and manupulated in any standard highlevel languages. As programming in XSLT is a little complex, any one would prefer working on latest programming languages.

Now my question:
Will XSLT be a significant choice in future, not considering the fact of maintaining already developed XSLT? Can I recommend new programmers to study XSLT?

答:
As a matter of fact, I think it is more efficient to use XSL than another language for presenting data. For example you can present an XML as a PDF using XSL-FO and you can control every inch, but if you work with RDLC (.NET) for example, you will see that is very difficult to present exactly what you want.

Even the evolution/correction is quite easy, as in XSL each element has its own template.
I think that the extension of XSL is more important like XSLT and XSL-FO. That's why this language will still be used in the future (but i really hope that will be more stable and less complex).


答:
It's a reasonably common maxim that a function (to use C terminology) should be no more than one or two screens worth of code (example), with the reasoning being that it's easier to take in the entirety of what the function does without having to repeatedly scroll up and down.

It's certainly the case that when a function runs into hundreds or even thousands of lines it becomes more difficult to read and understand.  I think you need to be pointing this out to your reviewer.


问:
Is it just me or is this a baffling tech interview question?

Background

I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

That's it.  That is all the information I was given.

I asked the interviewer what the goal was but apparently there wasn't one, just "traverse" the "object".

I don't know about anyone else, but this seems like a silly question to me.  I asked again, "am I searching for a value?".  Nope.  Just "traverse" it.

Why would I ever want to endlessly loop through this "object"??  To melt my processor maybe??

The answer according to the interviewer was that I should have written a recursive function.

OK, so why not simply ask me to write a recursive function?  And who would write a recursive function that never ends?

My question:

Is this a valid question to the rest of you and, if so, can you provide a hint as to what I might be missing?  Perhaps I am thinking too hard about solving real world problems.  I have been successfully coding for a long time but this tech interview process makes me feel like I don't know anything.

答:
I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

The object in question is made up of the parts A,B and C, and it forms a triangle. The person is simply asking if the object (a collection) contains all equal parts.

The interviewer wants to know if presented with parts A, B and C can you tell if they are all equal without getting stuck in an infinite loop. This question is stupidly simply to understand and still they managed to f*** it up in asking it.

They are all equal when A == B && B == C && A == C, but that can be simplified to just A == B && A == C.

The simplicity of the question resulted in confusion, and it really is worded badly.

The correct wording should have been.

Write an algorithm to check the parts of a collection to see if they are all equal to each other. Care must be given not to get stuck in an infinite loop. For example; if parts A is equal to B and B is equal to C and A is equal to C could cause problems.

The answer according to the interviewer was that I should have written a recursive function.

Yes, you can answer the question are all my parts equal using recursive functions. No, this is not an efficient solution.

EDIT: After some thought. No it's not possible to check a collection contains all equal parts using a recursive function.

The most efficient solution is as follows.

```<code>function are_all_equal(parts)
{
   for(int i=1; i < parts.length; i++)
       if parts[i] is not same as parts[0]:
           return false;
   return true;
}

print are_all_equal(parts) ? "yes" : "no";
</code>```

This problem does occur in programming, and asking someone to write an algorithm to test a collection is perfectly normal. Depending upon the programming language this problem can often be solved with just one line of code.

Wording as they did, and expecting the wrong answer is not normal. Since this question was ask a year ago. I truly hope you ended up working somewhere else. I'd be interested in hearing from the original post how things turn out for him/her.

Body:
I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

The object in question is made up of the parts A,B and C, and it forms a triangle. The person is simply asking if the object (a collection) contains all equal parts.

The interviewer wants to know if presented with parts A, B and C can you tell if they are all equal without getting stuck in an infinite loop. This question is stupidly simply to understand and still they managed to f*** it up in asking it.

They are all equal when A == B && B == C && A == C, but that can be simplified to just A == B && A == C.

The simplicity of the question resulted in confusion, and it really is worded badly.

The correct wording should have been.

Write an algorithm to check the parts of a collection to see if they are all equal to each other. Care must be given not to get stuck in an infinite loop. For example; if parts A is equal to B and B is equal to C and A is equal to C could cause problems.

The answer according to the interviewer was that I should have written a recursive function.

Yes, you can answer the question are all my parts equal using recursive functions. No, this is not an efficient solution.

EDIT: After some thought. No it's not possible to check a collection contains all equal parts using a recursive function.

The most efficient solution is as follows.

function are_all_equal(parts)
{
   for(int i=1; i < parts.length; i++)
       if parts[i] is not same as parts[0]:
           return false;
   return true;
}

print are_all_equal(parts) ? "yes" : "no";

This problem does occur in programming, and asking someone to write an algorithm to test a collection is perfectly normal. Depending upon the programming language this problem can often be solved with just one line of code.

Wording as they did, and expecting the wrong answer is not normal. Since this question was ask a year ago. I truly hope you ended up working somewhere else. I'd be interested in hearing from the original post how things turn out for him/her.


问:
Can I perform a code review although I am very inexperienced?
I have been teaching myself Python as a first language for 2 years now. So far I have done some online courses (NLP, Design of a Computer Program etc.) and solved some puzzles but never worked with big applications.

Yet right now I have the opportunity to do some real work with Python on a project at my university. It's a web app using the Pyramid framework, currently at about 8000 lines. And they are using quite a few tricks that I have never encountered before - stuff like __metaclass__, lots of OO stuff that I have no prior experience with.

Do you believe that I could still do useful work for the project?

And what could I do to prove my worth?

Edit: The developers on the project are at a different university. The job available at my university seems to be a classic code review job: Check the code for security flaws, style, coherence, efficiency etc.

答:
Most of the times no. But you have to answer (at least)the following questions first, just in case you are the exception:

Can you recognize possible security flaws by reading the source code? If yes, can you propose a solution?

Are you aware of a handful of coding best practices and able to catch them up? From freeing memory and not causing memory leaks, applying the correct scope to members to using measure performance without a profiler(and much more of course)

Are you, at least, at an intermediate level on the language the program you are reviewing is written?

Are you experienced enough to review a much more talented colleague who is better than you at all the above?

Of course, there more points to look for...


答:
The other answers here are very good, read them over and over and really try to figure them out. If you do that then, with a more than average effort, you'll be able to emerge "alive" on the other side of your internship. Given your situation, it will be tougher than you expected, but it can be worth it.

This is crucial because, when you'll apply for a position to another company1, one of the key questions will be:

I see here you did an internship at the company X. How was it ? Why
  did you leave ?

If you can then show them that you handled your difficult situation in a professional manner, this will count A LOT, employers are usually very impressed with something like this.

Even if it kind of sucks, you can make it a valueable experience from which you have the opportunity to learn what your classmates never will...

1 = I hope you will, 'cause staying there will be a career suicide (sooner or later... probably sooner)

Title: How can I salvage my internship?


答:
Can I perform a code review although I am very inexperienced?

Yes, you could, and should join a code review whenever it is done (and you have free time). Even if you do not contribute, you can learn something new, therefore it is almost always useful.

Do you believe that I could still do useful work for the project?

Since you are new and inexperienced, your contribution is very limited, and I surely hope you got a senior to guide and tutor you. It will take you long to become a master (see Teach Yourself Programming in Ten Years), but don't give up. Over time, your expertise will grow, and you'll become useful.

Body:
I have been teaching myself Python as a first language for 2 years now. So far I have done some online courses (NLP, Design of a Computer Program etc.) and solved some puzzles but never worked with big applications.

Yet right now I have the opportunity to do some real work with Python on a project at my university. It's a web app using the Pyramid framework, currently at about 8000 lines. And they are using quite a few tricks that I have never encountered before - stuff like __metaclass__, lots of OO stuff that I have no prior experience with.

Do you believe that I could still do useful work for the project?

And what could I do to prove my worth?

Edit: The developers on the project are at a different university. The job available at my university seems to be a classic code review job: Check the code for security flaws, style, coherence, efficiency etc.


答: I would say that the problem with your candidates isn't that they can't program at all, but that they don't have a feel for using the right tool for the job. My suggestion is an essay question where they would be given high-level requirements for a new system and asked to provided an architecture and justify their component choices. But keep the FizzBuzz for the candidates who can't code at all without a browser.</p>

Title: How can I quickly weed out "copy & paste" coders?

Body:
I need a way to filter out resumes of folks who just copy-and-paste code then hope it works, and check it in if it does.  All this happens without having an understanding (or care) to understand the rest of the code in the system.

Sure I know that copying and pasting code is part of learning a new object, control, etc... but how can one tell if that accounts for 70% (or more) of their development career?

I've come across some senior level guys perhaps whose skills are so outdated or irrelevant for the project, that all they do is google, copy-then-paste some code without thinking about the solution as a whole.  As a result we have a mismash of JSON, AJAX, callbacks, ASMX, WCF and postbacks in the same project.  It is clear there is no consistency or logic behind where each technology is being used.

In the worst case, this type of developer creates security issues and vectors for attack.

Question

How would you recommend I filter out people who have a poor programming background?  Can I do it at the resume level?  If not, how do I do this during the interview.


答:
Do you believe that I could still do useful work for the project?

Yes, but be honest about your level of experience.

Some things you might be able to work on are the work items (bugs, tasks, etc.) that the team classified as "fairly trivial, no rush". This classification is from the viewpoint of someone who is comfortable with the existing codebase, so expect it to be a lot harder for you.

Assisting in code review can also be a learning experience. Don't expect to be a major contributor to the review .

Title: Can I perform a code review although I am very inexperienced?


答: It don't see why not. Just be respectful and frame things in terms of how you would have done something differently or as a question of whether it might better if... etc. Even when experience levels are matched, code review can be as much an opportunity to learn from the reviewed as it is to learn from the reviewer. It's not usually about sitting in judgment with zero feedback on your opinions (although IMO a good tech lead will slap down pointless Kool Aid that doesn't really bring anything useful to a solution). Sometimes a code review is great just for the stuff you realize is inefficient or pointless as you explain it to another dev.</p>


答:
I was in a similar position last year, where I had to develop everything from ground up and had no one else with any development experience.
I did finish the project they gave me but I wouldn't call it a polished application or even a maintainable one(since the only person that knows how it works is me and no one at the company has looked at the code.)

Here are some things I did and would do if I was in that situation. Some of these have already been mentioned in the previous answers

Figure out:

What do they want the product to do (inputs and outputs, the bare minimum)

What are your limitations? (i.e which programs can/cannot you use?)

This will give you a picture in your head about how the product should look. Draw this out on a piece of paper and show it to your manager/supervisor. See what they say about it. If they don't like it ask them what they want changed, change it and repeat the process. If they like it, do the bare minimum amount of coding and create a simple demo.

Show the demo to them (ask them if this is what they have in mind), this will show them your progress and help you understand what they want.

Whenever you need coding help, read manuals/tutorials, google search and finally post on stack overflow for help.

Don't get hung up on small details. You will waste a lot of time if you do this.

Code in small chunks, each chunk being a major functionality for the application.

Comment your code. If they are planning to pass this on to another intern or an employee it will be a huge help to them.

Keep communicating with your manager/supervisor about the project and your progress on it.

And don't worry if you cant finish the project, you are an intern and you did the best you can. They are at fault for hiring someone who is under experienced for such a project.

TL;DR

Communicate with your manager every step

Code the major functionality

Get help from Google and stack exchange

Dont worry if you cant finish

Title: How can I salvage my internship?


答:
Talk to Your Internship Advisor

All of the answers I've seen so far seem to focus on the employer, which is important.

However, you must have been set up with this internship through a program or office at your school.  I can't imagine that you'd be the first student they've had that has run into this kind of situation.  They should be able to guide you in a certain direction.

Even if they cannot help you now (which I find difficult to believe), then you will be helping the next student that finds him or herself in this situation, which is something that cannot be underestimated.

Title: How can I salvage my internship?


问:
Guid collisions
I have a product that lets game developers create games. Inside of their games they are required to give all the elements of their games GUIDs. I've told them that they need to generate their guids using a specific mechanism, but they seem to think that it won't cause any issues. What I'm concerned about is GUID collisions between games.

Some developers just sequentially increment the last digit of their GUID, others zero out the last block and increment other parts, well others just pull together a random armada of numbers and letters for each one.

My argument is that by doing this it dramatically increases the risk of colliding with other games that are both following the standard, and those that don't.

Just as a heads up there are potentially hundreds of thousands of GUIDs involved here.

Am I right in thinking this, or is it really improbable that this will really happen?

答:
Since you're not in control of guid creation you need to expect that there will be a collision at some point (if there isn't one already) and you have to expect that there will be novice developers who don't see why starting at 1 and counting up is a problem.

To make it impossible you would have to issue all the guids yourself.

But, since people can access other people's objects purely by a single ID, you also have a big security hole waiting to be exploited and depending on how you choose to fix that, this problem will may wind up a moot point.

Title: Guid collisions


问:
How to handle flag in multiple if-else's
I seem to see this often enough in my code and others. There's nothing about it that seems horribly wrong, but it annoys me as it looks like it can be done better. I suppose a case statement, might make a little more sense, but often variable is a type that does not work well or at all with case statements (depending on language)

```<code>If variable == A
    if (Flag == true)
        doFooA()
    else
        doFooA2

else if variable == B
    if (Flag == true)
        doFooB()
    else
        doFooB2
else if variable == C
    if (Flag == true)
        doFooC()
    else
        doFooC2
</code>```

It seems there's multiple ways to "factor" this, such as 2 sets of if-elses, where one set handles when Flag == true.

Is there a "good way" to factor this, or perhaps when this if-else algorithm happens it usually means you  are doing something wrong?

答:
Use polymorphism and a rule array

```<code>interface IRule() {
  boolean applicable(args...);
  obj apply(args...);
}

static final Array<IRule> rules = [new MeaningfulNameRule1(), new MeaningfulNameRule2(), ...];

/* where */
class MeaningfulNameRuleX extends IRule{ /* */ }

/* In your method */

for (rule in rules) {
  if (rule.applicable(a,b,c)){
    return rule.apply(e,f,g);
  }
}
</code>```

Or as mike30 suggested: If the rule conditions can easily form a key then a hashmap is the best way to go.

Body:
Use polymorphism and a rule array

interface IRule() {
  boolean applicable(args...);
  obj apply(args...);
}

static final Array<IRule> rules = [new MeaningfulNameRule1(), new MeaningfulNameRule2(), ...];

/* where */
class MeaningfulNameRuleX extends IRule{ /* */ }

/* In your method */

for (rule in rules) {
  if (rule.applicable(a,b,c)){
    return rule.apply(e,f,g);
  }
}

Or as mike30 suggested: If the rule conditions can easily form a key then a hashmap is the best way to go.


答:
I've come across some senior level
  guys perhaps whose skills are so
  outdated or irrelevant for the
  project, that all they do is google,
  copy-then-paste some code without
  thinking about the solution as a
  whole. As a result we have a mismash
  of JSON, AJAX, callbacks, ASMX, WCF
  and postbacks in the same project. It
  is clear there is no consistency or
  logic behind where each technology is
  being used.

I don't think the skills of your developers are the problem.  Your problem lies elsewhere, perhaps a team leader or architect who doesn't have the self-confidence to "encourage" better coding disciplines, or a management team that doesn't understand the importance of managing technical debt, and doesn't give their developers the time and resources to do so.  Does your company hold code reviews?

Leadership may be the problem, not copy-paste developers.


问:
Just in time prize winning algorithm
I'm building a contest where you can win prizes by opening boxes. Whatever the box is open, i just send a request to the server to test if the user won something. Since this contest is not a "Register and we'll draw a winner after some time" type of contest, i'm a bit puzzled at what algorithm i should be taking to calculate chances to win.

I've devised in an excel spreadsheet what i call a progressive winning algorithm in the form of:

```<code>([Number of prizes left] / [Prizes i should have left at this time of contest]) / 4
</code>```

Which gives me a rough percentage change of winning an item off the pool of remaining items around 25%. If there are many winners within a close timespan, the algorithm should automatically lower the chances of winning while going in the opposite direction if the scenario is different.

What i'm afraid of is that not all my items will be drawn by the end of the contest because it's a linear calculation of expected gifts left or i'm afraid that, by chance, most of my prizes will be won after only half of the contest (and by chance i mean that lots of player get truly great random odds and keep winning)

So my question is, how should i tackle this kind of scenario, what are already known methods for this and please keep it simple, i'm no mathematician nor statistician.

Variables to take into account

100 prizes to give out total

Contest lasts five whole days

Unknown number of participants

Unknown participation rule but will probably be once per day based on a unique credential such as an e-mail address.

It's an online contest where a user opens a virtual box, nothing physical

答:
You're thinking about it kind of backwards.  Rather than calculating an individual player's odds, it's much simpler to randomly distribute the time between winners.  For example, say you have 10 prizes, and the contest lasts an hour.  Randomly generate 10 numbers between 1 and 3600.  That gives a timestamp in seconds since the start of the contest.  The first player to open the box after that time wins the prize.

Assuming a relatively steady stream of customers, that distributes the prizes fairly, effectively increases the odds the longer it has been since a winner, automatically adjusts the odds for the number of players, and ensures all the prizes are distributed.

Title: Just in time prize winning algorithm


答:
I created an algorithm for something similar recently which might be of help -- I'll try to tailor it to your scenario:

You have 100 prizes to give away in 5 days, so divide the total time (5 days) into 100 time-slots.

At some point in time during each time-slot, a prize should become available to be won. So, pick random numbers between 0 and 1 to map to each time-slot interval (0 being the beginning of a slot, 1 the end) and this will be the time within each slot a prize will become winnable.

As time progresses, new prizes will become winnable. If people haven't been playing, then there will be more winnable prizes in the pool; when these run out, prizes will go back to becoming winnable at the regular schedule of one per slot.

I varied things in my application by drawing the times things became available within a time-slot from a normal distribution so that things were more likely to happen near the middle of the slot. You might want to take a different approach and vary the sizes of the time-slots during the contest so that they're not all the same length (e.g. more smaller slots in the middle of the 5 days to make a higher concentration of the prizes become available during that time).

Title: Just in time prize winning algorithm

Body:
I'm building a contest where you can win prizes by opening boxes. Whatever the box is open, i just send a request to the server to test if the user won something. Since this contest is not a "Register and we'll draw a winner after some time" type of contest, i'm a bit puzzled at what algorithm i should be taking to calculate chances to win.

I've devised in an excel spreadsheet what i call a progressive winning algorithm in the form of:

```<code>([Number of prizes left] / [Prizes i should have left at this time of contest]) / 4
</code>```

Which gives me a rough percentage change of winning an item off the pool of remaining items around 25%. If there are many winners within a close timespan, the algorithm should automatically lower the chances of winning while going in the opposite direction if the scenario is different.

What i'm afraid of is that not all my items will be drawn by the end of the contest because it's a linear calculation of expected gifts left or i'm afraid that, by chance, most of my prizes will be won after only half of the contest (and by chance i mean that lots of player get truly great random odds and keep winning)

So my question is, how should i tackle this kind of scenario, what are already known methods for this and please keep it simple, i'm no mathematician nor statistician.

Variables to take into account

100 prizes to give out total

Contest lasts five whole days

Unknown number of participants

Unknown participation rule but will probably be once per day based on a unique credential such as an e-mail address.

It's an online contest where a user opens a virtual box, nothing physical


问:
Homogeneous vs. heterogeneous AST representation
What are the reasons to choose a homogeneous vs. a heterogeneous AST representation for implementing a complex domain-specific programming language?

Just to be very clear about what I'm asking, here is some extra background:

By homogeneous, I mean a tree constructed of nodes which are a single generic type. For example, I think this question is really language independent, but using a C++-like struct for illustration, I'd consider this a minimal homogeneous abstract syntax tree node:

```<code>struct Node {
  int tag;
  void *data;

  Node *first_child;
  Node *next_sibling;
};
</code>```

By heterogeneous, I mean a tree constructed of nodes which are multiple individual types (e.g. one for each grammar production). For example, I don't want to assume a particular language, but again using C++-like structs for illustration, I'd consider these types part of a hierarchy used to build a heterogenous abstract syntax tree tree:

```<code>struct Node {};

struct Integer_Node : Node {
  int value;
};

struct Plus_Node : Node {
  Node *right;
  Node *left;
};

struct If_Statement : Node {
  Node *Condition;
  Node *Then_Expression;
  Node *Else_Expression;
};

// ... more types, depending on the language ...
</code>```

Over the years, I've implemented several small, special-purpose compilers, usually in a very ad-hoc way. I've never used much of a real "AST" because usually syntax-direct translation has been good enough.

Now I'm in the process of designing and implemented a new, much more complex language, where I will be building an AST and then walking over it with multiple passes for verification, semantic analysis, and so forth.

For example, it seems that using a homogeneous scheme reduces the amount of code up front, but I wonder if a heterogeneous scheme will pay off better in the long run for reasons I'm not considering. On the other hand, the heterogeneous scheme seems like it allows benefiting from the compiler's static type checking, virtual method dispatch, etc, but I wonder if any of that is really very useful when developing semantic passes and so forth.

Basically, I'm hoping to gain some insight from those who may have some real experience here. I've read many compiler books and have a moderate amount of basic compiler-writing experience, but I haven't seen this particular dichotomy addressed in any literature I can get my hands on.

答:
For me, the big advantage of the heterogeneous AST is that it forms a kind of forced, annotated switch statement (assuming a C-like language).

For the homogeneous AST you usually end up with some kind of routine or class with a big switch statement. You need to keep track of which child node is what yourself. "First child is the conditional, second the true-block, third the false-block." Whenever you change the code, you easily find yourself making a mental picture of your DSL syntax over and over again.

Of course you can document heavily, but a good program ought to be self-documenting as much as possible. The heterogeneous AST does just that.

Furthermore, you can easily turn a heterogeneous AST into a homogeneous one, but not the other way around. Add the tag info (which is a good idea, unless your language supports a cheap is-a query). You can add Node(int index) methods to return the named fields. So you lose nothing in generality by using the heterogeneous AST.

I won't mention that the heterogeneous AST is ideal for the Visitor pattern, as it is just as easy to use the Strategy pattern with the homogeneous switch routine. It is easier to add specific functionality to the heterogeneous AST itself, though. If you want to turn it into an interpreter, all you need to do is add some kind of "eval" methods.

I would consider a homogeneous AST if there are limiting circumstances. If you need to port the compiler to a system with no OOP language available, or if you need to optimize for speed. The homogeneous AST is easier to combine with an FSM. The latter can also be an advantage if you want to have a general multi-purpose compiler that loads syntax rules on the fly. But it is easier to start out with a heterogeneous AST that will generate those tables, after the compiler has been thoroughly tested.

So, all in all, I would say that neither tree offers specific advantages in terms of "does this tree help or hinder in, say, 'semantic passes'?" The advantage of the heterogeneous AST is, in my experience, to reduce the amount of thought and concentration you have to put into coding the tedious stuff of the compiler. There is a lot of repetitiveness and bookkeeping going on, so let the computer do the work for you as much as possible, is my motto.


答:
XSLT attempt from https://stackoverflow.com/a/17156452/317052 ...

I'm not sure if this would cover all cases, but you could do this:

XML Input

```<code><html>
    <!-- original text: -->
    <p id="p1"><i>Several more</i> Homo sapiens <i>fossils were discovered</i>.</p>
    <!-- same text, swapping italics: -->
    <p id="p2">Several more <i>Homo sapiens</i> fossils were discovered.</p>
    <p>Leave me alone!</p>
    <p><b><i>O</i>RIGINAL <big><i>with italics</i> and </big> withOUT</b></p>
</html>
</code>```

XSLT 1.0

```<code><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*[i]">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="node()" mode="swapItal"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="text()" mode="swapItal" priority="1">
        <i><xsl:value-of select="."/></i>
    </xsl:template>

    <xsl:template match="i" mode="swapItal">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="@*|node()" mode="swapItal">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" mode="swapItal"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
</code>```

XML Output

```<code><html>
   <!-- original text: -->
   <p id="p1">Several more<i> Homo sapiens </i>fossils were discovered<i>.</i></p>
   <!-- same text, swapping italics: -->
   <p id="p2"><i>Several more </i>Homo sapiens<i> fossils were discovered.</i></p>
   <p>Leave me alone!</p>
   <p><b>O<i>RIGINAL </i><big>with italics<i> and </i></big><i> withOUT</i></b></p>
</html>
</code>```

Input Rendered

    Several more Homo sapiens fossils were discovered.

    Several more Homo sapiens fossils were discovered.

Leave me alone!

ORIGINAL with italics and  withOUT

Output Rendered

   Several more Homo sapiens fossils were discovered.

   Several more Homo sapiens fossils were discovered.

Leave me alone!

ORIGINAL with italics and  withOUT

Body:
XSLT attempt from https://stackoverflow.com/a/17156452/317052 ...

I'm not sure if this would cover all cases, but you could do this:

XML Input

<html>
    <!-- original text: -->
    <p id="p1"><i>Several more</i> Homo sapiens <i>fossils were discovered</i>.</p>
    <!-- same text, swapping italics: -->
    <p id="p2">Several more <i>Homo sapiens</i> fossils were discovered.</p>
    <p>Leave me alone!</p>
    <p><b><i>O</i>RIGINAL <big><i>with italics</i> and </big> withOUT</b></p>
</html>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*[i]">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="node()" mode="swapItal"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="text()" mode="swapItal" priority="1">
        <i><xsl:value-of select="."/></i>
    </xsl:template>

    <xsl:template match="i" mode="swapItal">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="@*|node()" mode="swapItal">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" mode="swapItal"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

XML Output

<html>
   <!-- original text: -->
   <p id="p1">Several more<i> Homo sapiens </i>fossils were discovered<i>.</i></p>
   <!-- same text, swapping italics: -->
   <p id="p2"><i>Several more </i>Homo sapiens<i> fossils were discovered.</i></p>
   <p>Leave me alone!</p>
   <p><b>O<i>RIGINAL </i><big>with italics<i> and </i></big><i> withOUT</i></b></p>
</html>

Input Rendered

    Several more Homo sapiens fossils were discovered.

    Several more Homo sapiens fossils were discovered.

Leave me alone!

ORIGINAL with italics and  withOUT

Output Rendered

   Several more Homo sapiens fossils were discovered.

   Several more Homo sapiens fossils were discovered.

Leave me alone!

ORIGINAL with italics and  withOUT


答:
I had two internships like that, and enjoyed them immensely.  There are significant bright sides that you seem to be missing:

At this moment you are enjoying the kind of creative freedom that programmers working on large teams of programmers can only dream about.  Everything from language choice, to source control, to editors, to software architecture is completely up to you.  Trust me, you miss that when it's gone.

Working with people who don't know much about software is a significant part of the software development process.  School conditions you to expect well-defined assignments from people with a lot of experience teaching software development.  Even in teams of programmers, your assignments are never that clear cut.  Learning to deal with it now will give you an edge.

Acquiring domain knowledge without the benefit of mentors is a significant part of the software development process.  Once every year or two, I get an assignment like, "Become our subject matter expert on X technology."  Someone has to be the first one at a company to learn a new technology.  You will get more interesting assignments if you can show that person can be you.

From your point of view, it feels like a lot of pressure, but you should know that their expectations of you are really quite low.  They know it's more difficult for you without a proper mentor.  Just do your best and you'll be fine.

That being said, tackling your first large project can be overwhelming.  The following may help:

Try not to think about the whole project at once.  Think about what you need to do right now.

Get a list of features that need to be done, and get them to put it in priority order.  That way if you don't finish the entire app, the most important features will still be there.

Break the first feature down into smaller and smaller tasks, until you get down to tasks you can finish in a day or two.  Don't be afraid to make them sound stupidly simple.  My first task on brand new projects is always to get hello world working and checked into source control.  Especially if it's a new language, or one I haven't used in a while, that tells me my build environment and tools are set up properly.

Get your progress reviewed frequently.  Don't try to dump a finished product on them at the end of the summer.  Show them at least once per week what you have so far.

Spend some effort up front to try to find existing projects and components that can meet your needs.  It's much easier to customize an existing system than to do one from scratch.  A lot of companies need similar kinds of internal apps.  This is one I wish I had known about for myself.  One of my internship projects basically reinvented (poorly) a CRM.

So, relax, do your best, and learn as much as you can, whether it's about software or not.

Title: How can I salvage my internship?


问:
Algorithm in undirected BFS graph
I'm trying to put together an algorithm that will display the node degree for every node in a breadth first tree graph (assume BFS was called).  Assume it's an undirected graph.  I'm not sure how to get the node degree of a node when going through the graph.  I was thinking about adding up every occurrence of the node in every list, then adding up all the occurrences within that node's list (all of them since it's undirected), but I'm not sure not how to implement.  Just answer with pseudocode.  I just need the algorithm, then I'll implement later in a language.

```<code>BFS-get-all-degrees
    occurr[v] = 0
    for each v in G.v
        for each u in adj[v] //loop through each adjacency list
            if v==u
                occurr[v]++
        print occurr[v]++
</code>```

I think that's on the right track. It's definitely not right, but not sure where to go from there.

EDIT:

I came up with some better code.  I think it runs in O(V+E) but not sure.

```<code>BFS_Node_Degree
    for each vertex v in V
        count = 0
        for each vertex u in adj[v]
            count++
        print "the node ",v," has degree ", count
</code>```

答:
Well, just recall the definition of degree in undirected graphs:

A node's degree in an undirected graph without multiple edges is equal to the count of its neighbor nodes (=its adjacent nodes).

Since the adjacence list's count of each node is equal to its neigbor node count, the algorithm looks like this:

```<code>BFS-get-all-degrees
occurr[v] = 0
for each v in G.v
    occurr[v] = adj[v].Count
    print occurr[v]
</code>```

Title: Algorithm in undirected BFS graph

Body:
Well, just recall the definition of degree in undirected graphs:

A node's degree in an undirected graph without multiple edges is equal to the count of its neighbor nodes (=its adjacent nodes).

Since the adjacence list's count of each node is equal to its neigbor node count, the algorithm looks like this:

BFS-get-all-degrees
occurr[v] = 0
for each v in G.v
    occurr[v] = adj[v].Count
    print occurr[v]


答:
Seek clarification on the internship's goals - why were you assigned so many projects?

Clarify to management that within the allotted time, you cannot complete the requested projects

Prepare an analysis of how to best use your time. For example, suggest working solely on one project and dropping the others.

Your time would best help your company if you worked solely on one small project. Make sure to keep it well documented. Focus on creating useful documentation of architecture, project goals, project progress, and source code.

Title: How can I salvage my internship?


问:
Building a web application that is almost completely rendered by Javascript, while back end only delivers Json. Do or don't?
As a programmer, and taking into account the overall "funness" of the process, I'm tempted to start a project in Sinatra where the back end's sole concern is the logic, and returning a Json API, and then writing a javascript application that would interact with that API for rendering the actual content to the user.

I'm fairly new to programming and I've never done anything remotely like this before. What would be the pitfalls, advantages and disadvantages of completely separating logic from presentation in such a way? Any examples of this being done in the wild?

One concern off the top of my head is how would search engines respond to a site whose content is almost entirely served as Json...

答:
Try it. I did a few projects (mostly with angular and web api), and it was a good experience overall.

Advantages - you have a very fluid user experience, and can create single-page apps with ease; have a clean separation between business and UI; you can use web service for different apps (e.g. to feed a mobile app, etc - data is data, you can reuse it).

Disadvantages - you probably will end up with more calls to the server, unless you will combine multiple calls in one chunk (e.g. to pull data for 5 different dropdowns in a single call). It can also be somewhat slower to load - first you load an empty page with JS, and then are making calls to the web services - this is obviously takes longer than just serving a complete page. Generally not a bit difference.

SEO can be an issue, yes. I guess you can serve a simple static pages for robots, if you need your data to be indexed.


问:
Ways for a young programmer to not feel intimidated at my first REAL programming job?
I'd like to state first that I'm a 19 year old programmer living in Portugal, and have recently started my first REAL programming job.

I say "REAL" because at my previous jobs, I was normally the sole developer just working on creating and updating a sole website and further developing ideas for the company. (I've worked for a nightclub, for example) This did not work out, as said nightclub ran into some finance troubles and I decided to leave for my own good.

Naturally, due to (at least where I live) pre-conceived notions due to my age, I started offering myself to do projects pro-bono for many different companies, hoping it would help me get a job offer after a while. That day came last week, when I was offered a job at a website-based company, after they noticed my work. Naturally I was ecstatic and still am! I had my job interview today and it went very well, with me starting working there next week.

Even if this is all good news, I can't help but feel overwhelmed. This company is the real deal and is filled to the brim with excellent programmers in their late 20's to early 40's, whereas I am the youngest programmer they have ever hired (they made sure to tell me that at the interview) at age 19. I am not doubting my capacities due to my age and know deep inside that I'll do well after the initial gelling phase, seeing as they do not use any languages/technologies that are foreign to me, but I'm not entirely sure if everybody sees it the same way. I got the idea that my age was a big thing to them at the interview and was considered a risk, seeing as most people are 6-7 years older than me, which intimidates me quite a bit.

Does anyone have any advice or similar experiences they'd like to share? I may be overreacting as the interview went well and I seemed to impress, yet I just can't get this particular fear off my mind.

答:
Relax, ask lots of questions, understand how they work and their processes before diving in and suggesting to do it your way. But always be willing to make suggestions, and also be willing to accept that those suggestions may not be taken on board, don't take that personally!

Did I mention ask questions, ask more! If they're a good place to work, they wont expect you to be world class at your age, they also will expect that you probably think you know more than you actually do. So be open and learn as much as you can.

Find the smartest person in the company, get to know them and learn as much as you can from them.

And finally, never be precious about your code. Ever.

Oh and don't forget to have fun :)


答:
There’s a couple of things to note.

You will have collisions. Even if they are mathematically improbable, they're still possible. And given Murphy’s Law, you will end up seeing the improbable become reality at the most inconvenient time, like when you're trying to final. If you're using any kind of hashing algorithm, you need to be aware that you will at some point have hash collision, and need a process to fix it. This is quite often just adding more, unique information into the hash.

If you're letting people generate their own hash’s ids. You’re in for a world of hurt. There needs to be one way of hashing data, and that way needs to provide enough "uniqueness" to minimize collisions. Either that or you use a centralized GUID factory that doles out unique GUIDs. Of course, there are various threading issues with this approach.

Although you could simply have a GUID factory per thread, and give each GUID factory a different starting point a few billion id's apart from each other. This can also be a handy way to work out which thread exploded.

The real answer to "which approach" you should take should come from how your resource system works. If you're using a centralized asynchronous resource system (and you should be), you can assign GUID's at that point. If you're creating random objects all over the shop in various threads, then you're going to have to go with one of the other options above.

Title: Guid collisions

Body:
I have a product that lets game developers create games. Inside of their games they are required to give all the elements of their games GUIDs. I've told them that they need to generate their guids using a specific mechanism, but they seem to think that it won't cause any issues. What I'm concerned about is GUID collisions between games.

Some developers just sequentially increment the last digit of their GUID, others zero out the last block and increment other parts, well others just pull together a random armada of numbers and letters for each one.

My argument is that by doing this it dramatically increases the risk of colliding with other games that are both following the standard, and those that don't.

Just as a heads up there are potentially hundreds of thousands of GUIDs involved here.

Am I right in thinking this, or is it really improbable that this will really happen?


问:
Open source licensing of derived works
I derived an open-sourced work, Service-Nucleus, based on Netflix's Karyon (Apache License) and Google's AngularJS (MIT License).

I want to make sure proper licensing and copyrights are in place, and I am not sure how to honor those projects and move forward legitimately at the same time.

I've researched this to some length and it's a soupy mess out there. Any advice would be greatly appreciated.

I currently provide the Apache License from NetFlix at the root.

答:
I am not a lawyer, and this is not legal advice. You should hire an attorney who can advise you on the correct course of action. The following are, to my knowledge, the steps required to meet the requirements of both licenses.

Your software must include a relatively prominent Copyright notice that says something to the effect:

This software includes code from: AngularJS, Copyright (C) 2010-2012 Google, Inc., and Karyon, Copyright (C) 2013 Netflix, Inc.

Then, you must also include a copy of the MIT license shipped with AngularJS (the license requires that the Copyright notice and the license's warranty notice are both included in all copies) and the Apache License from Karyon (which also requires a notice of the Copyright and the warranty disclaimer). Both of these licenses should be copied, in full, into a file called NOTICES included in your project.

You are free to distribute the code under whatever open source license you see fit, not including the GPL or LGPL versions 1 or 2, or any other similar Copyleft license (GPLv3 is fine, as it's compatible with Apache v2). I recommend continuing to use the Apache v2 license. The license you choose to use should be placed in a file called LICENSE included in your project.

Again, I recommend consulting an attorney to ensure that you've met all requirements of the Apache license, before redistribution.

Title: Open source licensing of derived works


答:
Yes you should ask questions! But ask the right people, and at the right times! Be aware that not everyone believes that "there's no such thing as a dumb question", those people don't like to be pestered with minor queries but if you have something interesting to discuss they will spend time with you.

Don't obsess about your age! Stop thinking of people as being two, or seven, or fifteen years older than you. You're young, you know it, they know it, it's not a problem.

You're at the age where your brain is developing fast, so you will be able to learn a LOT very quickly. Push yourself and you will find that you will exceed what you thought were your limits.

As time passes you will discover where your interests lie. You may be into languages and algorithms, you may be into technology, you may be into UI and UX design, and you may be into developing relationships with partners and customers.

Stay open minded, and enjoy it. Welcome to our world!

Title: Ways for a young programmer to not feel intimidated at my first REAL programming job?

Body:
I'd like to state first that I'm a 19 year old programmer living in Portugal, and have recently started my first REAL programming job.

I say "REAL" because at my previous jobs, I was normally the sole developer just working on creating and updating a sole website and further developing ideas for the company. (I've worked for a nightclub, for example) This did not work out, as said nightclub ran into some finance troubles and I decided to leave for my own good.

Naturally, due to (at least where I live) pre-conceived notions due to my age, I started offering myself to do projects pro-bono for many different companies, hoping it would help me get a job offer after a while. That day came last week, when I was offered a job at a website-based company, after they noticed my work. Naturally I was ecstatic and still am! I had my job interview today and it went very well, with me starting working there next week.

Even if this is all good news, I can't help but feel overwhelmed. This company is the real deal and is filled to the brim with excellent programmers in their late 20's to early 40's, whereas I am the youngest programmer they have ever hired (they made sure to tell me that at the interview) at age 19. I am not doubting my capacities due to my age and know deep inside that I'll do well after the initial gelling phase, seeing as they do not use any languages/technologies that are foreign to me, but I'm not entirely sure if everybody sees it the same way. I got the idea that my age was a big thing to them at the interview and was considered a risk, seeing as most people are 6-7 years older than me, which intimidates me quite a bit.

Does anyone have any advice or similar experiences they'd like to share? I may be overreacting as the interview went well and I seemed to impress, yet I just can't get this particular fear off my mind.


问:
How can a developer working alone respond to a spike in server demands?
Imagine this scenario:

You've created a multiplayer game app for a mobile platform such as Android. You successfully set it up with one server, you figured out how to do that. It works quite well.

To your surprise, the game TAKES OFF. Server demands explode. You need to scale, but you have hardly any experience with running a single server, let alone running multiple servers in tandem.

What do you do? Is there a service (Heroku-style) to help with such a thing? Anything? Or do you need to hire someone with a certain skill set and the necessary experience?

答:
1. On app level

Running an app on multiple servers isn't terribly hard. There are techniques which are difficult to understand and implement, but there are also some basic techniques any one can use.

Learn those basic techniques. If it's not enough, then yes, you'll have to find a freelancer or to hire a developer.

2. On infrastructure level

Running servers yourself (read "at home") is very difficult. Most of the small companies which believe they have their data center are doing it wrong. Their "data centers" are not secure, badly managed, not protected against problems with power, etc.

Many developers, including myself, have a PC at home which runs day and night. We call them servers. They are not, but it doesn't matter, since it's funny to say: "I have a server at home".

Other people are using hosting companies, which most often don't include any scalability. If you're intended to use a fixed number of machines forever, you're lucky. If your app starts to be very popular, issues arise.

Cloud as a technical term, i.e. something like Windows Azure, not *cloud" as a marketing buzzword, like iCloud, helps you to solve that. You can easily scale the infrastructure from one to hundreds of servers in a few minutes, then to scale down again if needed.