# Designing interfaces for objects constructable from a file

**URL:** https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710
**Category:** General Usage
**Tags:** question
**Created:** [October 24, 2024, 3:47pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710 "2024-10-24T15:47:29Z")
**Posts on this page:** 16
**Page:** 2

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 25, 2024, 9:35pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/21 "2024-10-25T21:35:30Z")

</div>

Thanks for your response. This seems to make sense - I will take a look in more depth tomorrow as it’s late here now.

Certainly just forwarding the arguments (which I think is what you have essentially shown here) would be the most simple solution. Almost trivial, I suppose.

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 8:58am UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/22 "2024-10-26T08:58:58Z")

</div>

> [@CameronBieganek](#):
>
> `ConfigStruct(args...; kwargs...) = DataFrame(args...; kwargs...)`

Just coming back to this this morning. How does this work?

You have defined an outer constructor here, if I understand correctly?

And your outer constructor function is a function `ConfigStruct(args...; kwargs...)` which “maps” to the function `DataFrame(args...; kwargs...)`, meaning that it just calls this function instead.

I may be asking a slightly different question here, but what happens with that (implicit) return value?

The call to `DataFrame(args, kwargs)` returns a `DataFrame`, and presumably that is used to set the value in the struct `df`. But the name `df` has not been used.

What would you have to do instead if the struct was this:

```julia
struct ConfigStruct
    df::DataFrame
    df2::DataFrame
    some_other_stuff::String
end

```

I ask about this more general case, because I think without understanding this it’s difficult to understand the first case.

* * *

To go back to the function you defined, it may be useful to point out that

```julia
ConfigStruct(args...; kwargs...) = DataFrame(args...; kwargs...)

```

is the same as

```julia
function ConfigStruct(args...; kwargs...)
    return DataFrame(args...; kwargs...)
end

```

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 9:45am UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/23 "2024-10-26T09:45:17Z")

</div>

Ah ok - I’m now getting this.

```julia
MethodError: Cannot `convert` an object of type
Vector{Vector{String}} to an object of type
DataFrames.DataFrame

```

Is that what you would expect?

My code is exactly the same as the form you suggest.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 26, 2024, 12:16pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/24 "2024-10-26T12:16:24Z")

</div>

