Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Tech Guides - Languages

34 Articles
article-image-brief-history-python
Sam Wood
14 Oct 2015
4 min read
Save for later

A Brief History of Python

Sam Wood
14 Oct 2015
4 min read
From data to web development, Python has come to stand as one of the most important and most popular open source programming languages being used today. But whilst some see it as almost a new kid on the block, Python is actually older than both Java, R, and JavaScript. So what are the origins of our favorite open source language? In the beginning... Python's origins lie way back in distant December 1989, making it the same age as Taylor Swift. Created by Guido van Rossum (the Python community's Benevolent Dictator for Life) as a hobby project to work on during week around Christmas, Python is famously named not after the constrictor snake but rather the British comedy troupe Monty Python's Flying Circus. (We're quite thankful for this at Packt - we have no idea what we'd put on the cover if we had to pick for 'Monty' programming books!) Python was born out of the ABC language, a terminated project of the Dutch CWI research institute that van Rossum worked for, and the Amoeba distributed operating system. When Amoeba needed a scripting language, van Rossum created Python. One of the principle strengths of this new language was how easy it was to extend, and its support for multiple platforms - a vital innovation in the days of the first personal computers. Capable of communicating with libraries and differing file formats, Python quickly took off. Computer Programming for Everybody Python grew throughout the early nineties, acquiring lambda, reduce(), filter() and map() functional programming tools (supposedly courtesy of a Lisp hacker who missed them and thus submitted working patches), key word arguments, and built in support for complex numbers. During this period, Python also served a central role in van Rossum's Computer Programming for Everybody initiative. The CP4E's goal was to make programming more accessible to the 'layman' and encourage a basic level of coding literacy as an equal essential knowledge alongside English literacy and math skills. Because of Python's focus on clean syntax and accessibility, it played a key part in this. Although CP4E is now inactive, learning Python remains easy and Python is one of the most common languages that new would-be programmers are pointed at to learn. Going Open with 2.0 As Python grew in the nineties, one of the key issues in uptake was its continued dependence on van Rossum. 'What if Guido was hit by a bus?' Python users lamented, 'or if he dropped dead of exhaustion or if he is rubbed out by a member of a rival language following?' In 2000, Python 2.0 was released by the BeOpen Python Labs team. The ethos of 2.0 was very much more open and community oriented in its development process, with much greater transparency. Python moved its repository to SourceForge, granting write access to its CVS tree more people and an easy way to report bugs and submit patches. As the release notes stated, 'the most important change in Python 2.0 may not be to the code at all, but to how Python is developed'. Python 2.7 is still used today - and will be supported until 2020. But the word from development is clear - there will be no 2.8. Instead, support remains focused upon 2.7's usurping younger brother - Python 3. The Rise of Python 3 In 2008, Python 3 was released on an almost-unthinkable premise - a complete overhaul of the language, with no backwards compatibility. The decision was controversial, and born in part of the desire to clean house on Python. There was a great emphasis on removing duplicative constructs and modules, to ensure that in Python 3 there was one - and only one - obvious way of doing things. Despite the introduction of tools such as '2to3' that could identify quickly what would need to be changed in Python 2 code to make it work in Python 3, many users stuck with their classic codebases. Even today, there is no assumption that Python programmers will be working with Python 3. Despite flame wars raging across the Python community, Python 3's future ascendancy was something of an inevitability. Python 2 remains a supported language (for now). But as much as it may still be the default choice of Python, Python 3 is the language's future. The Future Python's userbase is vast and growing - it's not going away any time soon. Utilized by the likes of Nokia, Google, and even NASA for it's easy syntax, it looks to have a bright future ahead of it supported by a huge community of OS developers. Its support of multiple programming paradigms, including object-oriented Python programming, functional Python programming, and parallel programming models makes it a highly adaptive choice - and its uptake keeps growing.
Read more
  • 0
  • 0
  • 12177

article-image-pythons-new-asynchronous-statements-and-expressions
Daniel Arbuckle
12 Oct 2015
5 min read
Save for later

Python’s new asynchronous statements and expressions

Daniel Arbuckle
12 Oct 2015
5 min read
As part of Packt’s Python Week, Daniel Arbuckle, author of our Mastering Python video, explains Python’s journey from generators, to schedulers, to cooperative multithreading and beyond…. My romance with cooperative multithreading in Python began in the December of 2001, with the release of Python version 2.2. That version of Python contained a fascinating new feature: generators. Fourteen years later, generators are old hat to Python programmers, but at the time, they represented a big conceptual improvement. While I was playing with generators, I noticed that they were in essence first-class objects that represented both the code and state of a function call. On top of that, the code could pause an execution and then later resume it. That meant that generators were practically coroutines! I immediately set out to write a scheduler to execute generators as lightweight threads. I wasn’t the only one! While the schedulers that I and others wrote worked, there were some significant limitations imposed on them by the language. For example, back then generators didn’t have a send() method, so it was necessary to come up with some other way of getting data from one generator to another. My scheduler got set aside in favor of more productive projects. Fortunately, that’s not where the story ends. With Python 2.5, Guido van Rossum and Phillip J. Eby added the send() method to generators, turned yield into an expression (it had been a statement before), and made several other changes that made it easier and more practical to treat generators as coroutines, and combine them into cooperatively scheduled threads. Python 3.3 was changed to include yield from expressions, which didn’t make much of a difference to end users of cooperative coroutine scheduling, but made the internals of the schedulers dramatically simpler. The next step in the story is Python 3.4, which included the asyncio coroutine scheduler and asynchronous I/O package in the Python standard library. Cooperative multithreading wasn’t just a clever trick anymore. It was a tool in everyone’s box. All of which brings us to the present, and the recent release of Python 3.5, which includes an explicit coroutine type, distinct from generators, new asynchronous async def, async for, and async with statements, and an await expression that takes the place of yield from for coroutines. So, why does Python need explicit coroutines and new syntax, if generator-based coroutines had gotten good enough for inclusion in the standard library? The short answer is that generators are primarily for iteration, so using them for something else — no matter how well it works conceptually — introduces ambiguities. For example, if you hand a generator to Python’s for loop, it’s not going to treat it as a coroutine, it’s going to treat it as an iterable. There’s another problem, related to Python’s special protocol methods, such as __enter__ and __exit__, which are called by the code in the Python interpreter, leaving the programmer with no opportunity to yield from it. That meant that generator-based coroutines were not compatible with various important bits of Python syntax, such as the with statement. A coroutine couldn’t be called from anything that was called by a special method, whether directly or indirectly, nor was it possible to wait on a future value. The new changes to Python are meant to address these problems. So, what exactly are these changes? async def is used to define a coroutine. Apart from the async keyword, the syntax is almost identical to a normal def statement. The big differences are, first, that coroutines can contain await, async for, and async with syntaxes, and, second, they are not generators, so they’re not allowed to contain yield or yield from expressions. It’s impossible for a single function to be both a generator and a coroutine. await is used to pause the current coroutine until the requested coroutine returns. In other words, an await expression is just like a function call, except that the called function can pause, allowing the scheduler to run some other thread for a while. If you try to use an await expression outside of an async def, Python will raise a SyntaxError. async with is used to interface with an asynchronous context manager, which is just like a normal context manager except that instead of __enter__ and __exit__ methods, it has __aenter__ and __aexit__ coroutine methods. Because they’re coroutines, these methods can do things like wait for data to come in over the network, without blocking the whole program. async for is used to get data from an asynchronous iterable. Asynchronous iterables have an __aiter__ coroutine method, which functions like the normal __iter__ method, but can participate in coroutine scheduling and asynchronous I/O. __aiter__ should return an object with an __anext__ coroutine method, which can participate in coroutine scheduling and asynchronous I/O before returning the next iterated value, or raising StopAsyncIteration. This is Python, all of these new features, and the convenience they represent, are 100% compatible with the existing asyncio scheduler. Further, as long as you use the @asyncio.coroutine decorator, your existing asyncio code is also forward compatible with these features without any overhead.
Read more
  • 0
  • 0
  • 1034

article-image-new-languages-brave-new-world
Akram Hussain
26 Sep 2014
6 min read
Save for later

New Languages: Brave New World

