Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning + Programming + Speed
#1

The link above would lead you to a commentary on why some languages like Ruby or Python are considered slow by seasoned programmers or those that pretty much never used them. Kopylov's opinion seemed to be reasonable and appeared to be based on his experience on those languages plus Java, Javascript and C like languages.

If you start reading the comments previous readers left, you soon realized that people could not stop criticizing him for his general approach to the speed and syntax topics. Most of them would blame him for laying stress on the importance of syntax when its impact is low at the end of the day.

Well, syntax does matter anyway. Code won't run if the syntax (akin to human language grammar) is wrong or is missing something like a parenthesis. Usually languages do deal with this issue... once. I mean, they are expected to find any such issues at the very beginning.

If we were talking about C or C++, I could say that the compiler will immediately complain about it but the binary executable aka the program or app won't. So the compiler becomes your proofreader and by the time you publish your application, it should NOT include such errors at all. (Yet, the compiler has several other tasks to perform as well.)

Just in case you were thinking about Ruby Ruby or Snake Python, they initially relied on reading every single line of code you entered in your files. Yeah, that is the perfect way to make it run SLOWLY. At some point both languages went after either just in time compilation or simply producing bytecode. Java has been employing bytecode for quite some time.

Glossary

Source Code: Your code. Period.
Byte Code: Code read by a Virtual Machine or VM.
Binary Code or Machine Code: Used by OS libraries or even the CPU only. Memory and variable / pointer references do matter here.

The closer the code is to machine code, the lower its level will be.

That's why C and C++ and the like are considered low level languages, they rely on binary code.

Source Code
Can only be handled by people or language interpreters.
Slow.
Compatible with certain languages.
Simple TXT files with proper language file extensions.

Byte Code
Can only be handled by a VM.
Kind of Slow.
Compatible with several processor architectures.
Usually Cross Platform.

Binary Code
Can only be handled by an OS libraries or be directly fed to the processors like CPU's or GPU's.
Fast.
Compatible with specific processor architectures.
Cross Platform only if using very similar OS's, yet, Linux binaries won't run natively on Windows and vice versa.

The only fastest language I could think off would be Assembler that produces machine code, a set of millions of simplistic processor instructions.
Guess why people later preferred to develop languages like C and later C++ and many others. Winking

Thinking Does it mean that languages are stuck right there?
Happy with a sweat Not necessarily. Ruby and Snake have been improving their speed and overall performance as much as possible in the last decade. Of course, it would be hard to convince anybody that they will become as fast as C++ one day. Laughing 

Confused What did make a difference there?
Thinking Well, on one hand I could say they made several changes like redefining the way they collect garbage or zombie objects lurking around. On the other hand, they have improved memory allocation and reallocation. Besides they could have reduced the number of basic checks in their low level implementations (in C to be specific). At least Ruby has changed their interpreter from basic MRI to other implementations like YARV or added JIT or MJIT. They also cared about memoization. IIRC, memoizing some method call improves the speed by keeping a quick access register of where they are located and what arguments are being passed to them. Sometimes it's been a great addition to Ruby while Rails might have not enjoyed its benefits at all.

Confused What about syntax? Does it matter then?
Happy with a sweat Of course it does! Yet, the less you care about it, the slower the language might become.
In languages like C and C++ you gotta specify a lot of details like return value of a function, argument types, variable types, the specific moment a given variable should be declared or is it local or global?
C might not allow certain type coercions while C++ might allow you to do that if you provide it with some basic information on that value at some point. C++ has several default coercions included. It can even convert pointers into specific types.
Ruby Ruby won't allow you to coerce a number of any kind into a string. You need to call to_s method or define a string interpolation and then call sprintf to modify it.

Since none of the languages exposed here read actual source code anymore, the interpreter or executable does not focus on syntax at all (after it has finished loading your code).

Even so that does not mean other Bug errors common in low level languages won't show up like dumping cores or segfaults (segmentation faults).

You could say you might have encountered some Thief illegal or irresponsible calls that look for non existing information or temporary data that has been erased from memory or you were looking for data that does not belong to the memory space you had previously reserved via stuff like malloc or your language memory manager or your current thread. Or you didn't tell it to Cure-Chan keep it alive long enough to let you work with it. Laughing

Usually you could prevent that from ever happening if you take care of its error handling, i.e. don't let them set a value above 255 or no negative value should be allowed or don't ever let them divide anything by zero! Serious 

Now talking about the maker's way of living, don't nest several loops in a row if possible.
Actually, you could not avoid Indifferent it if you are planning to display some tileset on screen using engines like Gosu or Roole, but if you only need to check a certain method or value stored in a variable found in some list or Array, you better look for an alternative way to fetch it without more than a single (for each) loop. Winking

As a final word on this, I gotta say that glue code or spaghetti code won't help you here. The cleaner and more simple your code is, the better it should perform... usually. Happy with a sweat 

Thinking There could still be many other issues that could show up later on, but that's something that would deserve starting a new thread or posting a new reply some other day. Tongue sticking out

Disclaimer

I'm not saying here that I know everything about programming nor that I've covered every single aspect of it. You still can contribute to this thread by leaving your comments here if deemed necessary.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Learning Ruby is fun! amp 2 4,359 07-07-2010, 09:27 AM
Last Post: jubhub731



Users browsing this thread: