[swift-evolution] [Idea] Extending syntax for `extension`

Braeden Profile jhaezhyr12 at gmail.com
Mon Dec 5 15:48:35 CST 2016


I really enjoy having the ability to write and nesting my code at the appropriate indentation level in my file.  Extensions are fabulous, but I wonder—solely for readability/style sake, could we allow you to properly namespace your extensions?  Though I don’t know the implementation cost of this, I think it could be useful to be able to write this:

class MathEvaluator
{
	struct Number
	{
		let value: Double
	}
	
	struct Operation
	{
		let numbers: (Number, Number)
		let transform: (Double, Double) -> Double
	}
	
	extension Number
	{
		var factors: [Double]
		{
			// Calculate and return the factors
		}
	}
}

…which would be completely equivalent to:

class MathEvaluator
{
	struct Number
	{
		let value: Double
	}
	
	struct Operation
	{
		let numbers: (Number, Number)
		let transform: (Double, Double) -> Double
	}
}
	
extension MathEvaluator.Number
{
	var factors: [Double]
	{
		// Calculate and return the factors
	}
}

This change is in the same ball park as this, proposed a week or two ago:

struct MathEvaluator.Number
{
	let value: Double
	
	var factors: [Double]
	{
		// Calculate and return the factors
	}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161205/f36919dd/attachment.html>


More information about the swift-evolution mailing list