Tuesday, March 17, 2020
Programming Languages Comparison
Programming Languages Comparison Since the 1950s, computer scientists have devised thousands of programming languages. Many are obscure, perhaps created for a Ph.D. thesis and never heard of since. Others became popular for a while then faded due to lack of support or because they were limited to a particular computer system. Some are variants of existing languages, adding new features like parallelism- the ability to run many parts of a program on different computers in parallel. Read more about What is a programming language? Comparing Programming Languages There are several ways to compare computer Languages but for simplicity, well compare them by Compilation Method and Abstraction Level. Compiling to Machine Code Some languages require programs to be transformed directly into Machine Code- the instructions that a CPU understands directly. This transformation process is called compilation. Assembly Language, C, C, and Pascal are compiled languages. Interpreted Languages Other languages are either Interpreted such as Basic, Actionscript, and Javascript, or a mixture of both being compiled to an intermediate language - this includes Java and C#. An Interpreted language is processed at runtime. Every line is read, analyzed, and executed. Having to reprocess a line every time in a loop is what makes interpreted languages so slow. This overhead means that interpreted code runs between 5 - 10 times slower than compiled code. The interpreted languages like Basic or JavaScript are the slowest. Their advantage is not needing to be recompiled after changes and that is handy when youre learning to program. Because compiled programs almost always run faster than interpreted, languages such as C and C tend to be the most popular for writing games. Java and C# both compile to an interpreted language which is very efficient. Because the Virtual Machine that interprets Java and the .NET framework that runs C# are heavily optimized, its claimed that applications in those languages are as fast if not faster as compiled C. Level of Abstraction The other way to compare languages is level of abstraction. This indicates how close a particular language is to the hardware. Machine Code is the lowest level,à with Assembly Language just above it. C is higher than C because C offers greater abstraction. Java and C# are higher than C because they compile to an intermediate language called bytecode. How Languages Compare Fast Compiled Languages Assembly LanguageCCPascalC#Java Reasonably Fast Interpreted PerlPHP Slow Interpreted JavaScriptActionScriptBasic Machine Code is the instructions that aà CPUà executes. Its the only thing that a CPU can understand and execute.à Interpretedà languages need an application called anà Interpreterà that reads each line of the program source code and then runs it. Interpreting Is Easier Its very easy to stop, change and re-run applications written in an interpreted language and that is why theyre popular for learning programming. There is no compilation stage needed. Compiling can be quite a slow process. A large Visual C application can take from minutes to hours to compile, depending on how much code has to be rebuilt and the speed of memory and theà CPU. When Computers First Appeared When computers first became popular in the 1950s, programs were written in machine code as there was no other way. Programmers had to physically flip switches to enter values. This is such a tedious and slow way of creating an application that higher level computer languages had to be created. Assembler: Fast to Run- Slow to Write! Assembly language is the readable version of Machine Code and looks like this Mov A,$45 Because it is tied to a particular CPU or family of related CPUs, Assembly Language is not veryà portableà and is time-consuming to learn and write. Languages like C have reduced the need for Assembly Language programming except where RAM is limited or time-critical code is needed. This is typically in theà kernelà code at the heart of an Operating System or in a video card driver. Assembly Language Is the Lowest Level of Code Assembly Language is very low level; most of the code just moves values between theà CPUà registers and memory. If you are writing a payroll package you want to think in terms of salaries and tax deductions, notà Registerà A to Memory location XYZ. This is why higher level languages like C,à C#à orà Javaà are more productive. The programmer can think in terms of the problem domain (salaries, deductions, and accruals) not the hardware domain (registers, memory, and instructions). Systems Programming With C C was devised in the early 1970s by Dennis Ritchie. It can be thought of as a general purpose tool- very useful and powerful but very easy to let bugs through that can make systems insecure. C is a low-level language and has been described as portable Assembly language. The syntax of many scriptingà languages is based on C, for example,à JavaScript, PHP, and ActionScript. Perl: Websites and Utilities Very popular in theà Linuxà world, Perl was one of the first web languages and remains very popular today. For doing quick and dirty programming on the web it remains unrivaled and drives many websites. It has though been somewhat eclipsed byà PHP as a web scripting language. Coding Websites With PHP PHPà was designed as a language for Web Servers and is very popular in conjunction with Linux, Apache, MySql, and PHP or LAMP for short. It is interpreted, but pre-compiled so code executes reasonably quickly. It can be run on desktop computers but is not as widely used for developing desktop applications. Based on Cà syntax, it also includesà Objectsà and Classes. Pascalà was devised as a teaching language a few years before C but was very limited with poor string and file handling. Several Manufacturers extended the language but there was no overall leader until Borlands Turbo Pascal (for Dos) and Delphi (for Windows) appeared. These were powerful implementations that added enough functionality to make them suitable for commercial development. However, Borland was up against the much bigger Microsoft and lost the battle. C: A Classy Language! C or C plus classes as it was originally known came about ten years after C and successfully introduced Object Oriented Programming to C, as well as features like exceptions and templates. Learning all of C is a big task- it is by far the most complicated of the programming languages here but once you have mastered it, youll have no difficulty with any other language. C#: Microsofts Big Bet C#à was created byà Delphis architect Anders Hejlsberg after he moved to Microsoft and Delphi developers will feel at home with features such as Windows forms. C#à syntaxà is very similar toà Java, which is not surprising as Hejlsberg also worked on J after he moved to Microsoft. Learn C# and you are well on the way to knowingà Java. Both languages are semi-compiled so that instead of compiling to machine code, they compile toà bytecodeà ( C# compiles toà CILà but it and Bytecode are similar) and are thenà interpreted. Javascript: Programs in Your Browser Javascriptà is nothing like Java, instead, its aà scriptingà language based on C syntax but with the addition ofà Objectsà and is used mainly in browsers. JavaScript is interpreted and a lot slower thanà compiledà code but works well within a browser. Invented by Netscape it has proved very successful and after several years in the doldrums is enjoying a new lease of life because ofà AJAX; Asynchronous Javascript and XML. This allows parts of web pages to update from the server without redrawing the entire page. ActionScript: A Flashy Language! ActionScriptà is an implementation of JavaScript but exists solely within Macromedia Flash applications.à Using vector-based graphics, it is used mainly for games, playing videos and other visual effects and for developing sophisticated user interfaces, all running in the browser. Basic for Beginners Basicà is an acronym for Beginners All-purpose Symbolic Instruction Code and was created to teach programming in the 1960s. Microsoft has made the language their own with many different versions including VBScript for websites and the very successfulà Visual Basic. The latest version of that is VB.NET and this runs on the same platformà .NETà as C# and produces the same CIL bytecode. Lua is a free scripting language written in C that includes garbage collection and coroutines. It interfaces well with C/C and is used in the games industry (and non-games as well) to script game logic, event triggers, and game control. Conclusion While everyone has their favorite language and has invested time and resources in learning how to program it, there are some problems that are best solved with the right language. E.G you wouldnt use C for writing web apps and you wouldnt write an Operating System in Javascript. But whichever language you choose, if its C, C or C#, at least you know youre in the right place to learn it.
Sunday, March 1, 2020
Gunpowder Facts, History and Description
Gunpowder Facts, History and Description Gunpowder or black powder is of great historical importance in chemistry. Although it can explode, its principal use is as a propellant. Gunpowder was invented by Chinese alchemists in the 9th century. Originally, it was made by mixing elemental sulfur, charcoal, and saltpeter (potassium nitrate). The charcoal traditionally came from the willow tree, but grapevine, hazel, elder, laurel, and pine cones have all been used. Charcoal is not the only fuel that can be used. Sugar is used instead in many pyrotechnic applications. When the ingredients were carefully ground together, the end result was a powder that was called serpentine. The ingredients tended to require remixing prior to use, so making gunpowder was very dangerous. People who made gunpowder would sometimes add water, wine, or another liquid to reduce this hazard since a single spark could result in a smoky fire. Once the serpentine was mixed with a liquid, it could be pushed through a screen to make small pellets, which were then allowed to dry. How Gunpowder Works To summarize, black powder consists of a fuel (charcoal or sugar) and an oxidizer (saltpeter or niter), and sulfur, to allow for a stable reaction. The carbon from the charcoal plus oxygen forms carbon dioxide and energy. The reaction would be slow, like a wood fire, except for the oxidizing agent. Carbon in a fire must draw oxygen from the air. Saltpeter provides extra oxygen. Potassium nitrate, sulfur, and carbon react together to form nitrogen and carbon dioxide gases and potassium sulfide. The expanding gases, nitrogen and carbon dioxide, provide the propelling action. Gunpowder tends to produce a lot of smoke, which can impair vision on a battlefield or reduce the visibility of fireworks. Changing the ratio of the ingredients affects the rate at which the gunpowder burns and the amount of smoke that is produced. Difference Between Gunpowder and Black Powder While black powder and traditional gunpowder may both be used in firearms, the term black powder was introduced in the late 19th century in the United States to distinguish newer formulations from traditional gunpowder. Black powder produces less smoke than the original gunpowder formula. Its worth noting early black powder was actually off-white or tan in color, not black! Charcoal Versus Carbon in Gunpowder Pure amorphous carbon is not used in black powder. Charcoal, while it contains carbon, also contains cellulose from incomplete combustion of wood. This gives charcoal a relatively low ignition temperature. Black powder made from pure carbon would barely burn. Gunpowder Composition There is no single recipe for gunpowder. This is because varying the ratio of the ingredients produces different effects. Powder used in firearms needs to burn at a fast rate to quickly accelerate a projectile. A formulation used as a rocket propellant, on the other hand, needs to burn more slowly because it accelerates a body over a long period of time. Cannon, like rockets, use a powder with a slower burn rate. In 1879, the French prepared gunpowder using 75% saltpeter, 12.5% sulfur, and 12.5% charcoal. The same year, the English used gunpowder made from 75% saltpeter, 15% charcoal, and 10% sulfur. One rocket formula consisted of 62.4% saltpeter, 23.2% charcoal, and 14.4% sulfur. Gunpowder Invention Historians believe gunpowder originated in China. Originally, it was used as an incendiary. Later, it found use as a propellant and explosive. It remains unclear when, exactly, gunpowder made its way to Europe. Basically, this is because records describing the use of gunpowder are difficult to interpret. A weapon that produced smoke might have used gunpowder or could have used some other formulation. The formulas that came into use in Europe closely matched those used in China, suggesting the technology was introduced after it had already been developed. Sources Agrawal, Jai Prakash (2010). High Energy Materials: Propellants, Explosives and Pyrotechnics. Wiley-VCH.Andrade, Tonio (2016). The Gunpowder Age: China, Military Innovation, and the Rise of the West in World History. Princeton University Press. ISBN 978-0-691-13597-7.Ashford, Bob (2016). A New Interpretation of the Historical Data on the Gunpowder Industry in Devon and Cornwall.à J. Trevithick Soc.à 43: 65ââ¬â73.Partington, J.R. (1999). A History of Greek Fire and Gunpowder. Baltimore: Johns Hopkins University Press. ISBN 978-0-8018-5954-0.Urbanski, Tadeusz (1967),à Chemistry and Technology of Explosives,à III. New York: Pergamon Press.
Subscribe to:
Comments (Atom)