Posts

Showing posts from February, 2024

A Programmer’s Mindset

  A Programmer’s Mindset Before we finish the chapter, we need to have a word about  programming style . Obviously the point of writing a computer program is to make it do what it’s supposed to do, but the style of the program is also important. Your code should be clear and concise, and also be consistent in the way it follows conventions—from the names you choose for variables to the amount of whitespace you leave between blocks of code. Your code should also be easy to read and include comments that explain what the code does. You should always be looking to improve your code to make it more efficient and easier to follow. This process is called  refactoring , and should be done regularly so that your code stays up to date and doesn’t become stale. An important principle in programming is the rule “Don’t Repeat Yourself”, or  DRY . This means that you should always be looking to avoid repeating lots of code. Following this principle will help make your code more f...

Kotline Program

  fun main () { println ( "Hello, world!!!" ) test () } ​ fun test (){ val name = "Scalor" name = "Arjun" // Val cannot be reassigned print ( name ) } // no output fun main () { println ( "Hello, world!!!" ) test () } ​ fun test (){ var name = "Scalor" name = "Arjun" // var can be redundant or re-assigned print ( name ) } // Output Hello, world!!! Arjun mathematical operator fun main () { println ( "Hello, world!!!" ) test () } ​ fun test (){ var name = 40 var name_1 = 34 println ( name + name_1 ) println ( name - name_1 ) println ( name * name_1 ) println ( name / name_1 ) println ( name % name_1 ) } Hello, world!!! 74 6 1360 1 6