I'm a big proponent of the Nordic system, which constitutes primarily of emphasizing social freedom, well-regulated markets, and low income disparity. This is achieved not by adherence to political ideology, but rather by analyzing empirical evidence and employing the scientific method to determine the best ways in which to promote these goals. Take healthcare for instance -- Nordic countries have publicly funded universal health care not because a bunch of people voted in a bunch of freebies for themselves, but because it was cheaper and more effective than private health care. Likewise, they went with restrictive immigration policies because they can't maintain these benefits if they have an outside group willing to work for cheap. It's not about right or left (though it mostly leans left, since that's where the best benefit to cost ratio usually lies), it's about creating a high quality of life for the people of your country.
But one could argue that a polygamist should be entitled to have all his wives covered by the insurance offered by his job and that the polygamist should be able to use income splitting on his taxes with all his wives. That's the point trying to be made here. Why is one type of relationship the only valid one. Why not allow marriages between more than 2 people?
We should allow it, honestly. There's no compelling reason not to.
That's the fundamental problem with economic security. It's always at someone else's expense and the effort to avoid risk can be quite perverse in its consequences.
"The problem with enforcing property rights is that its always at someone else's expense. Why should I pay for police who only stop me from taking the nice stuff my neighbor has?"
*Everything* is at someone else's expense in some way or another, because contrary to what you believe, no man is an island. So put down Atlas Shrugged and go learn about life.
As the span of time reaches infinity the probability of a global catastrophic event approaches 1. It *will* happen eventually.
This assumes a fixed probability over all time.
If the probability lowers over time, then the cumulative probability can be bounded to any chosen value.
No, it doesn't. For the sake of argument, let us assume that the probability of global thermonuclear war in 2014, 2015, and 2016 is.001,.0001, and 0 (zero chance) respectively. So our chance of surviving 2014 is 1.0 - 0.001 =.999. Our chance of p(2015) = p(2014) * p(2015) =.999 *.9999 = 0.9989001, which is less than the.999 of p(2014). Even if p(2016) is 100% chance for survival, 1.0 * 0.999 * 0.9999 = 0.9989001, which means our chances of surviving have not increased, they have merely not decreased. And as long as the chance is non-zero (and it always will be), the chance of our survival for n+1 years is always lower than the chance of our survival for n years.
The nordics are not socialist. They are social democrats with a mixed economy where the government assumes responsibility for some critical infrastructure while aggressively breaking up cartels and preventing (to some extent) collusion in an otherwise free market in order to keep the markets free.
Actually, the nordics are good examples of libertarian ideals.
Yes, of Left Libertarian ideals, but those are almost completely unknown, and probably anathema, to most American libertarians.
Mod parent up. I wish American libertarians could mentally grasp the fact that "liberty" is meaningless in the absence of economic security.
There is no shortage of qualified technical workers in the US who are unwilling to relocate to where the jobs are. Meanwhile, in the ares where there are jobs, I have 10 open recs right now and haven't been able to find anyone even remotely qualified. The budget for fiscal '14 hasn't been finalized, but I'll probably have another 6 heads in Q1. Which is all just on paper anyways because I doubt I'll find more than 2-3 qualified candidates and I'll be lucky to have 1-2 accept our offer. I've got numerous friends at other companies who are experiencing the same thing. If you can't get hired in San Francisco right now you either aren't qualified, have wildly outlandish salary demands (moderately outlandish salary demands are considered reasonable these days) or simply don't know how to look for jobs.
Companies want H1-Bs because they don't have an attachment to any geographical area and are willing to move to where the jobs are. To anyone that's bitching about H1-Bs or lack of jobs...consider moving to the bay area...it costs a shit ton to live here, but you'll get paid a shit ton plus to work here.
Move your HQ a few hundred miles up to Portland and you'll find no trouble filling those spots. People don't always mind relocating, but they want to move somewhere that they can one day buy a house, and that is not the case in the bay area.
News flash, bad people do bad things and wishing guns away doesn't fix it.
besides, given his comment about eating hearts, clearly what we need is better utensil control laws. We can't have a bunch of heart eating maniacs getting their hands on forks, now can we?
So then let's just arm everyone with a nuke. After all, everyone is a rational actor and would never risk global annihilation, right?
The arm-people-with-nukes argument against gun ownership makes as much sense as the people-can-marry-animals argument against gay marriage. Ridiculous hyperbole doesn't do anyone any favors.
It's called reductio ad absurdum and it is a valid form of argument showing that a line of reasoning leads to a ridiculous conclusion. In this instance I'm attempting to show that interpretation of the right to weapons, if unlimited, leads to absurd results, and thus specific limits need to apply. The anti-gay marriage argument, on the other hand, is a slippery slope argument attempting to show that consenting marriage between adults will lead to child brides, bestiality, denderphelia, etc., without showing any clear circumstance in which it could lead to that.
and the second amendment does not clarify the limits of that right
I really believe people should move to amend the constitution if they feel something should be changed or clarified.
I agree, but there's little chance of that happening because we treat the Constitution as a sacred text (we're even supposed to capitalize it!). Honestly it seems clear that half the country (on the coasts mostly) wants something different than the other half (middle of the country, mostly). I wish we could just have a clean break, no hard feelings, and we could all be happy with our respective governments.
You're right, I went off on a rant (stupid HTML shit pissed me off at work). The banning cars argument is stupid. How's this argument.
Drunk drivers kill people , but people still do it, therefore we need to ban or license alcohol.
Is basically the same argument as
Criminals with guns kill people, therefore we need to either ban or require a license to own a gun.
Both of these are stupid arguments when looked at logically, criminals will break the law, while non-criminals won't. Requiring a license to buy a gun or alcohol will not stop people from getting killed. It might make it a little harder, but I doubt it. The Newtown shooting happened because a person stole guns from a law-abiding citizen. Had his mother had a license or not, it doesn't matter, those kids are still dead. The same thing in Virginia Tech. The student bought guns, after a background check. What more laws do we need? What is different between having to have a background check or having to have a license to buy a gun?
You're right in that such incidences are very hard to prevent, and would require drastic legislation for marginal effect (like the Australian rifle involuntary buy-back. it worked, but it would never fly here). Where a registry does help is with the numerous murders and other gun related crimes committed by career criminals. As it is, it is nearly impossible to trace a gun because we've put up massive legal barriers to doing so. If we merely kept better track of legal weapon purchases, we could not only solve gun crimes more quickly, but we could also go after "rogue buyers" who purchase weapons for criminals at a markup.
Not necessarily. There is no absolute line to be drawn. That said, unless there is a chance of a catastrophe, I don't believe people's liberties should be curtailed (meaning that I don't believe people should be banned from having something just because there's a potential for abuse).
This is the point I'm trying to make.. There's a debate to be had on what a catastrophe is, and a unilateral "you can take my gun when you pry it from my cold, dead hands" approach is not a constructive or rational argument. Guns are not different in effect from tire irons, knives, machetes, pipe bombs, napalm, nukes, etc. They are, however, different in both availability and in destructive capability. There's a debate to be had about how much is too much, and the second amendment does not clarify the limits of that right, and is ambiguous in who it pertains to. Going even further, the founding fathers did not believe the constitution should be set in stone (hence all the early amendments), and the philosophy of John Locke (whose writings inspired most of the founding fathers in the first place) outlined "life, liberty, and property" and the inalienable rights. It is not all clear that the founding fathers would have supported gun rights today, and I think that needs to be taken into consideration when we talk about what is or is not a "right".
It's also illegal to go around and kill people with a gun. Still happens. You can't protect people by taking away rights. Criminals are going to commit crimes.
Ah, the "laws just get broken, so lets not have laws" defense! I think we're done here, you've thoroughly discredited all of your ideas, but I'm sure you'll still cling to your second amendment with disregard to all the other "rights" in which those arms of yours were supposed to protect.
The difference is destructive power. One person going insane with a working gun could never do as much damage as someone with full access to a powerful nuclear weapon. Unless an action could cause the deaths of thousands, individual liberties must be preserved.
So your cutoff is 1000? If you cutoff was 10, would you not then be obligated to advocate a ban on AR-15s? Why do you assume your line in the sand is the correct one?
Every day in America, another 27 people die as a result of drunk driving crashes. That's over 9500 people a year. There are 211,000,000 registered drivers I propose we ban either cars or alcohol. I'll let you pick. The death rate is about the same number, but the number of drivers is less than the number of guns, so you're more likely to be killed by a drunk driver than you are to be shot to death. Not much though. I assume you agree with me that all cars or alcohol should be banned? Or maybe you just think we should only allow smaller cars. Nobody really needs to drive a 2-ton dually death machine anyways. Or maybe we should just ban all alcohol but wine. Nobody ever gets drunk on wine and drives a car. And no the argument that it's fun to just drink a few beers in not a strong argument for not banning alcohol.
Except your argument is extremely flawed, because we've already drastically reduced the vehicular death rate through safety improvements and drunk driving initiatives. There's plenty more we could do, but it is in no way analogous to *complete inaction* in regards to gun-related crime. Also, note that, unlike a gun, it *is* illegal to operate a vehicle without a license.
I'm generally curious what you mean by sane gun restrictions? Felons aren't allowed to purchase or carry a gun, if you've been convicted of domestic violence, you can't purchase or carry a gun?
There are over 300 million legally acquired weapons, and only two of them have been used in a mass shooting this year. And they weren't legally acquired by the person who used them.
And yet the total number of gun-related homicides in the US (not counting suicides and accidents) tends to hover around 10,000 per year, an order of magnitude greater than all other murders combined. Having an actual background check with a centralized weapon registry would go a long way in solving gun-related murder cases and preventing illegal weapon sales, thus putting downward pressure on "ordinary" gun-related homicides. Restrictions on magazine size and "assault weapons" would go a long way in terms of preventing mass murders, though their effect on the overall total of homicides would be negligible. That said, an AR-15 is not a good hunting rifle, and is not an appropriate home defense weapon (you're very likely to shoot your neighbors the next house over, but not any more likely to hit an intruder than you are with a semi-auto hand gun). The only arguments for having one that has even a shred of legitimacy is the "it's fun to shoot" argument, and that's not a very strong argument against preventing mass murders.
News flash, bad people do bad things and wishing guns away doesn't fix it.
besides, given his comment about eating hearts, clearly what we need is better utensil control laws. We can't have a bunch of heart eating maniacs getting their hands on forks, now can we?
So then let's just arm everyone with a nuke. After all, everyone is a rational actor and would never risk global annihilation, right?
It wasn't funny at all. It also wasn't a credible or targeted threat any more than claiming he was gonna get a Harry Potter wand and turn everyone into frogs.
If we had sane gun restrictions in this country, what you just said would be true.
Your example clearly shows, you don't know what a nested function is:)
Your example is a closure, and as you named it and obviously want to reuse it, it MIMICS a nested function, but is not.
Main difference: a nested function is static compiled. Your square is dynamic assigned at runtime.
I'm not sure about Scala, but I believe it has no nested functions either, only closures.
There's a lot that's wrong here, so I'll just go point by point.
1.) This is not a closure, it's an anonymous function, which is analogous to a nested function. I purposefully coded it that way to avoid the confusion, though a closure is still a nested function, just of a specific variety. In C#, all closures are anonymous methods, but the reverse is not true. From the article:
The term closure is often mistakenly used to mean anonymous function. This is probably because many programmers learn about both concepts at the same time, in the form of small helper functions that are anonymous closures. An anonymous function is a function without a name, while a closure is a function instance whose non-local variables have been bound either to values or to storage locations (depending on the language; see the lexical environment section below). An anonymous function may or may not be a closure, and a closure may or may not be anonymous.
2.) Anonymous methods (including closures) in C# are compiled as separate static methods (closures are handled as a new type instead, but are still compiled). See here. You can structure something to be compiled at runtime, but that is a different issue.
3.) The time at which a nested function is compiled has no bearing on whether or not it is a function. If that was the case, then you would have to claim that all nested functions in interpreted languages are not "true" nested functions. And since a nested function is just a function inside another function, you would then have to claim that interpreted languages do not support functions.
So I suggest you do your research next time before you run your mouth.
On the other hand, even if code isn't used in more than one place, that doesn't mean it's not "expressing something concisely".
Additionally:
1) Methods are great ways of naming orthogonal snippets of code, rather than using a comment that may become obsolete.
2) Breaking large methods into smaller ones increases maintainability by enforcing certain constraints such as not reusing variables declared 100 lines up just because they happen to serve similar purposes.
I agree that you don't want to just arbitrarily break your method up for the sake of smaller methods, but I don't think reuse is necessarily the best way to judge whether methods should be refactored.
You make a fair point there. I'm fully satisfied with breaking code into "reusable" blocks, even if they aren't "reused". My complaint is more toward tightly coupled functions, which is what I often see in refactoring scenarios.
I consider lambdas and inner functions to be quite different types of biests. How would you write a lambda that has itself 10 to 20 lines of code? How would you nest another function inside a lambda expression?
well, in C# you do this:
public void Foo(int x) {
Func pow = (num,pow) => {
Func mult = (a, b) => a * b;
int result = 1;
for (int i = 0; i < pow; i++) result = mult(result, num);
return result;
}
Console.Write(pow(x, 3));
}
In my experience most attempts to reduce function line count without regard to code reuse leads to tightly coupled messes. It may not be apparent to the original developer, but the poor maintainer has to dig through tons of code randomly scattered about in order to make sense of what should be a linear function. Note that I also do not state this as dogma (carefully read my original post and you'll see that I say his coworker "may have a point", not that he necessarily does). There are times when you can create a nice distinction by splitting into multiple single-use functions, and this is best handled with nested functions if they're supporting in the language you're using. I would say this is the exception rather than the rule, however. Most code can be more cleanly broken up by reusable functions than non-reusable ones.
I'm a big proponent of the Nordic system, which constitutes primarily of emphasizing social freedom, well-regulated markets, and low income disparity. This is achieved not by adherence to political ideology, but rather by analyzing empirical evidence and employing the scientific method to determine the best ways in which to promote these goals. Take healthcare for instance -- Nordic countries have publicly funded universal health care not because a bunch of people voted in a bunch of freebies for themselves, but because it was cheaper and more effective than private health care. Likewise, they went with restrictive immigration policies because they can't maintain these benefits if they have an outside group willing to work for cheap. It's not about right or left (though it mostly leans left, since that's where the best benefit to cost ratio usually lies), it's about creating a high quality of life for the people of your country.
But one could argue that a polygamist should be entitled to have all his wives covered by the insurance offered by his job and that the polygamist should be able to use income splitting on his taxes with all his wives. That's the point trying to be made here. Why is one type of relationship the only valid one. Why not allow marriages between more than 2 people?
We should allow it, honestly. There's no compelling reason not to.
And that's unique to India, how?
It's not, it's just much more prevalent in India because the culture there has not attached a negative social stigma to being a tech worker.
That's the fundamental problem with economic security. It's always at someone else's expense and the effort to avoid risk can be quite perverse in its consequences.
"The problem with enforcing property rights is that its always at someone else's expense. Why should I pay for police who only stop me from taking the nice stuff my neighbor has?"
*Everything* is at someone else's expense in some way or another, because contrary to what you believe, no man is an island. So put down Atlas Shrugged and go learn about life.
As the span of time reaches infinity the probability of a global catastrophic event approaches 1. It *will* happen eventually.
This assumes a fixed probability over all time.
If the probability lowers over time, then the cumulative probability can be bounded to any chosen value.
No, it doesn't. For the sake of argument, let us assume that the probability of global thermonuclear war in 2014, 2015, and 2016 is .001, .0001, and 0 (zero chance) respectively. So our chance of surviving 2014 is 1.0 - 0.001 = .999. Our chance of p(2015) = p(2014) * p(2015) = .999 * .9999 = 0.9989001, which is less than the .999 of p(2014). Even if p(2016) is 100% chance for survival, 1.0 * 0.999 * 0.9999 = 0.9989001, which means our chances of surviving have not increased, they have merely not decreased. And as long as the chance is non-zero (and it always will be), the chance of our survival for n+1 years is always lower than the chance of our survival for n years.
Not health care expenses, but overall costs. Dead smokers will not draw a pension, for example.
And non-smokers will?
The nordics are not socialist. They are social democrats with a mixed economy where the government assumes responsibility for some critical infrastructure while aggressively breaking up cartels and preventing (to some extent) collusion in an otherwise free market in order to keep the markets free.
Actually, the nordics are good examples of libertarian ideals.
Yes, of Left Libertarian ideals, but those are almost completely unknown, and probably anathema, to most American libertarians.
Mod parent up. I wish American libertarians could mentally grasp the fact that "liberty" is meaningless in the absence of economic security.
Perhaps the concern over "lost knowledge" says a lot about people's perception that some massive apocalyse is going to happen.
As the span of time reaches infinity the probability of a global catastrophic event approaches 1. It *will* happen eventually.
There is no shortage of qualified technical workers in the US who are unwilling to relocate to where the jobs are. Meanwhile, in the ares where there are jobs, I have 10 open recs right now and haven't been able to find anyone even remotely qualified. The budget for fiscal '14 hasn't been finalized, but I'll probably have another 6 heads in Q1. Which is all just on paper anyways because I doubt I'll find more than 2-3 qualified candidates and I'll be lucky to have 1-2 accept our offer. I've got numerous friends at other companies who are experiencing the same thing. If you can't get hired in San Francisco right now you either aren't qualified, have wildly outlandish salary demands (moderately outlandish salary demands are considered reasonable these days) or simply don't know how to look for jobs.
Companies want H1-Bs because they don't have an attachment to any geographical area and are willing to move to where the jobs are. To anyone that's bitching about H1-Bs or lack of jobs...consider moving to the bay area...it costs a shit ton to live here, but you'll get paid a shit ton plus to work here.
Move your HQ a few hundred miles up to Portland and you'll find no trouble filling those spots. People don't always mind relocating, but they want to move somewhere that they can one day buy a house, and that is not the case in the bay area.
News flash, bad people do bad things and wishing guns away doesn't fix it.
besides, given his comment about eating hearts, clearly what we need is better utensil control laws. We can't have a bunch of heart eating maniacs getting their hands on forks, now can we?
So then let's just arm everyone with a nuke. After all, everyone is a rational actor and would never risk global annihilation, right?
The arm-people-with-nukes argument against gun ownership makes as much sense as the people-can-marry-animals argument against gay marriage. Ridiculous hyperbole doesn't do anyone any favors.
It's called reductio ad absurdum and it is a valid form of argument showing that a line of reasoning leads to a ridiculous conclusion. In this instance I'm attempting to show that interpretation of the right to weapons, if unlimited, leads to absurd results, and thus specific limits need to apply. The anti-gay marriage argument, on the other hand, is a slippery slope argument attempting to show that consenting marriage between adults will lead to child brides, bestiality, denderphelia, etc., without showing any clear circumstance in which it could lead to that.
and the second amendment does not clarify the limits of that right
I really believe people should move to amend the constitution if they feel something should be changed or clarified.
I agree, but there's little chance of that happening because we treat the Constitution as a sacred text (we're even supposed to capitalize it!). Honestly it seems clear that half the country (on the coasts mostly) wants something different than the other half (middle of the country, mostly). I wish we could just have a clean break, no hard feelings, and we could all be happy with our respective governments.
You're right, I went off on a rant (stupid HTML shit pissed me off at work). The banning cars argument is stupid. How's this argument.
Drunk drivers kill people , but people still do it, therefore we need to ban or license alcohol.
Is basically the same argument as
Criminals with guns kill people, therefore we need to either ban or require a license to own a gun.
Both of these are stupid arguments when looked at logically, criminals will break the law, while non-criminals won't. Requiring a license to buy a gun or alcohol will not stop people from getting killed. It might make it a little harder, but I doubt it. The Newtown shooting happened because a person stole guns from a law-abiding citizen. Had his mother had a license or not, it doesn't matter, those kids are still dead. The same thing in Virginia Tech. The student bought guns, after a background check. What more laws do we need? What is different between having to have a background check or having to have a license to buy a gun?
You're right in that such incidences are very hard to prevent, and would require drastic legislation for marginal effect (like the Australian rifle involuntary buy-back. it worked, but it would never fly here). Where a registry does help is with the numerous murders and other gun related crimes committed by career criminals. As it is, it is nearly impossible to trace a gun because we've put up massive legal barriers to doing so. If we merely kept better track of legal weapon purchases, we could not only solve gun crimes more quickly, but we could also go after "rogue buyers" who purchase weapons for criminals at a markup.
So your cutoff is 1000?
Not necessarily. There is no absolute line to be drawn. That said, unless there is a chance of a catastrophe, I don't believe people's liberties should be curtailed (meaning that I don't believe people should be banned from having something just because there's a potential for abuse).
This is the point I'm trying to make.. There's a debate to be had on what a catastrophe is, and a unilateral "you can take my gun when you pry it from my cold, dead hands" approach is not a constructive or rational argument. Guns are not different in effect from tire irons, knives, machetes, pipe bombs, napalm, nukes, etc. They are, however, different in both availability and in destructive capability. There's a debate to be had about how much is too much, and the second amendment does not clarify the limits of that right, and is ambiguous in who it pertains to. Going even further, the founding fathers did not believe the constitution should be set in stone (hence all the early amendments), and the philosophy of John Locke (whose writings inspired most of the founding fathers in the first place) outlined "life, liberty, and property" and the inalienable rights. It is not all clear that the founding fathers would have supported gun rights today, and I think that needs to be taken into consideration when we talk about what is or is not a "right".
It's also illegal to go around and kill people with a gun. Still happens. You can't protect people by taking away rights. Criminals are going to commit crimes.
Ah, the "laws just get broken, so lets not have laws" defense! I think we're done here, you've thoroughly discredited all of your ideas, but I'm sure you'll still cling to your second amendment with disregard to all the other "rights" in which those arms of yours were supposed to protect.
The difference is destructive power. One person going insane with a working gun could never do as much damage as someone with full access to a powerful nuclear weapon. Unless an action could cause the deaths of thousands, individual liberties must be preserved.
So your cutoff is 1000? If you cutoff was 10, would you not then be obligated to advocate a ban on AR-15s? Why do you assume your line in the sand is the correct one?
Every day in America, another 27 people die as a result of drunk driving crashes. That's over 9500 people a year. There are 211,000,000 registered drivers I propose we ban either cars or alcohol. I'll let you pick. The death rate is about the same number, but the number of drivers is less than the number of guns, so you're more likely to be killed by a drunk driver than you are to be shot to death. Not much though. I assume you agree with me that all cars or alcohol should be banned? Or maybe you just think we should only allow smaller cars. Nobody really needs to drive a 2-ton dually death machine anyways. Or maybe we should just ban all alcohol but wine. Nobody ever gets drunk on wine and drives a car. And no the argument that it's fun to just drink a few beers in not a strong argument for not banning alcohol.
Except your argument is extremely flawed, because we've already drastically reduced the vehicular death rate through safety improvements and drunk driving initiatives. There's plenty more we could do, but it is in no way analogous to *complete inaction* in regards to gun-related crime. Also, note that, unlike a gun, it *is* illegal to operate a vehicle without a license.
An anonymous function and a closure are the same thing, with two different words for it ...
Ofc they are compiled "statically" but they are asigned dynamic to the variable you used in your example.
My point simoly is: your examples are not nested functions but workarounds for the lack of native nested functions.
No, they're clearly not the same thing, as you would see if you RTFA. Just because you say something over and over doesn't make it true.
I'm generally curious what you mean by sane gun restrictions? Felons aren't allowed to purchase or carry a gun, if you've been convicted of domestic violence, you can't purchase or carry a gun?
There are over 300 million legally acquired weapons, and only two of them have been used in a mass shooting this year. And they weren't legally acquired by the person who used them.
And yet the total number of gun-related homicides in the US (not counting suicides and accidents) tends to hover around 10,000 per year, an order of magnitude greater than all other murders combined. Having an actual background check with a centralized weapon registry would go a long way in solving gun-related murder cases and preventing illegal weapon sales, thus putting downward pressure on "ordinary" gun-related homicides. Restrictions on magazine size and "assault weapons" would go a long way in terms of preventing mass murders, though their effect on the overall total of homicides would be negligible. That said, an AR-15 is not a good hunting rifle, and is not an appropriate home defense weapon (you're very likely to shoot your neighbors the next house over, but not any more likely to hit an intruder than you are with a semi-auto hand gun). The only arguments for having one that has even a shred of legitimacy is the "it's fun to shoot" argument, and that's not a very strong argument against preventing mass murders.
News flash, bad people do bad things and wishing guns away doesn't fix it.
besides, given his comment about eating hearts, clearly what we need is better utensil control laws. We can't have a bunch of heart eating maniacs getting their hands on forks, now can we?
So then let's just arm everyone with a nuke. After all, everyone is a rational actor and would never risk global annihilation, right?
It wasn't funny at all. It also wasn't a credible or targeted threat any more than claiming he was gonna get a Harry Potter wand and turn everyone into frogs.
If we had sane gun restrictions in this country, what you just said would be true.
Btw, this actually explains anonymous functions and lambdas much better.
Your example clearly shows, you don't know what a nested function is :)
Your example is a closure, and as you named it and obviously want to reuse it, it MIMICS a nested function, but is not.
Main difference: a nested function is static compiled. Your square is dynamic assigned at runtime.
I'm not sure about Scala, but I believe it has no nested functions either, only closures.
There's a lot that's wrong here, so I'll just go point by point.
1.) This is not a closure, it's an anonymous function, which is analogous to a nested function. I purposefully coded it that way to avoid the confusion, though a closure is still a nested function, just of a specific variety. In C#, all closures are anonymous methods, but the reverse is not true. From the article:
The term closure is often mistakenly used to mean anonymous function. This is probably because many programmers learn about both concepts at the same time, in the form of small helper functions that are anonymous closures. An anonymous function is a function without a name, while a closure is a function instance whose non-local variables have been bound either to values or to storage locations (depending on the language; see the lexical environment section below). An anonymous function may or may not be a closure, and a closure may or may not be anonymous.
2.) Anonymous methods (including closures) in C# are compiled as separate static methods (closures are handled as a new type instead, but are still compiled). See here. You can structure something to be compiled at runtime, but that is a different issue.
3.) The time at which a nested function is compiled has no bearing on whether or not it is a function. If that was the case, then you would have to claim that all nested functions in interpreted languages are not "true" nested functions. And since a nested function is just a function inside another function, you would then have to claim that interpreted languages do not support functions.
So I suggest you do your research next time before you run your mouth.
On the other hand, even if code isn't used in more than one place, that doesn't mean it's not "expressing something concisely".
Additionally: 1) Methods are great ways of naming orthogonal snippets of code, rather than using a comment that may become obsolete. 2) Breaking large methods into smaller ones increases maintainability by enforcing certain constraints such as not reusing variables declared 100 lines up just because they happen to serve similar purposes.
I agree that you don't want to just arbitrarily break your method up for the sake of smaller methods, but I don't think reuse is necessarily the best way to judge whether methods should be refactored.
You make a fair point there. I'm fully satisfied with breaking code into "reusable" blocks, even if they aren't "reused". My complaint is more toward tightly coupled functions, which is what I often see in refactoring scenarios.
I consider lambdas and inner functions to be quite different types of biests. How would you write a lambda that has itself 10 to 20 lines of code? How would you nest another function inside a lambda expression?
well, in C# you do this:
public void Foo(int x) {
Func pow = (num,pow) => {
Func mult = (a, b) => a * b;
int result = 1;
for (int i = 0; i < pow; i++) result = mult(result, num);
return result;
}
Console.Write(pow(x, 3));
}
In my experience most attempts to reduce function line count without regard to code reuse leads to tightly coupled messes. It may not be apparent to the original developer, but the poor maintainer has to dig through tons of code randomly scattered about in order to make sense of what should be a linear function. Note that I also do not state this as dogma (carefully read my original post and you'll see that I say his coworker "may have a point", not that he necessarily does). There are times when you can create a nice distinction by splitting into multiple single-use functions, and this is best handled with nested functions if they're supporting in the language you're using. I would say this is the exception rather than the rule, however. Most code can be more cleanly broken up by reusable functions than non-reusable ones.