Akram Hussain
26 Sep 2014
6 min read
The tech world has seen a number of languages emerge, grow, and become super popular, but equally it has seen its fair share of failures and things that make you ask yourself “just why?” We initially had the dominant set of languages introduced to us many years ago (in the 80s), which are still popular and widely used; these include C++, C, Fortran, Erlang, Pearl, SQL, Objective C, and so on. There is nothing to suggest these languages will die out completely or even lose their market share, but the world of programming really came to life in the 90s in an era known as the “Internet age” where a new set of languages came to the party. During this period, a set of “special” languages emerged and I personally would go as far as to say they revolutionized the way we programme. These were languages like JavaScript, Python, Java, R, Haskell, Ruby, and PHP. What’s more interesting is that you see a huge demand for these languages currently on the market (even after 20 years!) and you certainly wouldn’t categorize them as new; so why are they still so popular? Has the tech market stalled? Have developers not moved on? Do we have everything we need from these languages? And what’s next for the future? The following image helps explain the introduction and growth of these languages, in terms of use and adoption; it’s based on Redmonks’ analysis which compares the popularity of Stackoverflow tags and Github repositories: This graph shows a number of languages with the movement from left to right as a positive one. It’s apparent that the languages that were introduced in the 90s are at the forefront of programming; there are even few from the 80s, which supports my earlier statement that older languages don’t die out but seem to improve and adapt over time. However with time and the ever changing tech market, new demands always arise and where there are problems, there are developers with solutions. Recently and over the past few years, we have seen the emergence of new programming languages. Interestingly they seem to be very similar to the older ones, but they have that extra oomph that makes them so popular. I would like to introduce you to a set of languages that may be around for many years to come and may even shape the tech world in the future. Could they be the next generation? Scala is a multi-paradigm programming language supports both object-oriented and functional programming. It is a scripting language used to build applications for the JVM. Scala has seen increased adoption from Java developers due to its flexibility, as it provides the ability to carry out functional programming capabilities. Could Scala replace Java? Go, introduced by Google, is a statically-typed programming language with syntax similar to C. It has been compared and seen as a viable alternative to major languages such as Java or C++. However, Go is different thanks to its inherent support for concurrent programming, where it independently executes tasks, and computations are designed to interact with each other that can be run on a single processor or multi-core processors. Swift is Apple’s new programming language, unveiled in June 2014. It is set to replace Objective-C as the lingua franca for developing apps for Apple operating systems. As a multi-paradigm language, it has expressive features familiar to those used to working with modern functional languages, while also keeping the object-oriented features of Objective-C. F# is a multi-paradigm programming language that encompasses object-oriented features but is predominantly focused on functional programming. F# was developed by Microsoft as an alternative to C#, touted as a language that can do everything C# can but better. The language was primarily designed with the intention of applying it to data-driven concepts. One of the greatest benefits of using F# is the interoperability with other .NET languages. This means code written in F# can work with different parts of an application written in C#.  Elixir  is a functional programming language that leverages features of the Erlang VM and has syntax similar to Ruby. Elixir offers concurrency, high scalability, and fault-tolerance, enabling higher levels of productivity and extensibility while maintaining compatibility with Erlang’s tools and ecosystem.  Clojure is a dynamic, general-purpose programming language that runs on the Java Virtual Machine that offers interactive development with the speed and reliable runtime of the JVM. It takes advantage of Java libraries, services, and all of the resources of the JVM ecosystem. Dart, introduced by Google, is a pure object-oriented language with C-style syntax. Developers look at Dart as a JavaScript competitor that offers simplicity, flexibility, better performance, and security. Dart was designed for web development and to scale complex web applications. Juliais an expressive and dynamic multi-paradigm language. It’s as fast as C and it can be used for general programming. It is supposed to be a high level programming language with syntax similar to Matlab and Fortran. The language is predominantly used in the field of data science, and is one to keep an eye out for as it’s tipped to rival R and Python in the future.   D is another multi-paradigm programming language that allows developers to write “elegant” code. There’s demand for D as it’s a genuine improvement over C++, while still offering all the benefits of C++. D can be seen as a solution for developers who build half their application in Ruby/Python and then use C++ to “deal with the bottle-necks”. D lets you have all the benefits of both of these languages. Rust is another multi-paradigm systems language developed by Mozilla. It has been touted as a valuable alternative to C++. Rust combines strong concurrent programming, low-level abstraction, with super-fast performance, making it ideal for high-level projects. Rust’s type system ensures memory errors are minimized, a problem that is common in C++ with memory leaks. However, for the moment Rust isn’t designed to replace C++ but improve on its flaws, yet with advancements in the future you never know… From this list of new languages, it’s clear that the majority of them were created to solve issues of previous languages. They are all subsets of a similar language, but better refined to meet the modern day developer’s needs. There has been an increase in support for functional languages and there’s also been a steep rise of multi-paradigm features, which suggests the need for flexible programming. Whether we’re looking at the new “class” of languages for the future remains to be seen, but one thing is for sure: they were designed to make a difference in an increasingly new and brave tech world. 
Read more
  • 0
  • 0
  • 2282

