Minggu, 06 Februari 2011
Scrum Startup Founders Cash Out in One Year
Documenting functions and named parameters
functoin myListener(event: MouseEvent, custom :String, custom2 : int) : void;
While the exact syntax above would not be possible, closures are in any case the way to go. I explained him how I’d do it and I forgot about the topic until today.
Today while waiting for a long compilation process to complete I’ve came up with an idea on how to improve code readability on cases similar to this. Here’s the cleaneast syntax I’ve came up with (ideas are more than welcome to improve it):
Does it look too verbose? I guess it will highly depend on the exact use case where this is used. But under some circumstances I think the readability can be substantially improved.
createListenerAdapterBasedOn is a package level method. I could have used a utility static method like FunctionUtils.createListenerAdapter. But instead I’ve used a package function because I can reduce the length of the Class + method name (or use the same number of characters to add verbosity and clarity). On the other hand it’s unlikely that this utility class would have more methods.
Documenting functions
This is a concept I’ve never read about or used before, but I think I’ll start using in different places. withParameters method is a completely dummy method that simply returns the parameters it gets but giving them a semantic and contextual meaning. The solely purpose of this method is to improve the readability by converting the method invocation in a Fluent API that can be read as natural language. The method is simply documenting the usage of the call. Putting this together with the Builder pattern and named parameters I discussed a while ago it gives us an incredible weapon to create self-documented code that doesn’t need most-of-the-times useless, needless and confusing ASDoc or inline comments.
If necessary when you have a method accepting several parameters of the same type and that can be confusing to read you could used Documenting functions to create kind of named-parameters:
Here are the details of the implementation in case you are interested in seeing the internal details and some of the tests.
createListenerAdapterBasedOn.as
{
public function createListenerAdapterBasedOn(callback:Function, … args):Function
{
return function(… rest):*
{
if (args.length == 1)
return callback.apply(null, rest.concat(args[0]));
else
return callback.apply(null, rest.concat(args));
}
}
}
withParameters.as
createListenerAdapterBasedOnTest.as
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.MouseEvent;
import flashx.textLayout.debug.assert;
import org.flexunit.assertThat;
import org.hamcrest.object.equalTo;
public class ListenerUtilsTest
{
private static const ORIGINAL_PARAMETER:String = "originalParameter";
private static const FIRST_PARAM:String = "firstParam";
private static const SECOND_PARAM:String = "secondParam";
[Test]
public function createCallbackAdapterWithNoParameters():void
{
var callbackAdapter:Function = createListenerAdapterBasedOn(function(data:String):void
{
assertThat(ORIGINAL_PARAMETER, equalTo(data));
});
callbackAdapter(ORIGINAL_PARAMETER);
}
[Test]
public function createCallbackAdapterWithIndividualParameter():void
{
var callbackAdapter:Function = createListenerAdapterBasedOn(function(data:String, p1:String):void
{
assertThat(ORIGINAL_PARAMETER, equalTo(data));
assertThat(FIRST_PARAM, equalTo(p1));
}, withParameters(FIRST_PARAM));
callbackAdapter(ORIGINAL_PARAMETER);
}
[Test]
public function createCallbackAdapterWithIndividualParameterNoFluent():void
{
var callbackAdapter:Function = createListenerAdapterBasedOn(function(data:String, p1:String):void
{
assertThat(ORIGINAL_PARAMETER, equalTo(data));
assertThat(FIRST_PARAM, equalTo(p1));
}, FIRST_PARAM);
callbackAdapter(ORIGINAL_PARAMETER);
}
[Test]
public function createCallbackAdapterWithIndividualParameters():void
{
var callbackAdapter:Function = createListenerAdapterBasedOn(function(data:String, p1:String, p2:String):void
{
assertThat(ORIGINAL_PARAMETER, equalTo(data));
assertThat(FIRST_PARAM, equalTo(p1));
assertThat(SECOND_PARAM, equalTo(p2));
}, withParameters(FIRST_PARAM, SECOND_PARAM));
callbackAdapter(ORIGINAL_PARAMETER);
}
[Test]
public function createCallbackAdapterWithIndividualParametersNoFluent():void
{
var callbackAdapter:Function = createListenerAdapterBasedOn(function(data:String, p1:String, p2:String):void
{
assertThat(ORIGINAL_PARAMETER, equalTo(data));
assertThat(FIRST_PARAM, equalTo(p1));
assertThat(SECOND_PARAM, equalTo(p2));
}, FIRST_PARAM, SECOND_PARAM);
callbackAdapter(ORIGINAL_PARAMETER);
}
}
}
如果你的心裏裝得下另外一個女人,那我的床上就可以睡得下另外一個男人
1.有人把你放心上,有人把你放床上。 26.我允許你走進我的世界,但不許你在我的世界裏走來走去。
(圖文/網路 夢筠蒐輯整理分享) |
What is carbon?
This question and answer is part of the Guardian's ultimate climate change FAQ
• See all questions and answers
• Read about the project
Carbon is a chemical element, like hydrogen, oxygen, lead or any of the others in the periodic table.
Carbon is a very abundant element. It exists in pure or nearly pure forms – such as diamonds and graphite – but can also combine with other elements to form molecules. These carbon-based molecules are the basic building blocks of humans, animals, plants, trees and soils. Some greenhouse gases, such as CO2 and methane, also consist of carbon-based molecules, as do fossil fuels, which are largely made up of hydrocarbons (molecules consisting of hydrogen and carbon).
In the context of climate change, 'carbon' is commonly used as a shorthand for carbon dioxide, the most important greenhouse gas released by humans. Technically, however, this isn't accurate. Carbon only becomes carbon dioxide when each atom of carbon joins with two atoms of oxygen (hence the chemical formula of carbon dioxide, CO2).
This shorthand can sometimes cause confusion, because although 'a tonne of carbon' will often be used to mean 'a tonne of CO2', in a scientific context the same phrase could mean 'CO2 containing a tonne of carbon' (which is a much smaller amount, as oxygen accounts for most of the weight of each CO2 molecule).
The term carbon also crops up in the phrase carbon footprint, which describes the total amount of greenhouse gases released as the result of a given activity. In this context, 'a tonne of carbon' may mean something else still: 'a mix of greenhouse gases with a combined warming impact equivalent to that of a tonne of CO2'.
Carbon molecules move around the Earth system in the carbon cycle.
The ultimate climate change FAQ
• This answer last updated: 21.01.2010
• Read about the project and suggest a question
• Report an error in this answer
Related questions
• Is the world really getting warmer?
• Are humans definitely causing the warming?
• What are climate change feedback loops?
EU urged to overhaul fishing policy
Unprecedented alliance of retailers and conservationists urges drastic reform to prevent fish stocks from passing point of no return
Europe's fishing practices must be drastically reformed in order to prevent dwindling fish stocks passing the point of no return, a coalition of British supermarkets and conservationists warned today.
The unprecedented alliance, which includes Sainsbury's, Marks & Spencer, members of the UK's Food and Drink Federation and WWF, is making the strongest statement from business to date on the failures of the European Union fishing policy.
It follows public anger at the practice of discarding fish that was highlighted in Channel 4's Fish Fight series, which has prompted hundreds of thousands of people to sign a petition calling for reform.
Fishermen should no longer be forced to discard large amounts of their catch, as they do under the current system of EU fishing quotas, the coalition said, and the quotas should be reviewed so that stocks can recover.
Discarding is a long-standing and wasteful practice, resulting in as much as two-thirds of the fish caught being thrown back in the water, usually dead. About 1m tonnes are estimated to be thrown back each year in the North Sea alone. Discarding is a consequence of the strict quotas on the amount of fish that boats may land – when fishermen exceed their quota, or catch species of fish for which they do not have a quota, they must discard the excess.
The coalition is putting forward their proposals for a reformed common fisheries policy in a meeting with Maria Damanaki, the EU commissioner for fisheries, in London today.
The commission is in the process of reviewing the CFP, with a view to introducing reforms in two years. The EU is the world's fourth biggest producer of fish, both wild and farmed.
The coalition criticised the practice of discarding as 'the result of poor management and fishing practices that are not attuned to market and consumer needs', and said the CFP was not working.
The group, led by the green campaigning organisation WWF, said that fishermen would be better served by a different system, as the wasteful practice of discarding was a cost to fishing fleets.
Alternatives to discarding include allowing fishermen to land all the fish they catch, but restricting the days on which they are allowed to fish. Better technology can also help to ensure that fishermen are able to target particular species more closely.
The group called on governments to introduce long-term fishery management plans that would include fishermen, giving fleets a bigger role in 'co-managing' stocks rather than simply being handed quotas, as under the current system.
Super Bowl Movie Trailers: 'Captain America,' 'Transformers,' 'Pirates' and More
The Big Game is upon us, and with it will come what is perhaps the most anticipated slate of movie trailers we've seen in years. The 2011 Super Bowl featuring the Green Bay Packers taking on the Pittsburgh Steelers will play host to a number of brand new movie previews for some of the year's biggest films, like 'Captain America: The First Avenger,' 'Transformers: Dark of the Moon,' 'Pirates of the Caribbean: On Stranger Tides,' 'Cowboys and Aliens,' 'Super 8,' 'Thor,' 'Rango,' 'Kung Fu Panda: The Kaboom of Doom' and much more.
This post will serve as your home base for all the movie trailers that premiere before and during this year's Super Bowl. Please bookmark this page and keep coming back as we'll be continually updating it with trailers as soon as they arrive online.
Head after the jump to see what Super Bowl trailers are available right now ...
Continue Reading
'The Matrix 4' and '5': Are the Rumors True?
Even though this may well turn out to be just another cleverly orchestrated Keanu Reeves meme, the Internet is abuzz today with reports that the actor revealed to a group of London students that two more installments in 'The Matrix' franchise may be on the way -- in 3D, no less.
Now, before you start annoying all your friends by whipping out that lame 'There is no spoon' quote again, consider that the original source -- an anonymous Ain't It Cool News reader going by 'El-Nino' -- is questionable to the extreme and that Entertainment Weekly has already debunked the news. Still, we have to wonder if there isn't something to the rumors, given that the 'Matrix' franchise raked in more than $1.5 billion.
But after the debacles that were 2003's 'The Matrix Reloaded' and 'The Matrix Revolutions,' the two disjointed follow-ups to the truly groundbreaking 1999 original, the biggest question may be whether Reeves and the Wachowski brothers should expect anyone to care.
So, what do you think of this very intriguing and probably not true development? While you're contemplating, check our our pick for the best moment from 'The Matrix' trilogy below, and if you dare, click here to feast your eyes on the worst.
Continue Reading