This is how most Julia code looks like. The methods are the interface and 
thus which is exposed in public.
It is pretty natural to program this way when doing generic programming and 
taking multiple dispatch into account.

I agree that this could be better documented somewhere but the solution is 
not to bring more complexity into the language. This has also been 
discussed several times on the mailing list, so I would be very surprised 
that introducing warnings for field access would gain any acceptance among 
the core Julia developers.


Am Dienstag, 7. Juli 2015 10:54:05 UTC+2 schrieb Pontus Stenetorp:
>
> On 7 July 2015 at 04:12, Ismael VC <ismael...@gmail.com <javascript:>> 
> wrote: 
> > 
> > Couldn't we just get a warning and let people shoot themselves in their 
> foot 
> > if that's what they want? 
> > 
> > Something like: 
> > 
> > Warning: Using private method/type in module Foo at foo.jl:n. 
>
> I like that you are trying to find some middle ground.  But if I am 
> doing this intentionally the warning will be a constant annoyance, so, 
> how should I silence it?  Yet another command line option so that we 
> approach gcc/clang with different levels of warnings?  Yuck... 
> Annotations (@silence?) like Java?  Double yuck... 
>
> Giving users this level of power is something that I am happy with. 
> Last week it allowed me to add temporarily add a function looking deep 
> into a composite type from a library when debugging.  Sure, it can be 
> abused, but it can equally well be used properly when necessary. 
> Sure, it may break, but ultimately it is always up to the caller not 
> to violate the API.  Sure, sometimes base violates this idiom, but 
> this is most likely due to historic reasons and a lack of a consensus 
> more than anything else. 
>
> In the future, given enough experience and evidence to the contrary, I 
> would be happy to reconsider my position.  But for now, using idioms 
> like the one below, is how I write my Julia code. 
>
>     export Weights, W, b, fanin, fanout 
>
>     immutable Weights{T<:FloatingPoint} 
>         W::Matrix{T} 
>         b::Vector{T} 
>     end 
>     Weights(fanin, fanout) = Weights(rand(fanout, fanin)./1024, 
> zeros(fanout)) 
>     W(w) = w.w 
>     b(w) = w.b 
>     fanin(w) = size(W(w), 2) 
>     fanout(w) = size(W(w), 1) 
>
> Apologies for the terribly short variable names, it is an example after 
> all. 
>
>     Pontus 
>

Reply via email to