> Now the popular packages tend use include in a way that's fairly 
> harmless--i.e. to allow a lot of different symbols and functions to be 
> exported from a single module, without writing all the code in a single 
> giant file. But given that the good uses of include are pretty restricted, 
> I think we'd be better off if the default tool for doing this kind of thing 
> was more restrictive.

Any thoughts on how a restricted include should work?

I like your goto-include example, nice abuse!

> If you want to use include poorly, you can use it very poorly. This last 
> part is entirely for amusement--it's a total strawman--but it just occurred 
> to me that you can use include to simulate labeled GOTO:
>
> # factorial.jl
> n = parseint(ARGS[1])
> accum = n
> include("helper-a.jl")
>
> # helper-a.jl
> n = n - 1
> if n <= 0
>   print(accum)
> else
>   include("helper-b.jl")
> end
>
> # helper-b.jl
> accum *= n
> include("helper-a.jl")
>
> Now I can run
>
> $ julia factorial.jl 5
> 120
>
> On Sunday, December 28, 2014 4:27:34 AM UTC-5, Stefan Karpinski wrote:
>>
>> I'm not sure where you get the idea that anyone "admires" using include. I 
>> specifically just recommended not using it.
>>
>> On Sun, Dec 28, 2014 at 1:45 AM, Jason Merrill <jwme...@gmail.com 
>> <javascript:>> wrote:
>>
>>> On Saturday, December 27, 2014 5:15:38 PM UTC-5, Stefan Karpinski wrote:
>>>>
>>>> You shouldn't be using include here – the way to do this is to make sure 
>>>> that moduleFile.jl is in your LOAD_PATH and then do `using moduleFile` or 
>>>> `import moduleFile`.
>>>>
>>>
>>> I've complained before that "include" in user code is an anti-pattern, 
>>> and I guess I'm going to complain about it again.
>>>
>>> Are there examples of other languages that people admire where the 
>>> equivalent of "include" is regularly used in user code?
>>>
>>> The main place that I think I've seen people use something like it is 
>>> PHP, and even there, I think "require" is used more frequently in good code.
>>>
>>> Languages I've used where include-like functionality is very rarely used 
>>> include Python (include->execfile), Java, and node-style Javascript 
>>> (include->exec(fs.readFileSync("filename"))).
>>>
>>> I don't think there's much to learn from Matlab here, and Mathematica's 
>>> culture of user created libraries seems weaker than in many other 
>>> environments.
>>>
>>> Do people frequently use source() in R?
>>>
>>
>>

Reply via email to