article-image-5-go-libraries-frameworks-and-tools-you-need-to-know
Julian Ursell
24 Jul 2014
4 min read
Save for later

5 Go Libraries, Frameworks, and Tools You Need to Know

Julian Ursell
24 Jul 2014
4 min read
Golang is an exciting new language seeing rapid adoption in an increasing number of high profile domains. Its flexibility, simplicity, and performance makes it an attractive option for fields as diverse as web development, networking, cloud computing, and DevOps. Here are five great tools in the thriving ecosystem of Go libraries and frameworks. Martini Martini is a web framework that touts itself as “classy web development”, offering neat, simplified web application development. It serves static files out of the box, injects existing services in the Go ecosystem smoothly, and is tightly compatible with the HTTP package in the native Go library. Its modular structure and support for dependency injection allows developers to add and remove functionality with ease, and makes for extremely lightweight development. Out of all the web frameworks to appear in the community, Martini has made the biggest splash, and has already amassed a huge following of enthusiastic developers. Gorilla Gorilla is a toolkit for web development with Golang and offers several packages to implement all kinds of web functionality, including URL routing, optionality for cookie and filesystem sessions, and even an implementation with the WebSockets protocol, integrating it tightly with important web development standards. groupcache groupcache is a caching library developed as an alternative (or replacement) to memcached, unique to the Go language, which offers lightning fast data access. It allows developers managing data access requests to vastly improve retrieval time by designating a group of its own peers to distribute cached data. Whereas memcached is prone to producing an overload of database loads from clients, groupcache enables a successful load out of a huge queue of replicated processes to be multiplexed out to all waiting clients. Libraries such as Groupcache have a great value in the Big Data space as they contribute greatly to the capacity to deliver data in real time anywhere in the world, while minimizing potential access pitfalls associated with managing huge volumes of stored data. Doozer Doozer is another excellent tool in the sphere of system and network administration which provides a highly available data store used for the coordination of distributed servers. It performs a similar function to coordination technologies such as ZooKeeper, and allows critical data and configurations to be shared seamlessly and in real time across multiple machines in distributed systems. Doozer allows the maintenance of consistent updates about the status of a system across clusters of physical machines, creating visibility about the role each machine plays and coordinating strategies for failover situations. Technologies like Doozer emphasize how effective the Go language is for developing valuable tools which alleviate complex problems within the realm of distributed system programming and Big Data, where enterprise infrastructures are modeled around the ability to store, harness and protect mission critical information.  GoLearn GoLearn is a new library that enables basic machine learning methods. It currently features several fundamental methods and algorithms, including neural networks, K-Means clustering, naïve Bayesian classification, and linear, multivariate, and logistic regressions. The library is still in development, as are the number of standard packages being written to give Go programmers the ability to develop machine learning applications in the language, such as mlgo, bayesian, probab, and neural-go. Go’s continual expansion into new technological spaces such as machine learning demonstrates how powerful the language is for a variety of different use cases and that the community of Go programmers is starting to generate the kind of development drive seen in other popular general purpose languages like Python. While libraries and packages are predominantly appearing for web development, we can see support growing for data intensive tasks and in the Big Data space. Adoption is already skyrocketing, and the next 3 years will be fascinating to observe as Golang is poised to conquer more and more key territories in the world of technology.
Read more
  • 0
  • 0
  • 2521
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime
Banner background image