The Delphi Cookbook
- Content: What will you get from it?
It’s always a pleasure to see a new book come out about technology you work with, especially when that book is not aimed solely at existing developers but is accessible and helpful for those new to the development environment as well. About a month ago, Packt Publishing posted on Google+ asking for expressions of interest to review their new book.
Disclosure: I was given a free copy of the ebook version of Delphi Cookbook in order to write this review. While reviewing, I noticed one of my open-source libraries is recommended in the book. I have no other relationship with either Packt Publishing or the book’s author, Daniele Teti.
A very short version of this review is published on Amazon.
- Delphi Cookbook page on Packt Publishing
- Delphi Cookbook on Amazon
- The author (Daniele Teti)’s website
When reading about a technical book, there are a number of things I want to know:
- Who is it for? Am I going to find it interesting and/or useful?
- What does it cover?
- What is the quality of the code? If I follow the book, will I write decent code or use decent techniques?
- Is it thorough? If I was an expert on one area in the book, what criticisms would I have?
- Is it worth buying?
This reviews attempts to answer those questions. If you don’t want to read the whole thing, the answer to the question ‘is it a good book?’ is yes.
Content: What will you get from it?
The book is styled as a ‘cookbook’; that is, a series of recipes for achieving a number of different tasks. Rather than discussing technologies, being a technical reference for library functions, a language reference, etc, it aims to do two things:
- Show you how to do things you might not know how to do. These vary from common-place to complex / technical.
- Be a starting point for learning more
A book of recipes
The recipe style means that the book is divided into ‘how to do’ a wide number of things. Each of these has a brief introduction, and then rather than discussing the concepts it gives you a step by step (literally, steps are usually numbered and a sentence or two long, although that format isn’t kept for all recipes) walkthrough of one way to do it. These are then followed by an explanation of what the steps / code do, and further information – where to go next and what you should learn about.
In many cases, information is introduced and then reappears in a more complex form in a later section – for example, JSON is introduced in the Delphi Basics section, and reappears in the chapter covering web services in two more complex and in-depth examples interacting with datasets and RTTI. Or, owner-drawing is introduced early on, and then the equivalent (altering styles) for FMX is shown in the FMX chapter.
The book is divided into seven chapters:
- ‘Delphi Basics’: this covers a mix of UI and technical material: owner-drawing in the VCL, JSON, XML, streams, etc.
- ‘Become a Delphi Language Ninja’: this covers the Object Pascal language itself: anonymous methods, writing enumerable types and enumerators (so you can use for..in syntax), RTTI, class helpers, etc.
- ‘Going Cross Platform with FireMonkey’: this covers styles, animations, LiveBindings, paths, and mixing FMX with the VCL
- ‘The Thousand Faces of Multithreading’: this covers TMonitor, TEvent (and multiple events) and a threadsafe queue, and then an example of a threadsafe oscilloscope
- ‘Riding the Mobile Revolution with FireMonkey’: searching a listview, SQLlite, photos, etc.
- ‘Using Specific Platform Features’: using Android and iOS native libraries, and then examples using a couple of those, including Android Intents.
It covers a wide variety of topics, and uses modern Delphi – it focuses a lot on what you can get out of FireMonkey, and covers using it on different platforms. Threading is promoted. The language itself, and useful and modern parts of it, is covered. Reading through the book, it feels even wider in scope than these seven chapter names indicate.
One important thing is the breadth of topics covered in each chapter. Many of the examples cover interesting subjects that are as worthwhile in their own right as the subject they are supposed to demonstrate it: anonymous methods are used in the context of a simple map/reduce framework using generics (the capability of which I haven’t examined, but I like its choice as an example.) Enumerable types shows how to enumerate over all lines of text in a file. The JSON/dataset example uses a subproject in the author’s own DelphiMVCFramework. The example on using UDP on a local network sends configuration options to a (simple) client database program. The first FMX mobile app takes photos and applies effects, creating a mini-Instagram. The Android text-to-speech program pronounces text sent by a VCL app over the local network.
The point is that focusing on the topic names alone gives a very small view of the material – the author has chosen great examples that sometimes do a lot more than the titles indicate, and the book covers a lot more material than it appears to judged on chapter titles alone. These recipes are fantastic, and their choice and the extra things they do is a significant strength of the cookbook.
Initial impressions from the first chapter
The very first recipe in the first chapter (‘Delphi Basics’) involves changing VCL styles, followed by two on owner-drawing controls. These make the book seem like its material is more superficial (UI / looks only) than it really is. When you’re familiar with owner-drawing, the overview of the topic will seem light, especially for the TListBox section. A TListBox can have some complex ownerdraw cases, which aren’t mentioned at all, even in the discussion. The next example is ‘a stack of Delphi forms’ and is particularly odd; what this really means is creating a tabbed interface like a web browser (which is not a stack, it’s tabs, nor should it be implemented as a data-type-stack since tab access is random, so I’m not sure why it’s called a stack.) However, a lot of subsequent material is fantastic, so don’t let this put you off.
This first half of the first chapter lets it down; as a first impression it should be improved. In fact, this is the main reason I mention my first impressions – if you buy the book and start at the start, you may feel let down.
Don’t. Keep reading.
The chapter rapidly gets going into good material and in the same ‘Delphi Basics’ chapter covers JSON manipulation, XML, using streams, and then putting your application in the Windows tray and associating with with a file extension. This mix of both technical (JSON, streams) and UI (system tray) and very specific (file extension association) shows the variety of things the book covers – it is a scattershot of useful information, covering concepts and then specific useful things you may want to do.
Two typical recipes
Here are two typical recipes from a randomly chosen location in the book, one simple and one complex.
Simple: Making a phone call from your app
The screenshot to the right gives a good overview of what to expect from a simple recipe. A few words of introduction mentioning why you might do something and what is possible, and then straight into a numbered set of steps. These are each a sentence long (except where including code, which can often be several lines long) and following them will give you an entire new application. This particular recipe is ten steps long, with steps 6-9 being code (about three pages’ worth rendering in iBooks, probably forty lines. This is split over FormCreate, adding items to a list box, and then a few event handlers to handle phone call states, and an OnClick event to actually make a phone call.)
At the end is a paragraph explaining how it works, and then a There’s more… section explaining what to read up on or look into next. Each is very brief, one paragraph. It is a very simple recipe (obviously I haven’t included a screenshot of the code, but it’s basic) and the book had not much to say. It’s a simple topic, but also a useful one to have a good example of.
Complex: Tracking the application’s life cycle
The very next recipe in the book is far more complex, and discusses a mobile application’s life cycle. Here’s a screenshot of the first page:
You can see a good discussion at the start explaining why it’s important, and it covers it from the perspective of someone aware of Windows development, showing something you need to know for mobile development. It’s clear, concise, and quite comprehensive.
The recipe itself is eight pages long (formatted as in the screenshots in iBooks) and includes code, an explanatory table of different event types and what they mean, an example of output when the application runs, and instructions on specific things to do or try with the app that show important aspects. Obviously, I can’t include screenshots of the entire recipe, but the impression it gives is of something in-depth, well written, researched, and which shows you important things you need to know. It’s great stuff.
Post-recipe discussion (the ‘what’s next’ sections)
After an example, the book always gives you information about things you should know and should learn about. Given most recipes are instructions for how to do something, the discussion afterwards is often the most interesting part of each section. The post-recipe info for the ‘stack of forms’ example is several pages long and mentions a design pattern to know about (Observer pattern), a messaging framework built into the RTL (System.Messaging.TMessageManager), and so forth. The amount of material it points you to is large, and of high quality – ie if you’re a coder who needs to know more, following the references will point you in the right direction.
However, some references in the post-recipe discussions are annoying light, and this is the book’s main weakness.
Weakness in coverage
One example is the discussion after mixing FMX and VCL in the one application, where the recipe, putting FMX forms in a DLL, is followed by a linkdump of libraries. Specifically, four dot points. Those four dot points (one of which is a link to my own TFireMonkeyContainer, which is why I picked this example since I have a sense of what the book should say) mention nothing about what each is, what it does, or why you might want to investigate it. Yet each is worthwhile and applicable for different projects and in different situations, which could be summarised quite well with a single sentence each – but isn’t. If I knew nothing about what each of the four is, I wouldn’t know where to start with them. A single sentence each would have solved this.
I got this sense a bit in the book: I really appreciate the examples it gives and the breadth of topics it covers. I understand it’s not a reference book and the material it points you to is something you need to follow up yourself. But for some of the recipes I really think a few more words of explanation – not to reference level, just a sentence or two more, to explain why you need to know what you need to know, or context about what you need to know, or something – would add a lot to both some of the examples and to some of the references it points you to. Many of the recipes have this, and when they do, it’s great. The choice would have been a hard editorial decision, and I can see why some of it is omitted, but adding it would improve the book.
Breadth of coverage
Consider the discussion of streams: a lot of time is spent on stream readers or writers, and the book mentions the importance of knowing the right text encoding when reading text (and this is an example of it being up to date and living in the modern Unicode world.) I would have appreciated more discussion about how to handle text encoding, and also about other types of streams: file streams, memory streams, etc, which simply aren’t mentioned in that section, though they are used in others. Paradoxically, the end effect is actually of wide coverage, but that you need to read the entire book to be aware of everything it covers even on one specific topic.
However, many of the post-recipe discussions do contain a lot of useful pointers.
Many of the examples, especially later in the book, are lengthy and address real-world problems. For example, one FMX mobile client is a front-end for a RESTful service, is non-blocking, uses LiveBindings, and so covers a wide variety of material in one example. This is not unusual.
Because of this recipe approach, showing one or perhaps two common tasks in a wide variety of areas, as steps (although with discussion), it is hard to describe how thorough this book is.
In terms of an overview of what you might want to do with Delphi, it is thorough. While reading, several times I thought of basic things I hoped would be addressed (‘Will it cover FMX styles?’ ‘Will it cover JSON?’ ‘What about using native iOS libraries?’) and for each of these bar one (see below), which I noted down as a thought of them, the book later turned out to cover those topics.
In terms of coverage of each individual topic, it cannot be thorough with its approach, and it doesn’t try or pretend to be. It covers a useful example for each topic – and it is spot-on with the examples it gives, they really are things you will need to do – and gives references for where to go next. It does this well.
I was often surprised by how interesting the examples were. The book covers a lot more material than the chapter titles make it appear, simply because many of the examples demonstrate more than the one topic they are filed under. In that sense, the book is wide-ranging and interesting.
For example, would you expect an example of Android text-to-speech to include an example of UDP communication from a VCL app? There is a lot of stuff in this book.
The book doesn’t waste time. It treats the reader as intelligent and interested, assumes you’re an enquiring reader, and writes briefly, and this is a good approach. It shows you an example of using something and lets you see, by demonstration, how useful it is. I really like the tone and the way it treats the reader.
The book comes with a complete source download for all recipes – some is too long to be printed in whole in the book.
Unfortunately I haven’t had time to do more than skim much of the code. However, it looked good quality, well laid out, and done the Right Way (it looked clean, organised, and included things I look for when judging if Delphi code is good quality.) They are short and written to demonstrate particular things, so don’t put them directly into production.
Some small but odd things I noticed:
- AppMethod is mentioned exactly once, in the context of the FMX framework. This is puzzling, because the vast majority of the book is equally applicable to AppMethod.
- The language is consistently referred to as Delphi, not Object Pascal (which is what the official name of the language is as of 2014.) Again puzzling, especially since had it been broadened to Delphi and AppMethod, the book’s audience would presumably be wider. I’m sure Embarcadero would have liked to see a book published on AppMethod too.
- Source code is oddly formatted. All Delphi keywords are in a serif font, while the rest of the source is blue Courier New.
- The epub version of the book doesn’t contain author metadata (something I emailed the publisher about a while ago and they promised they’d fix.)
These are all minor, of course.
There is no mention of Spring4D at all. In a book giving examples of modern Delphi usage (and including anonymous methods, generics, etc) missing mentioning the Spring library even in a footnote is strange. Even if the topic of dependency injection is out of scope for the book – and I don’t think it is, I think a good, clear example of DI would make a great chapter – at least mentioning the library, plus its collections library (in the context of interfaces, generics and anonymous methods, at least) seems an obvious topic. I’m puzzled why it’s not there.
On the face of it, the recipe approach may make it seem a beginner’s book: surely if you have been using a platform like Delphi for some time, you already know how to do whatever you want to do?
For those who are new to Delphi or AppMethod it will be an excellent book to learn basic fundamentals: if you need to “learn Delphi” and get a grasp of its many parts, this book will show you a scattershot of a vast number of things and you’ll have both a conceptual overview of what’s possible, and knowledge about how to do it; if you are new to the platform and your boss wants you to do something basic (but not necessarily simple if you don’t already know how to do it), from changing how an application looks or a control draws, to writing a RESTful server, to using the native iOS or Android libraries, this book will show you how. In other words, for those who are new to Delphi, the recipe approach is a quick, concise way of covering a lot of material in a lot of areas of what Delphi provides.
In many cases the examples use modern styles or libraries, and the references are to the ‘right way’ of coding – it will mention specific patterns, etc. This is good, and you could do far worse than learn from the book’s references.
What about those who have used Delphi for many years? I believe there are two other categories of Delphi programmers, apart from those new to the language:
- Those with an excellent up-to-date knowledge, but – because Delphi and its capabilities are huge, and we are human – do not know everything in detail
- Those who have used Delphi for years, and use it as though it was the product it was ten years ago
I put myself in the first dot-point category. I’ve used Delphi since the Turbo Pascal days, and know it pretty well. But I’m not familiar with using it to write web servers, REST communication, or databases – things some people would regard as ‘core Delphi’. My background is in scientific programming (and other languages like C++), big data, algorithms, data processing, UI design and ergonomics, raw Win32, custom components and use of the VCL and FMX, multithreading, etc. That’s a wide number of areas, and I certainly have the background to learn anything I need to know – and I think regardless of what areas you know in-depth, this describes many coders: few of us know every single thing there is to know about every single area, but we can learn what we need to. So with that basis, did I learn anything from this book? Yes. And, will I find it useful as a reference for when I want to know where to go to learn more about those topics? Yes.
Normally, you’d have a hard sell to convince me I would need to buy a book in order to do so, because it’s not what you expect to do in 2014, the age of blogs and Stack Overflow. I will say that having read it, the examples are much higher quality than a lot of material online; while you won’t get anything other than an overview of any topic you need to know about, given in the form of an example plus a small discussion, that overview may be more accurate or of higher quality or easier to use as a basis than someone’s answer on Stack Overflow. The recipes cover an amazing variety of things. There is no way you won’t find something new for you in here. Now I have the book, I will certainly be revisiting it, because of how interesting much of the material is.
The second category are those who have used Delphi for many years, but for a variety of reasons haven’t been able to stay up to date. There are many valid reasons for this, and I’ve met people whose company doesn’t promote or buy them updated versions of Delphi; people who don’t know what’s in new Delphi, or don’t see why what’s new is great and worth using; and people who know but simply haven’t seen the need to use newer versions. The reason this book is an excellent resource for this group of Delphi programmers is that it covers modern Delphi: the Delphi in this book is one with both the VCL and FMX; a language with anonymous methods, generics and good support for multithreading; and a platform useful for writing apps for Windows, servers, and mobile devices. If you’re one of this group of coders, the Delphi you will see presented by this book is a different Delphi to the one you may be familiar with. It will be illuminating, in the way that revisiting a country you haven’t been to for many years gives you a different view of the place and people. It would be a great book to buy.
Value proposition for different audiences
- Those new to Delphi or AppMethod: it will show you a scattershot of a wide variety of things. Worth buying? Yes.
- You’ll use it to learn about the platform, and get an overview of what it can do
- Remember that the examples are well chosen. The things it shows how to do are things you will need to do. Some of them are outright just plain interesting. It will be useful.
- Those up to date in Delphi: it will give example of things you may not be familiar with. Worth buying? That’s a trickier question. If there are areas it covers and you want a high-quality basis for it (you know nothing about web services and want to see a modern example, to start off right), then yes. I think it’s especially worth it from the wide scope of the material and the examples.
- Those not up to date in Delphi: it will give you an illuminating view of modern Delphi. Worth buying? Yes. Read it through.
- Amazingly wide material
- Recipes are fantastic: both real-world, useable examples (if you need to do something, a great start) and often cover much more than you’d expect. Consistently interesting.
- Delphi coders from any background will learn something
- Discussion after some recipes for where to go next is sometimes lighter than it should be
- Code formatting isn’t great, and the first half of the first chapter gives a weaker first impression than the book deserves
- Delphi Cookbook page on Packt Publishing
- Delphi Cookbook on Amazon
You must log in to post a comment.