I think the nature of structs in their present state—being visually tied to 
a `defmodule`—limits the thinking around them. I think that given the 
ability to create structs "at-will", opportunities will present themselves 
where one would've previously used a tuple or a plain map.

Some contrived examples:

defmodule Rectangle do
  defstruct Point, x: 0, y: 0

  ...
end

defmodule User do
  defstruct Name, first: "", middle: "", last: ""

  ...
end

I will admit that I have no direct experience to back up these claims 
though. I'll implement the macro in some of my own projects and try it out.

On Tuesday, December 27, 2016 at 3:42:39 PM UTC-5, Paul Schoenfelder wrote:
>
> I definitely wouldn't call this a severe limitation, but it would be a 
> nice-to-have for readability. That said, I haven't actually run into any 
> cases where I would've used the shorthand syntax - as José mentioned in his 
> original reply, the vast majority of the time, structs have functions that 
> go with them, or at the very least, typespecs. 
>
> I do think it's possible for there to be cases where the shorthand syntax 
> would be used, but I have to say that I haven't seen that in the wild, or 
> in my own projects yet, so I can't say the need is particularly dire to 
> have this in the standard library. It's easy to implement this as a macro 
> in your own projects if it's a common need though. I think a real-world use 
> case which demonstrates the value would go a long way towards making your 
> case.
>
> Paul
>
>
> On Tue, Dec 27, 2016 at 2:33 PM, Akio Burns <[email protected] 
> <javascript:>> wrote:
>
>> Has there been any further consideration on this topic? Structs are 
>> great, but they feel severely limited without the ability to easily and 
>> cleanly define arbitrarily named structs.
>>
>>
>> On Wednesday, March 19, 2014 at 5:43:45 PM UTC-4, José Valim wrote:
>>>
>>> That won't be the case for now. Structs are different than records. 
>>> Cases where you define a module simply to define a struct should be more 
>>> uncommon, I expect it to rather have struct-related functions the majority 
>>> of the time.
>>>
>>> So having only defstruct/1 will help send this message across. After 
>>> v0.13 is out and we are more familiar with structs, we can re-evaluate the 
>>> shortcut syntax again.
>>>
>>>
>>>
>>> *José Valim*
>>> www.plataformatec.com.br
>>> Skype: jv.ptec
>>> Founder and Lead Developer
>>>
>>>
>>> On Wed, Mar 19, 2014 at 10:20 PM, Dave Thomas <[email protected]> 
>>> wrote:
>>>
>>>> Would there be any support for extending defstruct so that
>>>>
>>>> defstruct Person, name: "", age: 21
>>>>
>>>> was a shortcut for
>>>>
>>>> defmodule Person
>>>>   defstruct name: "", age: 21
>>>> end
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "elixir-lang-core" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/716bde83-ad19-46ad-896f-90be5493c035%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/716bde83-ad19-46ad-896f-90be5493c035%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/9f48d9f0-8cd0-4e92-a838-bcc3b92a3917%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to