> [@anon91151494](#):
>
> To go back to the function you defined, I would _guess_ that

You guess correctly, but it’s better not to guess at all. Julia’s Manual covers [function syntax](https://docs.julialang.org/en/v1/manual/functions/). Many of your follow-up questions here would be resolved by studying [the type system](https://docs.julialang.org/en/v1/manual/types/) and [its role in method signatures](https://docs.julialang.org/en/v1/manual/methods/) as well. Eyeballing parallels to other languages (“template parameters” are not a Julia concept) and scattered discourse questions are just no substitute for studying the language’s or a library’s broad fundamentals, and that amount of information goes into documentation, not comment threads.

> [@anon91151494](#):
>
> I don’t understand much of what you posted above either.
> 
> You made multiple posts here and didn’t explain anything.

If you didn’t understand what Eben60 wrote, then it’s premature to cast blame on them for not providing an explanation. I certainly saw one about properly using the type system to allow your type constructor to accept your attempted input and other reasonable alternatives. I understand the frustration of not understanding code, but there are more productive ways to learn than to blame your incomprehension entirely on people trying to help you.

> [@CameronBieganek](#):
>
> `ConfigStruct(args...; kwargs...) = DataFrame(args...; kwargs...)`

Might be a typo here? I’d expect the resulting `DataFrame` to also be passed into another likely default `ConfigStruct` constructor, given it’s a type constructor method.

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 1:12pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/25 "2024-10-26T13:12:27Z")

</div>

> [@Benny](#):
>
> Julia’s Manual covers [function syntax](https://docs.julialang.org/en/v1/manual/functions/). Many of your follow-up questions here would be resolved by studying [the type system](https://docs.julialang.org/en/v1/manual/types/) and [its role in method signatures](https://docs.julialang.org/en/v1/manual/methods/) as well.

I have read through these things. As I said before, simply providing a link to the documentation, implying that I didn’t bother to read it, it unhelpful. I would not be asking these questions unless I had already read all of the relevant documentation pages.

I am asking because despite having read those pages I still do not understand exactly what is wrong with my attempt or why.

> [@Benny](#):
>
> I understand the frustration of not understanding code, but there are more productive ways to learn than to blame your incomprehension entirely on people trying to help you.

There’s a bigger problem than that. He wrote in English sentences, but it looks like they were written by ChatGPT - incomprehensible.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 26, 2024, 1:47pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/26 "2024-10-26T13:47:05Z")

</div>

> [@anon91151494](#):
>
> implying that I didn’t bother to read it

Nobody did anything of the sort. In fact, how many times you’ve read the documentation is irrelevant because…

> [@anon91151494](#):
>
> I am asking because despite having read those pages I still do not understand exactly what is wrong with my attempt or why.

Considering the questions you are asking, it is worth reviewing the material with the benefit of better experience. To this day, I learn new things by rereading the documentation, especially when it’s updated by version. Your reaction to people highlighting the relevant sections is clearly skewed by frustration, and venting that frustration on much smaller comments for failing to reword the documentation to your satisfaction won’t help you understand anything better. Reviewing the material might not only clear up some questions, it could help you clarify questions for more targeted topics; trying to fill too many knowledge gaps in one problem is a recipe for frustration.

> [@anon91151494](#):
>
> He wrote in English sentences, but it looks like they were written by ChatGPT - incomprehensible.

Venting like so. I offer a gentle reminder that unproductive insults go against community standards, and it’s not uncommon for such comments to be flagged for moderators. I’ll leave that decision up to the people involved.

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 2:09pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/27 "2024-10-26T14:09:37Z")

</div>

> [@Benny](#):
>
> Considering the questions you are asking, it is worth reviewing the material with the benefit of better experience. To this day, I learn new things by rereading the documentation, especially when it’s updated by version

How many times should I read it? If I told you that I have read these particular pages at least 3 times in the last 4 weeks would you say that’s probably enough times to have read something before asking for further help?

> [@Benny](#):
>
> frustration

> [@Benny](#):
>
> venting that frustration

> [@Benny](#):
>
> Venting like so

I can assure you I am not frustrated. Nor am I _venting_. I don’t know why you have perceived that from what I have written.

I would suggest it is more likely the case that you have anticipated a frustrated response from the other posts in this thread, which speaks volumes.

> [@Benny](#):
>
> I offer a gentle reminder that unproductive insults go against community standards, and it’s not uncommon for such comments to be flagged for moderators. I’ll leave that decision up to the people involved.

Nothing I have said here is insulting. I simply pointed out that I can’t read what he’s written because it’s incomprehensible.

By the way I realized there was a minor error in one of my earlier code examples. (The one with the `struct` with multiple fields.) I’ve now edited it so that it does make sense, but since no one picked up on this I don’t think it makes any difference to the rest of the thread.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 26, 2024, 2:30pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/28 "2024-10-26T14:30:14Z")

</div>

> [@anon91151494](#):
>
> How many times should I read it?

I’ve lost count how many times I read it, and I don’t believe the number is at all important for understanding. The difference comes from rereading with improved experience or a different perspective. If you lost faith in rereading the material, then demanding people communicate the same material to you here won’t make a difference.

> [@anon91151494](#):
>
> I can assure you I am not frustrated. Nor am I _venting_. I don’t know why you have perceived that from what I have written.

Again, the unwarranted blame over your own incomprehension and the unflattering comparisons to generative AI toward people who put time and effort into helping you. You’re entitled to pretend those aren’t insults, but nobody else will. I won’t dispute your claim this is casual behavior for you, but it’s not justified or acceptable here. I hope you recognize this is constructive criticism; your obvious passion for learning Julia shouldn’t be wasted like this.

> [@anon91151494](#):
>
> I should also point out that **it does not even work**.

And yet you didn’t earlier. Perhaps it’s because the only typos are the missing `using DataFrames` and a terminating `)`, and the simplest fixes ran your code example without errors, so you were more interested in understanding how it worked then. Considering you admitted to minor errors of your own, let’s not stoop to nitpicking.

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 2:50pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/29 "2024-10-26T14:50:39Z")

</div>

> [@Benny](#):
>
> then demanding people communicate the same material to you here won’t make a difference.

I did not do this. I asked a separate question which was entirely unrelated to the information in the documentation, FAQs, etc.

> [@Benny](#):
>
> the unwarranted blame over your own incomprehension

Again, where have I done this?

> [@Benny](#):
>
> and the unflattering comparisons to generative AI

> [@Benny](#):
>
> You’re entitled to pretend those aren’t insults

It’s not an insult. It _does_ look suspiciously Chat-GPT like. These days you cannot tell who might just be plugging their forum accounts into a gen AI tool.

> [@Benny](#):
>
> Perhaps it’s because the only typos are the missing `using DataFrames` and a terminating

Lol… This just shows what a low opinion you appear to have of me. You must think I’m _really stupid, or someone who has absolutely no idea what they are doing_.

Look, I get it, you accused me of a bunch of things I didn’t do because you perceived the situation not as it is. You then made the situation worse and doubled-down on your mistake. You’re now trying to _lawyer_ me as if this is a courtroom.

The reality is we just don’t agree.

- You think this is a trivial problem
- I don’t know how to solve it so I asked for help

Maybe I have some fundamental misunderstanding as to how Julia language works. Completely _possible_, but I’m not going to figure that out be _repeatedly reading the same documentation pages over and over again_.

You have to _ask questions_ and _get answers_. Not just _read the docs, stupid person_.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 26, 2024, 3:05pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/30 "2024-10-26T15:05:55Z")

</div>

> [@anon91151494](#):
>
> I asked a separate question which was entirely unrelated to the information in the documentation, FAQs, etc.

This is the question that is entirely related to the information in the linked FAQ and documentation:

> [@anon91151494](#):
>
> I don’t know enough Julia to understand this. Is the `where` necessary? Why did you choose a design which uses a template parameter `T`?

> [@anon91151494](#):
>
> > [@Benny](#):
> >
> > the unwarranted blame over your own incomprehension
> 
> Again, where have I done this?

Right here.

> [@anon91151494](#):
>
> I don’t understand much of what you posted above either.
> 
> You made multiple posts here and didn’t explain anything

People do listen to what you say and take you seriously. It’s why we’re responding to you this way.

> [@anon91151494](#):
>
> You must think I’m _really stupid, or someone who has absolutely no idea what they are doing_.

> [@anon91151494](#):
>
> Not just _read the docs, stupid person_.

It is counterproductive to imagine that people are looking down on you to excuse unwarranted insults, when they in actuality demonstrated a willingness to help. Considering that I am involved this time, I’ll flag this comment and overall thread for moderators to decide how it should be handled.

---

<div class="post-metadata">

### Author: ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)
#### Post date: [October 26, 2024, 3:19pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/31 "2024-10-26T15:19:58Z")

</div>

> [@anon91151494](#):
>
> And your outer constructor function is a function `ConfigStruct(args...; kwargs...)` which “maps” to the function `DataFrame(args...; kwargs...)`, meaning that it just calls this function instead.
> 
> I may be asking a slightly different question here, but what happens with that (implicit) return value?

Ah, sorry about that. Brain fart. I didn’t actually test that code. It should be this instead:

```julia
using DataFrames

struct ConfigStruct
    df::DataFrame
end

function ConfigStruct(args...; kwargs...)
    ConfigStruct(DataFrame(args...; kwargs...))
end

```

So, in this case I define an outer constructor that passes the arguments to `DataFrame` to create a dataframe, and then wraps the dataframe in a `ConfigStruct` (using the default constructor). And this time I did test it:

```julia-repl
julia> using DataFrames

julia> struct ConfigStruct
           df::DataFrame
       end

julia> function ConfigStruct(args...; kwargs...)
           ConfigStruct(DataFrame(args...; kwargs...))
       end
ConfigStruct

julia> ConfigStruct(a=[1, 2, 3], b=[4, 5, 6])
ConfigStruct(3×2 DataFrame
 Row │ a b     
     │ Int64 Int64 
─────┼──────────────
   1 │ 1 4
   2 │ 2 5
   3 │ 3 6)

```

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 3:20pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/32 "2024-10-26T15:20:49Z")

</div>

> [@Benny](#):
>
> It is counterproductive to imagine that people are looking down on you to excuse unwarranted insults

Most of your comments on this thread were in some way insulting or belittling. This is how _read the docs_ comes across, also.

---

<div class="post-metadata">

### Author: ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)
#### Post date: [October 26, 2024, 3:23pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/33 "2024-10-26T15:23:31Z")

</div>

Thanks for your reply. I appreciate you are trying to be helpful but I’ve asked for a moderator to step in and delete this thread as it’s degraded into noise.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 26, 2024, 3:29pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/34 "2024-10-26T15:29:49Z")

</div>

> [@anon91151494](#):
>
> Most of your comments on this thread were in some way insulting or belittling.

If you really believe so, you are welcome to flag the comments you find offensive and let a moderator handle this. I for one welcome any suggestions on how I communicate.

> [@anon91151494](#):
>
> This is how _read the docs_ comes across, also.

Though I would suggest reconsidering your judgement if you perceive insults in reading suggestions but claim not to see it in this:

> [@anon91151494](#):
>
> He wrote in English sentences, but it looks like they were written by ChatGPT - incomprehensible.

> [@anon91151494](#):
>
> It’s not an insult. It _does_ look suspiciously Chat-GPT like. These days you cannot tell who might just be plugging their forum accounts into a gen AI tool.

I believe there’s nothing else we have to say to each other.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [October 26, 2024, 4:32pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/35 "2024-10-26T16:32:23Z")

</div>

As a moderator I’m locking this thread because it doesn’t bring anything positive to anyone involved.

@anon91151494, the way I see it, everyone who interacted with you in this thread was legitimately trying to help. The fact that their answers may not have been useful _for you_ does not mean that they are bots. I regularly delete full ChatGPT answers from this forum and block their creators, and they look completely different.

As for your feeling of being insulted, people who answer on this forum often make assumptions about the nature of your misunderstanding. This is very useful especially for beginner questions, to quickly zero in on the source of the problem when we’ve seen such problems before. And in such cases, pointing out a specific section of the documentation is often the right answer.  
In your case, it didn’t seem to have worked. Part of the issue might have been that @CameronBieganek’s link was accidentally broken: the section he actually meant to point you towards was [https://docs.julialang.org/en/v1/manual/faq/#Why-doesn’t-it-work-to-declare-foo(bar::Vector{Real})-42-and-then-call-foo([1])?](https://docs.julialang.org/en/v1/manual/faq/#Why-doesn't-it-work-to-declare-foo(bar::Vector%7BReal%7D)-42-and-then-call-foo(%5B1%5D)?). It wasn’t a generic “read the docs, stupid” kind of answer, it was helpful and focused on a precise part of the FAQ.

In fact, I don’t remember seeing the word “stupid” on this forum to refer to a person before today. That should tell you the level of good will and politeness you can expect from other people here. I suggest you keep this in mind for future interactions (which I hope will be many since you’re obviously passionate about the language).

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [October 26, 2024, 4:36pm UTC](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710/36 "2024-10-26T16:36:19Z")

</div>



[Previous page](https://discourse.julialang.org/t/designing-interfaces-for-objects-constructable-from-a-file/121710.md?page=1)
