, I also had hate on oop. Although used alot, I personally felt very un-understandable. I used to use classes instead of functions without much knowing , Just to show recuiter.
But i am afraid how would it be used in giant software development and ml things.
I am probably thinking, Julia may have initialized a new form of OOP idea which is powerful than OOP. . thinkjulia helped me alot and i have came to functions and will about to finish basis of it Also,
I think that explaining that in any meaningful way (how it is different, really, for the purposes of the programmer who aims to write performant, idiomatic Julia code) just amounts to at least 70% of the manual.
Also, a reasonable reader should just assume that any two programming languages are fundamentally different (unless stated otherwise, eg because one was derived from another). I am not sure the manual should belabor this point.
Yes. This is what I am suggesting. My point is that there isn’t any shortcut around this, and assuming that one can skip the manual is a common mistake.
I think I have a slightly different take on the original question. It is based on a false premise in my opinion. I do not think that anybody telling you “things you should be aware of” is going to help you learn to code in Julia (or any language). Beyond superficial differences in syntax, you will likely forget/not internalize most of what you are told until you see it for yourself. Repetition is key. You should not just read the Docs. You should code with the Docs always open. Code. Docs. Code Docs. Then you will know. This is the way of the Julian.
and Discourse. Because this forum is really great. I cannot express enough my gratitude to everyone that helped me along this year.
I’ve got valuable resources by real Julian developers,
from here instead of following or searching online through difference that people wrote (from outdated version). I was also able to get resources, that are beneficial to me.
Got a very interesting ideas , ways, links. I am sure, other beginners if found hard will be able to found some good materials from these discussion.
But although,Your answer made solution, which is good in another sense.
I should be now doing some real world project to get grasp instead of doing basis things as previous developer.
My question was also trying to tell that instead of reading whole material and got some reading materials that I am just (maybe) able learn julia basis in few days. :
Thank you .
This is the way.
2.0f
is equivalent to 2.0 * f
in Julia
Well…
julia> supertype(Bool)
Integer
Bool
is a type of Integer
(i.e., the abstract type) in Julia.
But I understand your annoyance. If you see numbers without decimal places it is easy to assume Int
and not to think of Bool
.
It’s also the inconsistency compared to singular values:
julia> x = true
true
julia> typeof(x)
Bool
julia> x
true
julia> x = Bool[true, false]
2-element Array{Bool,1}:
1
0
julia> x[1]
true
FWIW, I consider this a feature rather than an inconsistency.
Feature in what way? What’s the advantage?
julia> X = rand(["true", "false"],10,10)
10×10 Array{String,2}:
"false" "true" "false" "false" "true" "false" "false" "true" "true" "true"
"false" "false" "false" "false" "false" "true" "true" "false" "false" "true"
"false" "false" "false" "true" "false" "false" "false" "false" "false" "true"
"true" "true" "false" "false" "true" "false" "true" "true" "false" "false"
"false" "true" "false" "false" "false" "true" "true" "false" "false" "true"
"false" "false" "false" "false" "true" "false" "false" "false" "false" "false"
"true" "false" "false" "false" "false" "true" "false" "true" "true" "false"
"false" "true" "false" "false" "false" "true" "false" "true" "true" "false"
"false" "false" "true" "false" "true" "true" "true" "true" "true" "false"
"true" "true" "false" "false" "false" "true" "true" "true" "true" "false"
julia> map(x->x=="true", X)
10×10 Array{Bool,2}:
0 1 0 0 1 0 0 1 1 1
0 0 0 0 0 1 1 0 0 1
0 0 0 1 0 0 0 0 0 1
1 1 0 0 1 0 1 1 0 0
0 1 0 0 0 1 1 0 0 1
0 0 0 0 1 0 0 0 0 0
1 0 0 0 0 1 0 1 1 0
0 1 0 0 0 1 0 1 1 0
0 0 1 0 1 1 1 1 1 0
1 1 0 0 0 1 1 1 1 0
I consider the latter to be much easier to parse. Also, the identification of true
and 1
is not an invention by Julia. It is very much common in a theoretical computer science context.
Note that switching representations to improve readability is great and also utilised in many other contexts as well. In Julia 1.6 for example, you will see that the style of printing a sparse matrix depends on its size:
That’s just how they are printed in a compact form.
It’s possible that this compact printing should be turned off for vectors? E.g.:
julia> rand(ComplexF64, 2, 4) # Compact printing
2×4 Matrix{ComplexF64}:
0.471554+0.731366im 0.832658+0.694934im 0.21162+0.420378im 0.558943+0.646677im
0.904187+0.33054im 0.545873+0.438978im 0.712625+0.785231im 0.281017+0.428674im
julia> rand(ComplexF64, 2) # Less compact
2-element Vector{ComplexF64}:
0.28745077927138274 + 0.9626892790343715im
0.7954924735065929 + 0.5122839212553927im
julia> rand(Bool, 2, 10) # Great this is compact
2×10 Matrix{Bool}:
0 1 0 1 1 0 0 0 1 1
1 1 0 1 1 1 1 0 0 1
julia> rand(Bool, 2) # Here there is space to be more verbose?
2-element Vector{Bool}:
1
1
The fact that Bool <: Integer
leads to a bigger problem that you have to be very careful when implementing indexing and it gets done inconsistently even in Julia Base:
julia> (1,2,3)[true]
1
julia> [1,2,3][true]
ERROR: ArgumentError: invalid index: true of type Bool
julia> (a=1,b=2,c=3)[true]
ERROR: MethodError: no method matching getindex(::NamedTuple{(:a, :b, :c),Tuple{Int64,Int64,Int64}}, ::Bool)
julia> (1:3)[true]
1
julia> 1[true]
1
That’s a good point and should be considered (might have been?). Personally, I still prefer the 1,0
representation for (long) vectors, though.
Good list. While I know different programming languages, I initially started using Julia as I program in Python, and I find the majority of them. In particular, I spend months without realising that many of my functions returned values even when I did not use return, it was very confusing for me .
In my opinion about the comments in this thread, Julia conceptually is not a complex language. The performance searched implies to be more knowledge about types, it is normal. However, in comparison C++ is a lot more complex (I teach it, and it has many details). My daily small programs in Julia are not more complex than Python (and sometimes is more elegant, using broadcast). About the functional approeach considering the OO in Python is not too strange in my opinion (anyway, in methods the self parameter appear always as the first one), it is a small change, in my opinion.
One mistake I often did is to assign an array a
to a new variable b
and modify b
:
a = [1, 2]
b = a
b[1] = 9
This modifies a
as well. One has to use copy: b = copy(a)
. I have a long experience with R and there’s no such a trap in R.
@bkamins, very puzzling, why does this happen? I.e., why true
is not interpreted as an integer in some cases? If we write Int(true)
(or Int(boolean) more generally) this should get us off the hook.