Why is Python so Slow?

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 1,2 тыс.

  • @TechWithTim
    @TechWithTim  5 лет назад +511

    Hey guys just wanted to make clear that I believe I may have made some mistakes in the video! Some people that are clearly more educated on this specific topic and have left some polite comments to clear up any confusion. I'd like to apologize if I've misinformed anyone. I believe a majority of what I've said is correct but there may be have been a *more* correct answer to the question. It seems like the dynamic typing is an issue regarding speed but the more influential issue comes from the lack of a JIT compiler by default.

    • @hedleypanama
      @hedleypanama 5 лет назад +2

      Golang is quite fast and it can be dinamically typed too using the assignment operator :=.
      Golang can be both interpreted or compiled!

    • @noelgomile3675
      @noelgomile3675 5 лет назад +27

      @@hedleypanama The := assignment operator does not mean you are using dynamic typing, it means that you are letting Golang infer the type of the variable based on the data type that is on the right hand side of the operator. The variables will still not be allowed to have their data types changed however unless explicitly converted to a different data type. And Golang is a compiled language it is not both interpreted or compiled.

    • @mario123abc
      @mario123abc 5 лет назад +2

      Tech With Tim Great video. One correction Java is not low level progamming. en.m.wikipedia.org/wiki/Low-level_programming_language

    • @kudoamv
      @kudoamv 4 года назад +4

      That mad guy in the corner in the of the room bashing keyboard laughs crazily as he types C and other assembly languages.
      .
      (cuz he a hacker x)

    • @bitbudsupport9925
      @bitbudsupport9925 4 года назад +4

      If I compile a python program and turn it to an exe.....will it run faster?

  • @BeachBoi1000
    @BeachBoi1000 4 года назад +1829

    Python in real life is slow also. Compared with other snakes.

  • @RamkrishanYT
    @RamkrishanYT 5 лет назад +1692

    The problem is that a scripting language has become so popular that we're holding it upto the expectations of compiled languages

    • @platcrab4890
      @platcrab4890 5 лет назад +32

      I mean is there much of a difference between a compiled language and a shell language? Python is still eventually run in assembly just like C or Java

    • @TricksterRad
      @TricksterRad 5 лет назад +218

      @@platcrab4890 There's a difference between running interpreted bytecode (Python, Java, etc.) and actual machine code (C/C++). Also, please, do not confuse Machine Code (the thing your CPU runs) and Assembly (the thing you used to write programs in)
      Edit: Also, Java certainly does *not* compile into machine code.

    • @pencilcase8068
      @pencilcase8068 5 лет назад +5

      The Zucc has spoken

    • @MJFAN666
      @MJFAN666 5 лет назад +3

      @@TricksterRad how does Java run if not turned into assembly?

    • @TricksterRad
      @TricksterRad 5 лет назад +106

      @@MJFAN666 Java gets turned into JVM bytecode. When you run a Java app, JVM executes that bytecode.
      If java were compiled into machine code, you wouldn't have to install JRE on every computer where you want to run java programs.

  • @prasangsinghal262
    @prasangsinghal262 5 лет назад +2920

    Python was not made to be fast...but to make developers fast...

    • @TechWithTim
      @TechWithTim  5 лет назад +293

      Ik!

    • @Lioneltunisianorevo
      @Lioneltunisianorevo 5 лет назад +137

      Give that man a cookie 🍪

    • @zyrohnmng
      @zyrohnmng 5 лет назад +16

      @@Lioneltunisianorevo But let that man know if you're in Europe!

    • @Lioneltunisianorevo
      @Lioneltunisianorevo 5 лет назад +1

      @@zyrohnmng Tunisia :p but why ?

    • @RmDIrSudoSu
      @RmDIrSudoSu 5 лет назад +69

      As is java.. Java is easier to program and faster to program, but far slower to run than C/C++.. It's the same for C# it's faster to code, but slower at runtime. That's why C++ is still a thing in 2019, because no other programming language can be as optimize as C/C++ (except the languages that also compile directly in assembly). But C/C++ is slower to code, way slower to code.. You need deep knowleadge of how your computer and language works to make it efficient at runtime. That's why Java and C# are everywhere and C++ is only used for application that required a lot of optimisation.

  • @JohnDavidDunlap
    @JohnDavidDunlap 3 года назад +136

    The benefits of static typing are not limited to execution speed. It also results in a code base which is considerably easier to refactor years down the line.

    • @Jarrod_C
      @Jarrod_C 3 года назад +1

      how does it make it easier to refactor?

    • @JohnDavidDunlap
      @JohnDavidDunlap 3 года назад +8

      @@Jarrod_C Because there's more meta data embedded into the source code.

    • @rantalbott6963
      @rantalbott6963 3 года назад +11

      It also catches lots of mistakes that can be a bitch to find, like a spelling error in a variable name that creates a new variable at run time instead of an error message at compile time.
      It's "horses for courses": use something like Perl or Python for things that run interactively and don't hurt anyone if they fail, but a strict language for programming when failure is not an option.

    • @skaruts
      @skaruts 3 года назад +1

      This hasn't been my experience. Static typing always seems to involve a lot more thinking to refactor, plus a lot more writing.

    • @skaruts
      @skaruts 3 года назад

      @@rantalbott6963 that depends on the language design. But then, unless you're using notepad to write code, you're not gonna have many issues with mistyping variables. I've never had any difficult issues from it either way. That will result in some null variable error a few lines down, which will be enough to tell what's wrong pretty easily. (My experience is mostly with Lua, though, I haven't used that much python in the last 4-5 years.)
      However, Python does carry some stupid Murphy's Law traps. For example: *x = 10* always defaults to a local *new variable,* and since it's so easy to forget to preface a function with *global x,* you can (and will) find yourself wasting hours on a weird problem caused by that. In Lua this is never a problem; as long as you know to avoid using globals, you're always in direct control of scope.

  • @jt95124
    @jt95124 5 лет назад +159

    I graduated with a comp sci degree in 1974. I have programmed in assembler (several different), fortran, basic, C, mumps, cobol, pl/1, apl, lisp, java, C++, javascript, can't even remember them all. I met Donald Knuth and discussed structured programming with him. I was onto OO after reading the issue of Byte magazine that introduced smalltalk to the masses. I met Charles Moore, inventor of Forth, and worked with Jules of Jovial fame (well, maybe not fame). I supported the C++ run time library, cfront, and know LEX/YACC and how the internals of compilers and run times work.
    For write only programs, python and similar are quick. If you are writing a corporate product with many parts and many people and care about performance, pleae give me static data typing. C++ and stl give you much of the goodness of python lists. I claim I can program in C++ or java almost as fast as python.
    The speed of coding in python is due to the many magical diddles in the language, but that is a two edged sword. I say C++/Java is a little more verbose, but typing speed is not really an issue, and the quick writing is an inevitable tradeoff with clarity, at least to those who are not doing 10 hours a day with python. I would rather see spelled out code than a list comprehension, for instance.
    Also, Java and C++ are pretty much what they started out as. Python is continually changing, multiple versions are very different, meaning learning and update time. Makes docs a nightmare of info about how it used to be and how it is now. Much worse than C++ and Java,
    Also also, I have been using Kivy, and both kivy and python have documentation that was done quickly and often needs 2 or 3 times as many words, way too terse, seems like it never really does a top down discussion of things. Corporate libraries and languages I used had complete and relatively static documentation in known places. Python is all over the place.
    There are tradeoffs, like clarity for brevity. As a silicon valley software architect, for quality, dependability, and clarity you have to pay a price, and I don't want to fly in an airplane whose software has dynamic typing. I know there are those who can read (and code in corporate settings gets read way more than written) python quickly, but for many, slower and less reliably correct.
    If you are writing throwaway code, amusing yourself, or ???, okay python. For large projects with many modules, versions, programmers, maintainers, performance demands, etc, I would definitely choose C++ or Java.
    Lastly, if you are writing software you expect to maintain and enhance over many years, at some point, you are going to have giant headaches over versions, do you stay with the 10 year old version, or massive convert? No good answer.

    • @sumodmadhavan
      @sumodmadhavan 5 лет назад +1

      jt95124 What is your observation about ADA. Is it still active? Will you choose ADA over C++/C why? Why didn’t ADA fly?

    • @jt95124
      @jt95124 5 лет назад +4

      @@sumodmadhavan ada was trying to be c++ but with async multithreading built in. It was developed and pushed by Dept of defense as solution to their issues. C++ does the same thing and grew from the C culture, so had community and momentum.

    • @jt95124
      @jt95124 5 лет назад +3

      @@sumodmadhavan languages succeed by large community, Adam has none, so no open source, no tools, no programmers

    • @Calvin_M.
      @Calvin_M. 5 лет назад

      I'm studying C++ and Python languages right now in my univeristy, which language would you recommend me to develop also and should I?

    • @masheroz
      @masheroz 5 лет назад +1

      What about Fortran?

  • @harshitgupta6856
    @harshitgupta6856 5 лет назад +361

    REEEE
    Kinda wish you mentioned numpy for when you were referring to just raw speed for computing math. Numpy is much much more optimized than the base interpreter and is usually the answer to this type of issue.
    Numpy is the reason why Python can be used for so many data analytics and machine learning applications.

    • @jwhite1202
      @jwhite1202 5 лет назад +35

      Harshit Gupta Agreed. Machine Learning is definitely Pythons sweet spot. I love Java, but none of Java’s data structures comes close to pandas and data frames. Those alone makes stats and ML doable without a Ph.D.

    • @ShadowaOsu
      @ShadowaOsu 5 лет назад +61

      Numpy is fast, I wonder what's the reason behind it omegalul.
      Could it be, because, *ehem*, heavy parts of it are coded in coded in C?

    • @maxclifford937
      @maxclifford937 5 лет назад +44

      @@ShadowaOsu also the most the machine learning bits in python are just wrappers around c/c++ code

    • @ShadowaOsu
      @ShadowaOsu 5 лет назад +1

      @@maxclifford937 yea exactly

    • @mennoltvanalten7260
      @mennoltvanalten7260 5 лет назад +28

      > Could it be, because, *ehem*, heavy parts of it are coded in coded in C?
      Yes, and so it would have been a great example as an extension someone has already written.

  • @chesshooligan1282
    @chesshooligan1282 4 года назад +61

    "I'm learning as well."
    Everybody likes a modest person.

  • @DrumRoody
    @DrumRoody 5 лет назад +478

    I've casually tried to learn coding many times, python has been the only language I have understood. Seems like a good place to start

    • @ajricherson1099
      @ajricherson1099 5 лет назад +4

      Can I ask which languages you tried to learn?

    • @DrumRoody
      @DrumRoody 5 лет назад +20

      @@ajricherson1099 brainfuck. Joke. It was C or one of its variants

    • @ajricherson1099
      @ajricherson1099 5 лет назад +66

      @@DrumRoody You are really comparing two ends of the spectrum then. C is pretty low level language, and Python is one of the higher level programming languages. Just something to think about.
      If you do want to learn another language, I would recommend something like Java, C#, or perhaps JS if youre interested in web dev

    • @lincolnsand5127
      @lincolnsand5127 5 лет назад +25

      @@DrumRoody I use C, C++, & Rust. I definitely find them much more expressive & powerful than python. Also. Brainfuck can be used as a test output for compilers. Brainfuck is essentially simplified assembly language.

    • @incognitojon902
      @incognitojon902 4 года назад +14

      Lincoln Sand this has to be a joke brainfuck was created to fuck ur brain it’s not useful for anything

  • @finnepower
    @finnepower 4 года назад +2

    Static types takes much longer developing? Jesus what a blanket statement. Last time I checked, me writing "int" or "double" was not the major challenge in my coding. If you're doing anything significant you're spending most of your time just thinking.

  • @NovemberOrWhatever
    @NovemberOrWhatever 5 лет назад +24

    in my experience multiprocessing is simple enough if you set it up as here's your data, here's your code, come back to me when you're done. Setting it up that way is a lot easier for compute applications though

  • @brusch1553
    @brusch1553 3 года назад +72

    Speed is a key factor to me.
    That's why I chose Assembly.

    • @zodiaq7186
      @zodiaq7186 3 года назад +1

      what?

    • @78anurag
      @78anurag 3 года назад +3

      Tf

    • @gavinthecrafter
      @gavinthecrafter 3 года назад +14

      I'm assuming you're joking, but unless you're trying to run your program on a computer from 1989, you probably don't need to go _that_ low level. C and C++ should be plenty fast enough.

    • @brusch1553
      @brusch1553 3 года назад +6

      @@gavinthecrafter your assumption was right

    • @theseusRJ7
      @theseusRJ7 3 года назад +3

      Hats off

  • @Stl71
    @Stl71 2 года назад +19

    I mostly write in java, but python is spread everywhere. Learning python, makes you able to make webpages and apps, able to perform data science and machine learning, able to make a stand alone app for desktop. I think it is worth learning python.

  • @spkim0921
    @spkim0921 2 года назад +14

    Absolutely agree, every variable in python is by default an Object Class; in Java you can define variables to be primitive values, which helps it skip python's verification of datatype at runtime. Multithreading is also difficult in python while you can instruct Java to do it specifically when needed; my favourite language is still python for its simplicity and much friendlier user input structure in coding, so usually what I do is write up the code in python to run it, and if I need to reduce runtime for my software, I try to rewrite it in Java and hopefully achieve the same if not similar results.

  • @G33KN3rd
    @G33KN3rd 5 лет назад +10

    It's not just the case that Python uses dynamic typing but because its interpreter uses a stack-based virtual machine to execute python code instead of a register-based virtual machine like Lua uses and Lua is a very quick little scripting language.

  • @cx3268
    @cx3268 5 лет назад +432

    Interpreted VS compiled

    • @TechWithTim
      @TechWithTim  5 лет назад +65

      Python is still compiled! Just differently than other languages.

    • @tobychadderton4209
      @tobychadderton4209 5 лет назад +7

      @@TechWithTim only when you use bytecode right?
      Python is interpreted when you run a .py script

    • @TechWithTim
      @TechWithTim  5 лет назад +38

      it’s compiled to .pyc then *interpreted as byte code.

    • @TricksterRad
      @TricksterRad 5 лет назад +5

      @@tobychadderton4209 Python is compiled before running into __pycache__ directories.

    • @AsirIset
      @AsirIset 5 лет назад +4

      But isn't Java interpreted as well?

  • @arjanbal3972
    @arjanbal3972 4 года назад +44

    Technically speaking, a python program would be slower than a similar c/c++ program by a constant factor, say 100X, not exponentially. Exponentials blow up really quickly

    • @rinrin4711
      @rinrin4711 4 года назад +21

      Actually, no. There cannot exist a functionally-desribed correlation between Python and C speed. Even if you write 100 pairs of absolutely semantically identical pieces of code in Python and C that cover different aspects of programming and measure the execution speed difference for each pair. You will not be able to drive any meaningfull corellation between those two languages outside of Python being generally much slower. Why? For many reasons. One of them is compiler optimisations for C. For example, if you write a simple cycle that adds 5 to variable y 1000 times, in C this code will be compiled to just "y = y + 5000", while Python will execute all 1000 loop iterations effectively executing at least 1000 slower, but if there were only 10 loop iterations then the code would be only 10 times slower. However these 1000 times and 10 time are also not representative, since integers are absolutely different things in those languages and different operations might(will) have different speed ratios.
      There are many other reasons, but I think you got an idea)

    • @CallousCoder
      @CallousCoder 2 года назад

      Actually in same cases it can be far more than exponentially faster than Python.
      Python has no contextually knowledge of types and therefore of optimization.
      I have optimized a piece of Python code to run 100+ times faster by changing I % 2== 0 into I & 1 == 1 and changing division of multiples of two by shifting right!
      These are far more than exponentially faster situations, because a division on an x64 takes 45-93 cycles a shift and bit wise operation 1 cycle!
      Changing the run speed of that back batch processor from running 6-7 minutes to 33 seconds. In total since these operations were the crippling factor.
      A compiler does these sorts of optimizations for you because it has context. And when I tell a compiler to optimize for speed, it can (and will) un roll loops avoiding many of 100s or even 1000s compare and branch statements. Having a million of the instruction instructions in a row compared to 1 or those and a million compared and branch shorts saved at least 8 cycles per time so 8.000.000 cycles.
      But of course every problem is unique so it would not scale quadratically on all factors but most often a C/C++ at least teams 4 to 100 times as fast! And I some cases but 1000s of times.
      This is why I advocate that every programmer at least have 1 semester of experience in assembly. Because then you know to avoid those deadly pitfalls.

  • @aakarshan4644
    @aakarshan4644 4 года назад +29

    bro if you can make a video on writing C extensions for python, that would be really helpful. Great vid btw, also what are your thoughts regarding Go ?

  • @CyberQuickYT
    @CyberQuickYT 4 года назад +29

    thumbnail is misleading, Java isn't 3rd fastest language by any means.
    There are faster/more efficient languages, usually those which get compiled into native code, not into vm code.

    • @atomfusion231
      @atomfusion231 4 года назад +10

      It’s also misinformative as well. Python is an interpreter while C,C++ and java are all compilers, which provides a massive difference in performance. It’s why I dislike these comparison videos, as it’s comparing different types of how a language is run on something like speed. Compilers are usually faster than interpreters.

    • @programmer4047
      @programmer4047 4 года назад +3

      Even C isnt the fastest language, assembly and few other languages are much faster than C

    • @embeddedbastler6406
      @embeddedbastler6406 4 года назад +8

      @@atomfusion231 Java compiles to bytecode, not to machine code. This means at runtime there is still a interpretation.

    • @embeddedbastler6406
      @embeddedbastler6406 4 года назад +7

      @@programmer4047 Since both Assembly and C do compile to machine code, you can't simply say one language is faster than the other. It depends on optimization and the quality of the code.

    • @CyberQuickYT
      @CyberQuickYT 4 года назад +2

      @@programmer4047 I have to disagree with you. C compilers are very optimized, so the generated machine code is often more efficient than if you would write assembly by hand.

  • @robbprof111
    @robbprof111 4 года назад +20

    Good video, Tim! As others have pointed out, nits can be picked over some wording choices, but I like the spirit of what you intended to do here. I have used many computer languages over the years: Basic (several flavors), Fortran, C, C++, Java, Assembly (Intel & Motorola), DOS, BASH, VMS, REXX, Matlab, RT-Works, ObjecTime, Avenue, and now Python. I am not a programming expert, or even a professional programmer, but my coding experience is fairly broad. The design goals of Python's creators focused on issues other than speed. They were more interested in usability and efficiency, as well as some very deep computer science crap ... I mean operability. For anyone who thinks Python was intended to be user-friendly, just try reading the official docs. However, the flexibility and robustness of this language are impressive. Still, it gives you plenty of rope to hang yourself; you can easily write poor code if you lack sufficient skill or discipline. That said, I think Python is a good first language for those who are willing to explore what it offers. It gives you plenty of tools to write good code, and perhaps more important, to develop good programming habits. A language like Visual Basic may be easier to learn, but the skills you can develop are limited, and you are likely to pick up some ugly habits. For more advanced programmers, Python offers a dynamic coding environment that allows you to achieve goals that are difficult to match in other languages. If you are willing to dig deep, you can write intentionally ugly code that will bypass typical limitations found elsewhere. You should not expect Python to perform well on code segments that involve serious number crunching or manual loop structures. But, there are advanced mechanisms available (in the base language) to help improve speed, such as ranges, iterators, maps, comprehensions, closures, etc. Like the 'sorted' built-in function, these code patterns leverage pre-optimized execution, behind the scenes. Without regard to the language/compiler used to build a particular Python implementation, these mechanisms represent a large manpower investment by dedicated people! If you learn how to use them well, they will help you write faster code. And, I think writing C (or Fortran) extensions is quite viable for extreme number crunching. If you like Java, use Jython in place of C-Python, and write Java extensions, instead. Just remember that powerful Python libraries, such as NumPy, are available, as well. If you need to take Fourier Transforms, for example, you might find that NumPy is faster than using a Java routine that you found on the Web -- it depends on array length, precision, etc. Ultimately, I agree with others that no one language will serve all your programming needs.

    • @StrangeIndeed
      @StrangeIndeed 4 года назад +1

      top notch comment c:

    • @uguree
      @uguree 3 года назад

      Well very nice comment but compressions don't make your code faster just tidier!
      Cheers

    • @ajflink
      @ajflink 2 года назад

      I have made essentially a curse word check in Python that checks for curses being used in a word, is simply a curse word, or composed of multiple and/or repeating curse words as well as having different rules for strings after a certain length. It can do a maximum of very roughly over 2 million checks before determining if a curse word is present in less than 1 second. I have recreated the Python code in C to discover that the speed is essentially the same and could not improve the speed in C any further.
      In general, Python is slower; however, when creating solutions and algorithms only possible in Python, it quickly becomes one of the fastest.

    • @dgh25
      @dgh25 Год назад

      👏

    • @robbprof111
      @robbprof111 Год назад

      @@uguree Perhaps. Cheers!

  • @igorthelight
    @igorthelight 5 лет назад +8

    How to make Java fast - use JIT compiler with "Server" preset
    How to make Python fast - use JIT compiler (PyPy) or compile your libraries to C and import them in your project (CPython). Second is more difficult and clashes with Python idea to be elegant and simple.

  • @liamattard3899
    @liamattard3899 4 года назад +94

    7:07 "whenever you do this you need to shutup"

    • @PwnUrBadCock
      @PwnUrBadCock 4 года назад +4

      I was looking for this comment

    • @disk38
      @disk38 4 года назад +1

      lmao that got me

  • @Sam-gd4xp
    @Sam-gd4xp 4 года назад +69

    You can speed up Python code quite substancially by using PyPy or Cython. Or by using LRE cache dictionary, that function doesnt have to re-calculate all over again in for/while loop

    • @ekrem_dincel
      @ekrem_dincel 4 года назад

      I did not understand LRE cache thing?

    • @ruudhermans4243
      @ruudhermans4243 4 года назад +2

      @@ekrem_dincel I assume he means using a cache to hold your variables but I am also guessing he means LRU and noet LRE. Would not know how using one would speed up Python though.

    • @ekrem_dincel
      @ekrem_dincel 4 года назад +2

      @@ruudhermans4243 I now got it, he means the "lru_cache" function in functools module.

    • @pawelpow
      @pawelpow 3 года назад +1

      Still not faster than C/C++ Though... sadly

    • @abhayagarwal5097
      @abhayagarwal5097 3 года назад

      @@pawelpow what do you even mean ?

  • @aliorunity
    @aliorunity 4 года назад +13

    I am not sure about the statement: the python is slow because its dynamic. Why? Lua.
    I am sure there is more to that. I am not an expert in python, but I think it's close enough.

  • @ChaosArtist
    @ChaosArtist 3 года назад +3

    I use Python a lot in my job, thanks for your explanation on why Python is slower than lower-level languages like Java and C.

  • @InternetMadeCoder
    @InternetMadeCoder 2 года назад

    Such a great explanation Tim!

  • @KayOScode
    @KayOScode 4 года назад +6

    So basically: how you make python faster is just using c. Glad we can agree on that

  • @MhmdK0030
    @MhmdK0030 4 года назад +1

    Great work Tim!! Keep it up 🌷🌹

  • @atrumluminarium
    @atrumluminarium 5 лет назад +14

    With regards to making "native python" faster, Numba is amazing. It's effectively just a decorator over native python and the acceleration on numerical tasks is comparable to C/Fortran with the simplicity of python.
    It also can interact with numpy for those wondering but at that point just use cython and import C headers directly since you're already deviating so much from native

    • @stdklr
      @stdklr 2 года назад +3

      Very important answer! You don't need to write C to make python faster. Let numba do it for you. It's converting your python code to C quite efficiently. You can keep your core code in python with all the convenience python is providing and just decorate the number crunching function that gives you a headache with numba. If it includes a prallelizable for loop you can just use numba's "prange" to even parallelize code.

    • @brianmcconnel640
      @brianmcconnel640 2 года назад

      This is the best comment on this video. There are reasons for why python was developed the way it was and why it is so popular. It feel like this video does not do the topic justice, and misrepresents the power of python. The better way to think of python is a general purpose scripting language for calling optimized libraries. If you are using it any other way you will be disappointed.

  • @laikbl
    @laikbl 5 лет назад +8

    Very informative and important at the same time, thx!

  • @pablomartinezazcona8450
    @pablomartinezazcona8450 4 года назад +3

    I am not an expert on this topic but I usually do heavy calculations in python and there's a module called Numba which has most of numpy's functions built in and it allows you to run some functions in python much faster, and even use parallel computation. It has allowed me to speed up my code a lot.

  • @MK-fw5bt
    @MK-fw5bt 4 года назад

    Thank you for Sharing, Tim!

  • @TobiPlayHD
    @TobiPlayHD 5 лет назад +21

    Writing main code in Python and importing Fortran/C algorithms is the way to go for me, most if the time at least. For most people speed really does not matter - if your code is written poorly in C there is no benefit to using it.

  • @thanatosor
    @thanatosor 5 лет назад +17

    If you can write fast code with slow language and have fun then you still can write faster code with fast language

  • @MegaToyy
    @MegaToyy 5 лет назад +22

    Python is a great PL for certain purposes. Imagine you need to walk to your barbershop one block away from home. Well you could . time your speed ,call a helicopter for that matter, and wait an hour for it to get to your house. Then find a place to land and so on.. Or you could simply use your Dynamic legs and put them into work.

    • @amirmousawi9156
      @amirmousawi9156 5 лет назад

      женя except when speed is necessary

    • @matiasrisso5917
      @matiasrisso5917 4 года назад +3

      @@amirmousawi9156 Well, he specifically gave a case when you don't. So what's your point?

    • @amirmousawi9156
      @amirmousawi9156 4 года назад

      I dont need to. It is obvious that python runtime is slow compare to languages such as c and c++.

    • @amirmousawi9156
      @amirmousawi9156 4 года назад

      @@matiasrisso5917 I dont need to. It is obvious that python runtime is slow compare to languages such as c and c++. So when speed is important python is not a good choice.

    • @AYoutubeUser0
      @AYoutubeUser0 3 года назад

      stupid logic 😂

  • @pushpajitbiswas3752
    @pushpajitbiswas3752 5 лет назад +49

    Really important video for python interview question, nicely explained man 👍

  • @SimGunther
    @SimGunther 5 лет назад +102

    UNIX: Everything's a file
    Python: Everything's an object, even when it doesn't need to be with unnecessarily high amount of levels in our hierarchies
    Smalltalk: Everything's an object, we just need reserved protocols and pointers to support our speedy tape measure despite the fact that we don't have an easy way to deploy our code
    C: Everything is a pointer, sometimes to functions, so be wary or else you get a segmentation fault for free

    • @__jan
      @__jan 5 лет назад +3

      In short, C is far superior to anything when you implement and use smart pointers.

    • @ShadersRS666
      @ShadersRS666 5 лет назад +3

      @@__jan What is a smart pointer in C?

    • @ShadersRS666
      @ShadersRS666 5 лет назад

      @@__jan Nothing exists all that pointers relies in memory and usage in typecasting in every single type that you see in pointers just goes through a specific memory address then you can disassemble in x86 where its going to head to in the offset relied in memory when it points you can make it point to another type

    • @comradepeter87
      @comradepeter87 5 лет назад +15

      Smart Pointers only exist in C++, not in C, as smart pointers heavily rely on destructor methods that are called after an object has gone out of scope and is to be deleted. C doesn't have objects, hence it doesn't have destructors either.

    • @OfficialRichardNixon
      @OfficialRichardNixon 4 года назад

      Vivek Yadav worst case make malloc/calloc/realloc/free wrappers maintaining a global array of void pointers thats freed via atexit. It’s janky but works if watch for abort

  • @broooth
    @broooth 4 года назад +1

    1) JS is a dynamic typing language but still fast on node.js
    2) Java still checks type matching at runtime: `String s = (String) (Object) 1;` as an example
    3) Node.js is also single-threaded but fast
    Seems like the real reason is that the python community doesn't care about performance much

  • @manojpawarsj3329
    @manojpawarsj3329 5 лет назад +40

    How about cython?

  • @md.nasiruddinprotul1315
    @md.nasiruddinprotul1315 5 лет назад +7

    If I have to write code in C to optimize, then why would I import it in Python and then run it. I can just run it as a C program with the C compiler.

    • @thedoublehelix5661
      @thedoublehelix5661 4 года назад +1

      Tell that to tensorflow

    • @onebacon_
      @onebacon_ 4 года назад +1

      If you already have a complex program, but one function is very slow. You can outsource that to the c compiler to optimize. This way you can keep the simplicity and elegance of python code while providing speed on complex requests.

    • @HermanWillems
      @HermanWillems 4 года назад

      Python is a composing language, a front-end language for gluing together modules like you are composing a solution. That's where python shines.

  • @Chertograad
    @Chertograad 2 года назад +5

    Then why is JavaScript so incredibly fast (especially comparing to Python) even though it is also dynamically typed?
    I'm not counter-argumenting. Just trying to understand...

    • @frostyflame4008
      @frostyflame4008 2 года назад +5

      pretty sure its all because JavaScript compiles the source code before the program starts, while Python does it one by one line

    • @thefoolishgmodcube2644
      @thefoolishgmodcube2644 Год назад +1

      Same for Lua. It's also dynamically typed but runs just as fast as a C program according to Linux's time command

    • @houstonfirefox
      @houstonfirefox Год назад

      JavaScript isn't a real language IMHO 🤣

  • @arbazkhan8320
    @arbazkhan8320 5 лет назад +18

    Can you make a video of how we can import a c progam in Python as an extension??

    • @TheTWYChannel
      @TheTWYChannel 5 лет назад +1

      Bhai kya bol raha ho

    • @Rajat-Sharma1
      @Rajat-Sharma1 5 лет назад +1

      😱

    • @omparikh4426
      @omparikh4426 5 лет назад +1

      🤣

    • @epsilonator
      @epsilonator 5 лет назад +2

      He's not kidding. It's possible

    • @omparikh4426
      @omparikh4426 5 лет назад +2

      @@epsilonator it's possible but not the way he describes. First you need to convert to bytecode to implement that

  • @universenerdd
    @universenerdd 4 года назад

    because python is an interpreted language, which means it scans the individual lines of code to see the machine instructions, while the others are compiled languages

  • @akj7
    @akj7 4 года назад +33

    8:00 Python is not written in C, CPython is.
    Moreover Python is not slow because of it is interpreted. Pypy is faster than CPython and even PHP is faster than CPython.
    CPython is actually slow because the language wasn't develop with Performance in Mind. A number is not only a whole class, but it is by default a BigNumber: it looks like this internally: struct {int total; int* digits}. While in C, long a = 500000000; gets converted to machine code directly and the variable name thrown away. Python will save the variable name, handle the reference counting, split the number into chunks and save them in the struct which is allocated on the heap. Even writing this pains me as a C, C++ dev.
    Ok, let's say, you want to anotate your code and do a: string. Python will store the annotation and doesn't actually give a crap if you do a = 2.

    • @ezrashaw1835
      @ezrashaw1835 4 года назад

      This is correct. I don't really know what else to say though.

    • @Markkkkkkkkkkkkkkkkk
      @Markkkkkkkkkkkkkkkkk 4 года назад

      Python IS written in C
      The first implementation was named CPython
      BOTH python and cpython are written in C just like 80% of modern programming languages

    • @akj7
      @akj7 4 года назад +2

      @@Markkkkkkkkkkkkkkkkk What are you talking about? I worked on the Cpython source code. Python is a programming language. It is not written in anoter language. Just like English is not written in German or Latin. CPython is the default and most popular Python interpreter. When people say Python, they mean Python interpreted by CPython.
      By the way modern Programming languages (interpreter/compiler) are written in C++, not C. Take a look at Swift, JavaScript (V8), Node, Julia, Rust.

    • @qendrimimeri2219
      @qendrimimeri2219 4 года назад

      @@akj7 i am new to tech, but with what i know C is lower than C++ and its closer to the machine why they use C++ for interpreter rather than C and most compiler of C++ is written in C ?

    • @akj7
      @akj7 4 года назад +2

      @@qendrimimeri2219 No. C and C++ are on the same level. C++ just has more features. C is not a low level language. C++ adds classes, which get transpiled to their C counterpart: struct, and the methods get turned into normal functions. The issue with C++ is name mangling. When you write a function in C, it has the same name in the binary output however every C++ compiler generates its functions differently (because of namespaces, ...). Due to this, it is harder to create shared libraries with C++, instead nowadays, people write their programs more in C++ instead of C and create C bindings for them.

  • @justinlee3453
    @justinlee3453 4 года назад

    super clear explanation and answers some of my problems I previously thought of

  • @olegkorsunskyi7007
    @olegkorsunskyi7007 5 лет назад +51

    Tell about the different versions of Python such as Pypy, IronPython, Jython and so on.

    • @user-ob5hj5vn8c
      @user-ob5hj5vn8c 5 лет назад +7

      Oleg Korsunskyi PyPy is fucking fast. Insanely fast. IronPython and Jython I think just allows c# and Java libraries

    • @xeome5596
      @xeome5596 5 лет назад +1

      @@user-ob5hj5vn8c still not fast as c++ or c or luajit

    • @user-ob5hj5vn8c
      @user-ob5hj5vn8c 5 лет назад +6

      ​@@xeome5596 True, although compared to regular python it is fast as helllllll

    • @jodazague8333
      @jodazague8333 4 года назад +1

      Isn't IronPy dead?

  • @arbazkhan8320
    @arbazkhan8320 5 лет назад +5

    Thanks for explaining it in a simple way...👍

  • @FabledNarrative
    @FabledNarrative 5 лет назад +23

    Keep up the great work, man!
    Videos like these seem simple, but in the long run,
    it will show case how much of a professional and teacher you are.
    :D

  • @ZaCharlemagne
    @ZaCharlemagne 2 года назад +1

    Nice explaination. 👍🔥
    There are also other ways to make Ur python code fast:
    JIT compilation. Because JIT compilation skips the whole process that goes on in the PVM and compiles code straight with an LLVM, it executes just as fast as C, or slightly slower, or in some cases (due to caching) faster.
    Another way is with Cython, which is a way of compiling python script to C++ code, for this you would need Ur python skills and some extra stuff from static typing to be able to write .pyx files (different from Ur regular .py files) you can achieve C++ speed with this as well. There's also another version called Jython (compiling python code to java)
    PS: I've tried all these out (except the Jython). Tho I don't code java, I do code C++.
    Concurrency and multiprocessing in python is actually straight forward, people only tend to use them where they don't necessarily apply (just saying) modules like asyncio can enable you convert a single thread python function into a coroutine simply by adding the function in the asyncio event loop or running loop. Also for anyone interested in performing multiprocessing in python I would advise you familiarise urself with mesh reduction.
    Also, most python modules / libraries / frameworks have key parts written in C or C++ or both...this is why one of the most computationally expensive tasks (machine learning) is done with python.
    And then, with the advancements in computer processors these days, the speed difference in alot of cases cannot even be perceived by humans (as you've already insinuated)

  • @doldol1
    @doldol1 4 года назад +9

    "python in an extremely slow programming language", you're confusing language with implementation there. In this case you're talking about CPython, the reference implementation of Python

    • @chudchadanstud
      @chudchadanstud 3 года назад +1

      CPython is not python. It's C. You're just converting your code to C and compiling.

  • @HABIBMUHD92
    @HABIBMUHD92 5 лет назад

    Informative as always thank you!

  • @dylanharding5720
    @dylanharding5720 4 года назад +2

    The main speed issue comes from the lack of a jit compiler. Pypy includes one, and, especially with long running scripts, can see as much as 6 times the performance increase. (note that it can be slower at times, especially with short running scripts)

  • @quantumjun
    @quantumjun 2 года назад

    that’s awesome, do you have a “deeper understanding” now. Can you make a video if so?

  • @jimihenrik11
    @jimihenrik11 5 лет назад +3

    This is the first time I ever heard someone say java was fast. I usually get to hear stuff like "slow languages like java are so inferior to faster languages like haskell".

    • @lincolnsand5127
      @lincolnsand5127 5 лет назад +1

      Haskell is not a fast language. Neither is java. Haskell has extremely strong typing, but is very high level, it also has a gc. Its gc is better than java's. Java is slow because it uses the jvm & a gc. C & Rust would be good examples of fast languages.

    • @chaddaifouche536
      @chaddaifouche536 4 года назад

      @@lincolnsand5127 In so far as we compare the couple "Language + standard compiler/interpreter", Haskell with GHC is definitely in the fast category. Of course what often makes the difference is the algorithms you use and idioms in your language can influence you to write slow code, such is the case with Haskell if you use the default lists and strings as a panacea (it is very easy to use better data structures without changing your code much thanks to type class but beginners are not always aware of that).
      On the other hand I would also place Java in the fast category, comparable to Haskell.
      The absolute best languages to write performance critical code are still C, C++, Rust or Fortran (eventually with some Asm) but you very rarely need this kind of performance in general programming and can often make do with fast high-level languages like Java, C#, Haskell, OCaml and so on. C and Fortran should probably be a last resort if you really need the performance, they're much too low level. C++ and Rust are reasonably high-level and Rust even provides a lot of safety compared to C/C++ but they're still more painful to write in than a higher level language.

    • @lincolnsand5127
      @lincolnsand5127 4 года назад

      @@chaddaifouche536 I'll tackle this in pieces. So. For the first part, Haskell is just a bit faster than java but nowhere near C/C++. Haskell is memory efficient and has the best gc I've ever seen. As for what fast is, I think Haskell and Java are slow because I mainly use C++ & Rust. So to me, these languages are slow. If you're using a snail language like Ruby or python, then Java is probably "fast." As for the last part, I somewhat disagree. I regularly use Rust even when I'm not doing performance critical operations because its abstractions and type systems are better than most mainstream high level languages that I've seen. I also think that pointers and consistent object lifetimes are very useful for code design and modeling how code should behave and neither of these are possible in high level languages (usually). Lastly, while C++ *can* be a pain sometimes, I think Rust is nicer to write code in than most high level languages. Also. I agree that Fortran and assembly are painful and should only be used when needed.

  • @welawela105
    @welawela105 2 года назад

    An other reason why Python is so used is, for "simple tasks", technology progress made C as fast as python at user scale.
    For example a C program that would last 0.001 seconds can be seen as fast as a Python program of 0.1 sec runtime, the time difference is imperceptible.

  • @sidneywinter8952
    @sidneywinter8952 4 года назад +6

    An interpreter that runs slow.,, That ring a bell! OMG, it reminds me of the old BASICA programming languag the 1980's and MS-DOS. Python is the BASIC!

    • @fatfurry
      @fatfurry 4 года назад +1

      Yes!

    • @simpletongeek
      @simpletongeek 4 года назад

      Old Basica? That was never popular. I'm surprised you mentioned that one. I think Atari Basic holds the prize for being the slowest of them all. It has a relatively powerful set of commands, but they have to make a lot of sacrifices to fit them into 8K. Later Basics for Atari broke the 8K limit and thus run much faster.

    • @sidneywinter8952
      @sidneywinter8952 4 года назад

      @@simpletongeek I'm comptemplating to either learn a new language like Python, Java, or the like or just keep using some of my older compilers.

    • @simpletongeek
      @simpletongeek 4 года назад

      @@sidneywinter8952 why would you want to learn a new language? For backend server side development, python is the wrong language to learn. For front end development, that's HTML5, CSS, Javascript.
      Java is good for generic usage, so you may want to learn that. I prefer Processing, though. It compiles to Java, and in fact, you will need Java for the really advanced usage of it. Processing is the gateway to Java and Javascript (via P5.js)
      If it's for personal use, then anything is fine. I'm currently finding out that Bash is rather powerful all by itself, and that assuming you don't need GUI, it can handle a lot of the old style textual interface programs.
      My preference is actually Basic and C, but Perl/Python/Ruby are useful. Just pick one. HTH.

    • @sidneywinter8952
      @sidneywinter8952 4 года назад

      @@simpletongeek I'm retiring next year (62) and I thought about upgrading to the new "languages". I took a course (Java) at a local community college and later saw some tutorials on the languages, so I decided to drop out after a week and get a refund and study at my own pace.

  • @akin242002
    @akin242002 4 года назад +1

    Gaming, multimedia, or high speed day trading industries may lean towards C and C++. Every other industry that doesn't need the fastest compute time are fine with Java, Javascript, or Python.

  • @ymhsieh
    @ymhsieh 3 года назад +3

    JavaScript is also a dynamic typing language, and it is also much faster than Python...

  • @nelsonk1341
    @nelsonk1341 2 года назад

    python: run slow, writes fast. C++: write really slow, debugging really slow, run fast

  • @norpriest521
    @norpriest521 4 года назад +4

    But I'm Data Engineer, not Software Developer.
    So I still need to use Python for the most part.
    So I guess as a Data Engineer, this is not gonna affect me, right?
    Data Engineer only uses Python to get their job done.
    No need to adapt in soon future?

  • @WiredMartian
    @WiredMartian 4 года назад

    Finally, Thank you 🙏🏽

  • @codewithwasif3517
    @codewithwasif3517 5 лет назад +8

    Love the way you explain things 💞

  • @ibapt
    @ibapt 4 года назад

    1000th commentary, from France !

  • @atharva1237
    @atharva1237 4 года назад +3

    Can u make a video on how to use C as an extension for python? Love your video as always.

  • @ojouniisama5401
    @ojouniisama5401 4 года назад +1

    Python may be slow but it's fast enough don't get discouraged of learning python because many says it's slow python isn't made for optimization but it has many features that takes forever to code in low level languages, so it's still a good language to learn

  • @justinlee4572
    @justinlee4572 3 года назад +9

    important to note: For most io bound loads (like running a web server), having n threads does not directly translate to n times performance. Also, single threaded asyncio based webservers frameworks like uvicorn/ node are often surprisingly fast.

    • @marcossidoruk8033
      @marcossidoruk8033 Год назад

      If you are IO bound 95% of the time and then you get a sudden spike in things to do that will still translate to a sudden lag spike once in a while and thus bad user experience.
      To this one should add that latencies add, even if the work your program does is 2x faster than the IO that still represents 33% of the latency time in your program, wich is quite significant.
      "IO slow therefore performance doesn't matter" is a terrible excuse 90% of the time, if you are doing something utterly trivial it might be a good excuse but as long as your program is actually doing something half interesting performance is important, perhaps not triple A video game kind of performance but in some way or form you should care about performance.

  • @AtomkeySinclair
    @AtomkeySinclair 5 лет назад +2

    Great content here. Thx. It think py gained popularity from the Maker folks - stem, rpi, arduino, iot... etc. And to make things worse, the desire for intermediate understanding of deep learning. Think scikit and Tensorflow. Which is crazy since that is mostly linear algebra, matrix math - and intensive list handling. But py makes the approach easy to handle especially for type conversions and containers. So the simplicity of py made coding it so attractive that folks got spoiled with it. Pre-existing cookie-cutter copy-past code and libs for interfacing with hardware and server services made it super easy. See github for copious examples. Attempting to move into C from that background will prove very frustrating. The whole idea that "I have to allocate and free memory for a variable?" mentality is just the beginning of it. And to be honest, some introductions in newer C++ standards are re-creating that lax attitude. Smart, self-maintaining classes like deque, array, and vector remove the responsibility from the programmer to know the actual algorithm/implementation by hiding it in the so-loved obscurity of object abstraction. Sometimes, I think, over encapsulation/abstraction will end up shooting you in the foot. It might just be that you could double the speed of a code section by doing it yourself. Class and template expectations are often large in the final design. Often simple is far better.

  • @baruchben-david4196
    @baruchben-david4196 5 лет назад +4

    It's great that development time is so fast, but... Once you've done the development, your program is still slow, and will remain so...

    • @mantality312
      @mantality312 4 года назад +1

      No, it will not remain slow and no it will not seem slower. This is the problem with self taught programmers, they regurgitate these kind of non-sensical ideas with no true knowledge of computing. There is no noticeable difference in a python script vs a c++ script. The only time it matters is when the code has to interact directly with the RAM and processors which python can not, thus making it ‘slow’. This is typically only relevant in embedded systems and gaming which shouldn’t be written in Python anyway. For anything Python is meant to be used for there will never be a noticeable or recordable difference in speed.

    • @jameszack7158
      @jameszack7158 4 года назад

      Only a few microseconds slower. You won't even notice it

    • @jameszack7158
      @jameszack7158 4 года назад

      @@mantality312 exactly, we are not coding F-35's software with python. Therefore speed difference is negligible

    • @sanjay_swain
      @sanjay_swain 3 года назад

      @@jameszack7158 "you won't even noticed it" this says you have never worked on real life. In reality a microseconds is really really helpful especially when you are dealing with millions and millions of data.

    • @jameszack7158
      @jameszack7158 3 года назад

      @@sanjay_swain I don't think so. Every year computer hardwares and microprocessors double their speed. Maybe 20 years ago programs written in python were slow, but not today

  • @gwenaeloppitz3972
    @gwenaeloppitz3972 4 года назад

    Really interesting man thanks

  • @michealhall7776
    @michealhall7776 5 лет назад +5

    Tim can you make a video about importing c code into python. What about c++?

    • @MSneberger
      @MSneberger 4 года назад +1

      Why not just write C/C++ then?

    • @madhulikamadhu51
      @madhulikamadhu51 3 года назад +1

      If you took your pain to write in c
      Let your prograam run in a 200 times faster language, don't convert to python

  • @arunabraham9382
    @arunabraham9382 3 года назад +1

    PHP dynamically typed. Much faster than python ever could dream. PS: speed out of the box

  • @DrLegitimate
    @DrLegitimate 4 года назад +5

    11 minutes to say, 'It's interpreted' -- excellent.

  • @ojouniisama5401
    @ojouniisama5401 4 года назад

    I'm currently taking CS50x an online course from harvard, the course progresses with scratch, c, python, sql then you choose tracks web android etc... There was a problem here where we were to create a spellchecker program in C that was so frustrating to make if you're new to c and data structures, then the next lecture we were shown how to implement that same program in python, and damn it was mesmerizing how little code was used, but also we were shown the cost of this little of code. The program we wrote aside from the functionality of spellchecking it was encourage to optimize the program as much as possible, the program also outputs the time it took in the functions and the overall time it took to spellcheck the file. In C the implementation of the staff took 0.6 smth s but in python it took 1.5 smth s the difference was very small but It made me realize there is no best language all of them have their advantages and disadvantages in certain situations, I'm quite bad with python currently but I'm trying to get comfortable with it cause I'm pretty comfy with c because i took a class with c++ before

  • @mansodev
    @mansodev 4 года назад +4

    Python was just too slow for me so I just used lua, it’s faster and lightweight than python, and is quite similar.
    Btw lua is a scripting language but there is luaJIT

    • @patrickcampbell957
      @patrickcampbell957 4 года назад +1

      What were you doing where python was too slow?

    • @mansodev
      @mansodev 4 года назад +1

      @@patrickcampbell957 (sorry for the very slow response) Iwas trying to re=create the game of life in the python terminal, I eventually transferred and edited all code to be compatible to pygame, the game ran very slow and took ages to load even with cpython and PyPy which are Jit compilers for pyhton t was still quite slow, I quit the project. I then found out about lua and LuaJIT and since moved there

  • @fulcanelly
    @fulcanelly 3 года назад +1

    Sorry, but you are wrong blaming in slowness dynamic typing. The good example of fast dynamic languages: luajit, julia, lisp and even C#. The reason why java fast isn't static typing (which not actually static, thankfully for Object) but it's JIT wich was improved for years and python slow for same reason: it's designers was focused not on performance but on speed of writing code. You saying that the slowness is the cost of type checks but java perform them to, the main trick is java's JIT who eliminates them based on where and how often they occur in runtime or even replace code with shorter equivalent.

  • @rahulmandal6139
    @rahulmandal6139 4 года назад +8

    No worries,we got a lots of reasons to love Python🐍

  • @jsonkody
    @jsonkody 4 года назад

    One of the best technique to speed up Python is to use Julia, but still lacking enormous number of Pyhton packages.

  • @alcar32sharif
    @alcar32sharif 4 года назад +7

    Broadly python became a C/C++ wrapper, because it is too slow.

    • @HermanWillems
      @HermanWillems 4 года назад +2

      In that sense, pythons is just a markup language for C/C++ modules.

    • @akj7
      @akj7 4 года назад +1

      I heard every language is a wrapper around C or C++. Go was written in C, then they used the old Go to write newer ones. Swift is written in C++, CPython is written in C. PHP in C, Java interpreter is written in C, Rust uses LLVM which is written in C++, JavaScript's Intepreter V8 is written in C++.

  • @pixel7038
    @pixel7038 5 лет назад

    What's cool about PyTorch is how you can develop your algorithms in python and deploy in C++.

  • @FeedFall8
    @FeedFall8 5 лет назад +6

    can you do a tutorial on using cython to convert python programs to c\c++?

  • @HardCorn12
    @HardCorn12 4 года назад

    another reason is that alot of people are writing in python but in a c language style (since they came from c or cpp c# java background) and python was not designed for it. if you write in "pythonic" way it will get faster. obviously this isn't a main reason but it is some part of the reason.

  • @nopens
    @nopens 5 лет назад +5

    Good video. Thank you. Python is fast *enough*, but as with anything in programming, you gotta use specific tools for specific task when you have to achieve best results. Im sure some time in the future (maybe python5?) will catch up in speeds.

    • @supremedeity9003
      @supremedeity9003 5 лет назад +2

      well the problem is not a problem in code. the actual thing is just python is interpreted and c++ etc are compiled.

  • @24mrdanny
    @24mrdanny 5 лет назад +2

    Does anyone know if when I use static type checking in python, do some of the slowness issues he mentioned go away?
    Python Static Types: medium.com/@ageitgey/learn-how-to-use-static-type-checking-in-python-3-6-in-10-minutes-12c86d72677b

    • @pavlg3944
      @pavlg3944 4 года назад

      Because static keyword locks the object to the memory so when its context or class is destroyed, it's done & you cannot use it w/o passing the compiler back to the line of the declaration of that variable or object ....so it helps in terms of performance and memory but you cannot use this in dynamic cases because if you destroy the thread of class or context having that variable & use that variable in a context you will get a NullPointerException or IllegalStateException & by the way static makes the object creatable only at the runtime of the context only one-time after that you cannot recreate it ...you will have to reRun the context or the application

  • @yuvalmusali2492
    @yuvalmusali2492 4 года назад +3

    That's right, but you have to remember that you can still define the type of variables in Python, and I actually use it a lot, for example:
    var: int
    That way Python know to inform you that you can't use string functions and methods on this variable, while you CAN use int functions and methods, or that you can or cannot send a certain parameter to a function according to its type.

  • @Luix
    @Luix 4 года назад +3

    C++, golang, rust. Or use wrappers like in ML.

  • @Vorlos
    @Vorlos 5 лет назад +9

    What I find most befuddling about this, is how *little* value dynamic typing brings, if any at all.
    Never in my years of programming in Python I exclaimed "Gee! I'm sure glad I didn't have to spell out the type of that variable there!". What it instead does, is reducing the clarity of the program not only for the humans writing and maintaining the code, but also the IDEs themselves which often fail to give you meaningful warnings of you fucking up.
    And for the cases, where it is supposed to be useful, i.e. having an input variable be of several possible types depending on what the function is supposed to do with it, Union Types a la Typescript do just as well of a job with all the benefits of static typing.
    So who thought that this was ever a good idea?

    • @pcp1976
      @pcp1976 5 лет назад

      Someone who wanted to monkey patch your class.

    • @mennoltvanalten7260
      @mennoltvanalten7260 5 лет назад +2

      And then the best thing: In my python programming class when making a function we had to typehint, aka write out the type. So instead of 'def function(x, y, flag):' we needed to write function(x: int, y: int, flag: bool) -> None:', which greatly negates the 'advantage' of writing dynamically.

    • @Vorlos
      @Vorlos 5 лет назад +1

      They're coming full circle.

    • @marcovoetberg6618
      @marcovoetberg6618 4 года назад

      I don’t know but I hate dynamically typed languages with a passion. I like my programming language strongly typed with type inference preferably and good code editor to help me out. Dynamically typed language make it too easy for me to create bugs that sometimes manage to hide for years only sometimes noticed and just hellish to find.

  • @shehab976
    @shehab976 3 года назад

    exactly,every languages have their own puposes....no one is best neither worst...they were just built by their creator for specific aims.But after all, i just love python the way it is so simple...some miliseconds doesn matter...good say tim,i am a great fan of yours!!

  • @Jib9001
    @Jib9001 5 лет назад +16

    I would argue that "python code can be developed 4 to 5 times quicker" is outright false. Sure for certain small things it can be done quicker, but when you get into large programs the speed advantages diminish greatly. Then it's dynamic and unclear nature actually can make it more difficult to debug.
    At least, as a senior computer science student who's programed in nearly 10 different languages, this has been my personal experience

    • @ogibalboa6517
      @ogibalboa6517 5 лет назад

      Connor Tellep I had a project that i need to communicate raspberry and arduino. I created a data algorithm which the integer values will placed side by side and sent to raspberry by serial from arduino and parsed again on raspberry. Man, it took 2 hours to understand how can i do it in c lang and finally i cancelled it. I know it might my fault but i could did it with 2 or 3 code in Python. But in C ?

    • @chaddaifouche536
      @chaddaifouche536 4 года назад

      @@ogibalboa6517 So you're comparing the time it would take you to write it in Python, a language you already know, to the time it would take to learn C + its interface to miscellaneous devices + the time to write the program ? And it seems going with Python would be faster ? Don't you think there's a slight bias in your comparison ?
      I'm not telling you that writing Python is not faster than writing the same in C (at least for small programs), it very clearly is, but Connor was talking about writing big programs for someone who's already adept with both languages and in this case I agree that "4 to 5x quicker" is an exaggeration.

  • @DoCodeRu
    @DoCodeRu 5 лет назад

    If you like Python syntax i recommend see Nim language. Nim compiles to C, C++ and JavaScript. If you already have a project with tons of Python code, see Dropbox project mypyc for converting Python code to C.

    • @encapsulatio
      @encapsulatio 4 года назад

      Yes but how does it compare to python in how much code you need to write?

  • @Luix
    @Luix 4 года назад +5

    Java is bytecode run in JVM. Java is slower than C C++ Go and Rust.

  • @megapixeler
    @megapixeler 4 года назад

    I was under the impression that the major cost of interpreted languages was that they had to be translated to machine code line by line... But now that I think of it, each line has to check for scope, type and logic of variables and stuff, so yes it makes sense.

  • @whawojedo
    @whawojedo 4 года назад +4

    I develop trading bots as a hobby. I use C for the backtests as the compiled .exes run 50 (!) times faster than the equivalent Python. The code that does the actual online trading is written in Python though as I don't need the speed and Python is waaaayyy nicer to work with, and easier to maintain.

    • @pcp1976
      @pcp1976 4 года назад +2

      This is a response that shows understanding which tools to use when. Lots of comments seem to want to make the argument that the only thing that matters is execution speed.

  • @velfad
    @velfad 4 года назад +1

    Any language requires special API to work with multi-threading, such as locks for shared objects. However certain compilers for statically typed languages might be advanced enough to do it automatically for some algorithms. It's just nobody bothered to implement this in Python so you have to do it all manually...

  • @domninin
    @domninin 4 года назад +8

    Java is actually compiled and interpreted, just like Python. Kind of a big thing to get wrong

    • @RWLN508D
      @RWLN508D 4 года назад +9

      Dominik T Java is compiled an runs on a vm, python is interpreted.

    • @lesfreresdelaquote1176
      @lesfreresdelaquote1176 4 года назад +1

      Crackpipe9 Python and Java work the same way. They are both compiled into an intermediary code (p-code), which is then executed in a virtual machine (pyc files). The role of this virtual machine is to execute this p-code, which is seen as some kind of pseudo-machine language. The main difference is that Java also evaluates the code at run time and can decide to compile into native machine language some recurrent snippets with the Just In Time Compiler. The compiler is also much more sophisticated in Java than in Python and can provide some very smart acceleration in the code that is produced.

    • @ekrem_dincel
      @ekrem_dincel 4 года назад

      @@RWLN508D python is compiled and runs on a vm, java is interpreted

    • @HermanWillems
      @HermanWillems 4 года назад

      @@ekrem_dincel i like your style. Let the programming language wars start !! ( Grandpa how did WW3 started? Well my child, it started with a fight between python and java..)

    • @ekrem_dincel
      @ekrem_dincel 4 года назад

      @@HermanWillems i did joke, i know both python and java are compiled into bytecode and then interpreted by a vm.

  • @markuspfeifer8473
    @markuspfeifer8473 2 года назад

    You’ll only get the benefit of faster development time if you can copy paste a lot of stuff from the internet. As soon as you try putting together your own solution and there’s a bug, debugging will cost you ten times longer than with Java, c++ or swift

  • @jaysanprogramming6818
    @jaysanprogramming6818 5 лет назад +4

    I don't know what to think of this video... Python binds a data which have a very specific type all the time it exists to a name (a variable). So that dynamic type arguing is not that accurate.

    • @telnobynoyator_6183
      @telnobynoyator_6183 4 года назад

      + that's not a reason for a language to be slow. Take js and the v8 engine for example.

    • @jaysanprogramming6818
      @jaysanprogramming6818 4 года назад +2

      @@telnobynoyator_6183 I don't know about JS v8 performances but I assume what you say here is that it's much better than Python. I heard that some Python implementations are quite fast. Would they be able to compete with JS v8 ?

  • @rohitjon4512
    @rohitjon4512 4 года назад +2

    Tim, what do you think about a language like Julia which is easy to write and at the same time has fast execution?

  • @xKenshin13
    @xKenshin13 4 года назад +5

    Since when is java considered a low level language?

    • @therealslimastolfo
      @therealslimastolfo 4 года назад

      do you know what low level means?

    • @xKenshin13
      @xKenshin13 4 года назад

      @@therealslimastolfo Yes, and Javas def. is not a low level language.

    • @therealslimastolfo
      @therealslimastolfo 4 года назад +2

      Kenshin well when you’re comparing it to python, it’s fair to call java, c, c++, etc lower level languages

    • @xKenshin13
      @xKenshin13 4 года назад

      Team Astolfo I completely disagree.

    • @xKenshin13
      @xKenshin13 4 года назад

      Team Astolfo You don't even have to worry about memory allocation in Java. You even get a garbage collector (even if it's complete trash and can barley be referred to as a garbage collector). What exactly is so low level about it?

  • @geekhamster4032
    @geekhamster4032 4 года назад +1

    Python is great for startups but at the end the cost in terms of lack of concurrency and performance issues can be dramatic. I'm living a nightmare with code made this way. We can't support too many users executing something really simple at the same time.

  • @dsinghr
    @dsinghr 4 года назад +4

    I have spent 6 months learning python and now you are telling me it is slow !