How to get out of easy syntax like programming? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

How to get out of easy syntax like programming?

So how to get used to not-too-abstracted languages? For example Place where I learn programming, I learned Python (3), and it wasn't hard for me. But now we have to make programs in Go(lang). And I have trouble specifying and remembering types, like in Go, there is not type of just array with random types like in python lists', you need to specify type of arrays all contents, and it's frustrating me to remember. (From what I know it's usual in other languages too.)

10th Jan 2019, 11:38 PM
Diamond Troller
Diamond Troller - avatar
7 ответов
+ 1
It can be hard learning​ a language with different syntax. You do get used to it. For the most part you just have to know if you want the type to be an int, a float or a string (or maybe Boolean). There are signed and unsigned integers​, numbers can be different sizes, but these usually don't matter much for code you write when you start using a language. Having static types can help you to think about how your algorithm is working. It can also help catch some types​ of bugs. John Wells Mentioned Kotlin can infer types for you. Go can also do this when you initialize the variable when declaring it. Diamond Troller and HonFu can you give an example of when an array or list of different types​ is useful? If you really need it you can make a sudo dynamic type and use how you want.
11th Jan 2019, 9:51 AM
Jared Bird
Jared Bird - avatar
+ 5
Jared Bird it was for this assignment: https://www.sololearn.com/learn/9298 My response: https://code.sololearn.com/c0hYHFyjFQru 843 lines likely half comments Out of the hundred plus languages I've coded in, Kotlin has kicked C++ out of the #1 most loved spot it held for 33 years.
12th Jan 2019, 10:26 AM
John Wells
John Wells - avatar
+ 4
I've got a Kotlin code using Any (class that can be Int, Double, String, or any other data type.) It is a code to parse a made up language and interpret it. All of my variables in that language were instances of Any. I'd have to see the actual type to decide what operation to perform for the '+' operator. Two integers stayed as an integer. A double and integer converted the integer to double. A string and integer/double converted the number to a string and concatenated the strings.
11th Jan 2019, 10:07 AM
John Wells
John Wells - avatar
+ 3
Most languages require explict typing of variables. The reason being they allocate the storage needed to hold the data up front before the data is seen. Python allocates the storage after the data is seen, but this makes the program significantly slower because each usage must first figure out what the data is before it can get used. It will definitely take some getting use to. However, you can use languages like Kotlin that can infer the type based on the usage to lessen some of the pain. Every variable has a type, but you seldom need to state it.
11th Jan 2019, 2:30 AM
John Wells
John Wells - avatar
+ 2
I also have that problem: Having proceeded from Python to the Cs, suddenly I have to make do without lists and slicing; as a compensation there's all that datatype business. How to deal with it? Well, in a pragmatic sense you just have to relearn how to write algorithms without the convenience you're used to. And that takes time and practice. Basically: Get used to it by using it.
11th Jan 2019, 9:03 AM
HonFu
HonFu - avatar
+ 2
Jared Bird, for example I made a vocabulary trainer. I stored the vocabulary in a list, but each vocabulary item was itself a list, consisting of two strings, two ints that control when the word will be presented again and a list that contains progress information. Then I started C++ and wondered: How would you even do that? Of course there are answers: You can design a datatype for it or a struct and put them in a vector... But it's different and you have to get used to it. With Python's lists you basically don't have to think: Just cram everything in there. ;-)
11th Jan 2019, 10:04 AM
HonFu
HonFu - avatar
+ 1
John Wells I'm not surprised that you've made something like that. May I ask how complex is the made up language? How big is the source code? Also how are you liking using Kotlin at the moment?
12th Jan 2019, 6:32 AM
Jared Bird
Jared Bird - avatar