Optimizing Visual Studio Code for Python Development: Developing More Efficient and Effective Programs in Python 1st Edition Sufyan Bin Uzayr - Download the ebook now for the best reading experience
Optimizing Visual Studio Code for Python Development: Developing More Efficient and Effective Programs in Python 1st Edition Sufyan Bin Uzayr - Download the ebook now for the best reading experience
com
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/mastering-visual-studio-code-a-
beginners-guide-1st-edition-sufyan-bin-uzayr/
ebookmeta.com
https://ebookmeta.com/product/visual-studio-code-for-python-
programmers-1st-edition-april-speight/
ebookmeta.com
https://ebookmeta.com/product/mastering-python-for-web-a-beginners-
guide-mastering-computer-science-1st-edition-sufyan-bin-uzayr/
ebookmeta.com
https://ebookmeta.com/product/mousetrap-structure-and-meaning-in-
hamlet-1st-edition-p-j-aldus/
ebookmeta.com
The Art Book First Edition Georgina Palffy Sam Atkinson
https://ebookmeta.com/product/the-art-book-first-edition-georgina-
palffy-sam-atkinson/
ebookmeta.com
https://ebookmeta.com/product/who-owns-haiti-people-power-and-
sovereignty-1st-edition-robert-maguire/
ebookmeta.com
https://ebookmeta.com/product/storey-s-guide-to-raising-pigs-care-
facilities-management-breeds-4th-edition-kelly-klober/
ebookmeta.com
https://ebookmeta.com/product/efficient-mysql-performance-final-
release-1st-edition-daniel-nichter/
ebookmeta.com
Sufyan bin Uzayr
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
Chapters at a Glance
Chapter 1, “Introduction to Visual Studio Code,” reviews how to set up
VS Code as well as provide an overview of the basic features, such as:
User interface: Provides the view of the documentation for VS Code.
Setup overview: Analyzes documentation for starting up and
running with VS Code, including platform-related setup.
Keyboard shortcuts: Provides customization options for your own
shortcuts and installation of Keymap extensions.
Keybinding extensions: Covers how to install a Keymap extension
and how to bring the keybindings from other editors to VS Code.
Chapter 2, “Getting Started with Python Programs in Visual Studio
Code,” explains in detail how to set up your VS Code for Python
Development. For the sake of demonstrating with examples, you’ll see
how to install most of the tools on Windows.
Chapter 3, “Setting Up the Environment and Testing,” demonstrates
how to install the top 8 Python extensions by typing Python in the
Extensions item on the Activity Bar.
Chapter 4, “Working with Python Frameworks,” discusses using
Python frameworks, such as Django and Flask. We will discuss topics
such as Python web development, Django apps, Flask development, and
so on.
Chapter 5, “Working with Containers and MS Azure,” covers Python
development in VS Code in assonance with MS Azure. Azure services
can be used for speedy deployment and building of production level
apps. With VS Code, Azure offers neat integration and this chapter
discusses the same.
Acknowledgments
There are many people who deserve to be on this page, for this book
would not have come into existence without their support. That said,
some names deserve a special mention, and I am genuinely grateful to:
My mother and father, for everything they have done for me.
Faisal Fareed and Sadaf Fareed, my siblings, for helping with things
back home.
Sana Akhtar Usmani, for all her help and support.
The Parakozm team, especially Madina Karybzhanova, for offering
great amounts of help and assistance during the book-writing
process.
The Apress team, especially Smriti Srivastava, Shrikant Vishwakarma,
and James Markham, for ensuring that the book’s content, layout,
formatting, and everything else remains perfect throughout.
Reviewers of this book, for going through the manuscript and
providing their insight and feedback.
Typesetters, cover designers, printers, and everyone else, for their
part in the development of this book.
All the folks associated with Zeba Academy, either directly or
indirectly, for their help and support.
The Python and VS Code community at large, for all their hard work
and efforts.
Figure 1-1 Visual Studio Code, a free and open-source code editor
In this chapter, we will walk you through setting up VS Code as well as
provide an overview of the basic features:
User interface: viewing the documentation for VS Code.
Setup overview: documentation for starting up and running with VS Code,
including platform-related setup.
Keyboard shortcuts: customization options for your own shortcuts and
installation of Keymap extensions.
Keybinding extensions: how to install a Keymap extension to bring the
keybindings from your previous editor to VS Code.
User Interface
According to the original intent, VS Code is a code editor. Similar to many other
code editors, VS Code has a common user interface and layout of an explorer
on the left, displaying all of the files and folders you have access to, and an
editor on the right, presenting the content of the files you have opened.
Basic Layout
VS Code comes with a straightforward yet intuitive layout that utilizes all the
space provided for the editor, while leaving some room to browse and access
the full context of your folder or the ongoing project. The User Interface is
divided into five main areas:
Editor: The main space for you to edit current files. You can open as many
editors as you need side by side, as well as vertically and horizontally.
SideBar: This area has different views such as the Explorer, to provide a
maximum assistance while you are working on your project.
Status Bar: Information about the current project and the files you are
editing.
Activity Bar: Placed on the far left-hand side, this area enables you to switch
between views and gives you additional context-specific measures—for
instance, the number of outgoing changes.
Panels: You can show different panels below the editor area for output or
debug content, errors, and warnings, or integrated information. The panel
can also be shifted to the right for more vertical space.
Each time you launch VS Code, it opens up in the same state it was in when
you last left it. The folder, layout, and opened files will be preserved the same.
Open files in each editor are displayed with tabbed headers (Tabs) at the top of
the editor region. To learn more information about tabbed headers, see the
details of the Tabs section. You can also move the Sidebar to the right-hand
side (View ➤ Move Side Bar Right) or enhance its visibility (Ctrl+B).
Side-By-Side Editing
As previously mentioned, you can open as many editors as you like side-by-
side vertically as well as horizontally. If you already have one editor open,
there are various ways of placing another editor to the side of the existing one:
Alt-click on a file in the Explorer.
Ctrl+\ to split the active editor into two.
Open to the Side (Ctrl+Enter) from the Explorer context menu on a file.
Click the Split Editor button in the upper right of an editor.
Drag and drop a file to any side of the editor region.
Ctrl+Enter (macOS: Cmd+Enter) in the Quick Open (Ctrl+P) file list.
Once you open another file, the editor that is in progress will display the
content of that file. So if you have two editors side by side and you need to
open file doc.cs into the right-hand editor, make sure that editor is active (by
clicking on it) before opening file doc.cs.
By default, editors are made to open on the right-hand side of the active
one. You can change this pattern through the setting
workbench.editor.openSideBySideDirection and modify to open new editors to
the bottom of the active one instead. At the same time, when you have more
than one editor active, you can switch between them easily by holding the Ctrl
(macOS: Cmd) key and pressing 1, 2, and 3. In addition, you can resize editors
and reorder them if you would like to: simply drag and drop the editor title
area to reposition or resize the editor.
Minimap
A Minimap (code outline) allows you to get a high-level overview of your
source code, which is quite useful for easy navigation and code
comprehension. A file’s minimap is displayed on the right side of the editor.
You can also click or drag the shaded area to quickly switch to different
sections of your file. It is also worth noting that you can move the minimap to
the left-hand side or even disable it completely by simply setting
“editor.minimap.side”:, “left”, or “editor.minimap.enabled”: false in your user or
workspace settings.
Indent Guides
The image above the editor also shows vertical lines or indentation guides that
are there to help you freely observe matching indent levels. If you would like to
turn off those indent guides, you should set “editor.renderIndentGuides”: false
in your user or workspace settings.
Breadcrumbs
If you take a look at the editor once again, you will notice it has a navigation
bar above its contents that is named Breadcrumbs. It is there to show your
current location and let you quickly navigate between folders, files, and
symbols.
Breadcrumbs also tend to display the file path, and if the active file type has
language support for symbols, it displays the symbol path up to the cursor
position. You can switch off Breadcrumbs with the View ➤ Show Breadcrumbs
simple command. You can also access the same information about the
Breadcrumbs feature at the Breadcrumbs section of the editor.
Explorer
The Explorer is a tool used to browse, open, and operate all of the files and
folders in your editing project. Since VS Code is file- and folder-based, you can
get started at any time simply by opening a file or folder in VS Code. Once you
open a folder in VS Code, the contents of the folder are shown in the Explorer.
You can do many modifications from here, such as:
Create, delete, and rename files and folders.
Change the location of files and folders by using drag and drop.
See the context menu to see all options.
Moreover, you can drag and drop files into the Explorer from outside VS
Code to make a VS copy of them, so that if the explorer is empty, VS Code will
access them instead.
VS Code also works very well with other tools that you might use,
especially command-line tools. If you need to run a command-line tool in the
context of the folder you have open in VS Code, right-click the folder and select
Open in Command Prompt (or Open in Terminal on macOS or Linux).
At the same time, you can navigate to the location of a file or folder in the
native Explorer by right-clicking on a file or folder and selecting Reveal in
Explorer (or Reveal in Finder on macOS, or Open Containing Folder on Linux).
You may also type Ctrl+P (Quick Open option) to quickly search and open a file
by its name.
By default, VS Code does not open some folders from the Explorer (for
example, .git). In this case, you can use the files.exclude setting to edit rules for
hiding files and folders from the Explorer. However, if you have any derived
resource files, such as \*.meta in Unity or \*.js in a TypeScript project, then
this solution is not really going to be useful. Please note that for Unity to
exclude the \*.cs.metafiles, the pattern to select would be “**/*.cs.meta”: true.
For TypeScript, you can exclude generated JavaScript for TypeScript files with
“**/*.js”: {“when”: “$(basename).ts”}.
Multiselection
You can choose multiple files in the File Explorer and OPEN EDITORS view to
complete actions (Delete, Drag and Drop, Open to the Side) on multiple items.
Simply use the Ctrl/Cmd key with a click to select individual files and Shift +
click to select a range. If you select two items, you can now use the context
menu Compare Selected command to quickly differentiate the two files. Also,
remember that in earlier VS Code releases, clicking with the Ctrl/Cmd key
pressed would open a file in a new Editor Group to the side. If you would still
like this feature, you can use the workbench.list.multiSelectModifier setting to
modify multiselection to use the Alt key by
“workbench.list.multiSelectModifier”: “alt”.
Outline View
The Outline view is a section at the bottom of the File Explorer. When
activated, it will show the symbol tree of the currently active editor. The
Outline view has different Sort By modes and optional cursor tracking, and
supports the usual open gestures. It also has an input box that can search for
filters and symbols as you type. Errors and warnings are also displayed in the
Outline view, allowing you to see a glimpse of a problem as well as its location.
As for symbols, the view relies heavily on the data computed by your
installed extensions for different file types. For instance, the built-in
Markdown support returns the Markdown header hierarchy for a Markdown
file’s symbols.
Markdown Outline View
There are a few Outline view settings that allow you to enable and disable
items and operate with errors and warnings display (all enabled by default):1
outline.icons: toggle rendering outline elements with icons.
outline.problems.enabled: shows errors and warnings on outline
elements.
outline.problems.badges: toggle using badges for errors and warnings.
outline.problems.colors: toggle using colors for errors and warnings.
Open Editors
At the top of the Explorer, there is a section labeled as OPEN EDITORS that
displays a list of active files or previews. There might also be some files visible
that you previously opened in VS Code. For example, a file will be listed in the
OPEN EDITORS view if you make a change to a file, double-click a file’s header,
double-click a file in the Explorer, or open a file that is not part of the current
folder. By clicking an item in the OPEN EDITORS view, it becomes active in VS
Code. Once you are finished with your project and wish to remove files
individually from the OPEN EDITORS view, or remove all files, you can do so by
using the View: Close All Editors or View and then Close All Editors in Group
actions.
Views
The File Explorer is just one of the Views available in VS Code. There are also
Views for:2
Search: Provides global search and replace across your open folder.
Source Control: VS Code includes Git source control by default.
Run: VS Code’s Run and Debug View displays variables, call stacks, and
breakpoints.
Extensions: Installs and manages your extensions within VS Code.
Custom views: Views contributed by extensions.
Any of these views can be accessed by using the View: Open View
command.
Activity Bar
The Activity Bar on your left is designed for you to easily switch between
Views. You can also reorder Views by dragging and dropping them on the
Activity Bar, or stow away a View entirely with the right-click Hide from
Activity Bar.
Command Palette
VS Code is also easily accessible from the keyboard. The most useful key
combination to know is Ctrl+Shift+P, which calls for the Command Palette.
With the Command Palette you have access to all of the functionality of VS
Code, including keyboard shortcuts for the most implemented operations. The
Command Palette provides access to many commands. You can manage editor
commands, open files, search for items, and see a quick outline of a file, all
while using the same interactive window. Following are a few navigation
combinations:3
Ctrl+P will let you navigate to any file or symbol by typing its name.
Ctrl+Tab will cycle you through the last set of files opened.
Ctrl+Shift+P will bring you directly to the editor commands.
Ctrl+Shift+O will let you navigate to a specific symbol in a file.
Ctrl+G will let you navigate to a specific line in a file.
Type ? into the input field to get a list of available commands you can
execute from Quick Open Help.
Settings
Most basic editor configurations are kept in settings that can be modified
directly. You can set options globally through user settings, or per project or
file through workspace settings. Settings options are kept in a settings.json file.
You can follow the path Select File ➤ Preferences ➤ Settings (or press Ctrl+,)
to edit the user settings.json file. To change workspace settings, click the
WORKSPACE SETTINGS tab to edit the workspace settings.json file. Note that
for macOS users, the Preferences menu is located under Code, not File; please
follow Code ➤ Preferences ➤ Settings.
You can access the VS Code Default Settings in the left window, and your
editable settings.json on the right. It is also possible to easily filter settings in
the Default Settings using the search box at the top. You can copy a setting over
to the editable settings.json on the right by clicking on the edit icon to the left
of the setting. Settings with a fixed set of values let you select a primary value
as a section of their edit icon menu. After editing your settings, type Ctrl+S to
settle your changes. The changes will take effect instantly. Workspace settings
will override User settings and are beneficial for sharing particular project
settings.
Zen Mode
Zen mode enables you to focus on your code by removing all User Interface
items (Activity Bar, Status Bar, Side Bar, and Panel) except the editor, displaying
the full screen and centering the editor layout only. Zen mode can be toggled
using the View menu, Command Palette or by the shortcut, Ctrl+K Z. To exit
Zen mode, press double Esc. The transition to full screen can be disabled via
zenMode.fullScreen. Zen mode can be further modified using the following
settings: zenMode.hideStatusBar, zenMode.hideTabs, zenMode.fullScreen,
zenMode.restore, and zenMode.centerLayout.
Tabs
VS Code displays open items with tabbed headings or Tabs in the title area
above the editor. If you open a file, a new Tab is added for that file. Tabs allow
you to quickly navigate between files, and you can drag and drop tabs to
reorder them as you wish. When you have more open items than can fit in the
title area, you can apply the Show Opened Editors command to show a
dropdown list of tabbed items.
If you do not want to use Tabs, you can turn off the feature by setting the
workbench.editor.showTabs setting to false: “workbench.editor.showTabs”:
false.
Tab Ordering
By default, new Tabs are included to the right of the existing Tabs, but you can
administer where you would like new Tabs to appear with the
workbench.editor.openPositioning setting. For instance, you might like new
tabbed items to appear on the left, by using
“workbench.editor.openPositioning”: “left”.
Preview Mode
Once you single-click or select a file in the Explorer, it is shown in a
presentation mode and reuses an existing Tab. This is particularly helpful if
you just need to quickly browse files and do not want each file you accessed to
have its own Tab. When you start editing the file or use double-click to open
the file from the Explorer, a new Tab is assigned to that file. Preview mode is
indicated by italics in the Tab heading: preview mode.
If you would rather not see the preview mode and always make a new Tab,
you can control the pattern with these settings:
workbench.editor.enablePreview: to globally enable or disable preview
editors.
workbench.editor.enablePreviewFromQuickOpen: to enable or disable
preview editors when opened from Quick Open.
Editor Groups
If you split an editor via the Split Editor or Open to the Side commands, a new
editor region that can hold a group of items is created instead. At the same
time, you can open as many editor regions as you like side-by-side vertically
and horizontally. You can see them in order in the OPEN EDITORS section at
the top of the Explorer view. The OPEN EDITORS section also allows you to
Drag and Drop editor groups on the workbench, move individual Tabs between
groups, and quickly close entire groups by clicking on Close All.
Be sure that VS Code uses editor groups whether or not you have any Tabs
on. Without Tabs, editor groups are a stack of your open items with the most
recently searched item visible in the editor pane. By default, editor groups are
structured in vertical columns when you split an editor to open it to the side.
You can also arrange editor groups in any layout you like, both vertically and
horizontally.
In order to support flexible layouts, you should create empty editor groups.
By default, closing the last editor of an editor group will also close the group
itself, but you can modify this behavior with the new setting
workbench.editor.closeEmptyGroups: false. You can also see if there are any
predefined set of editor layouts in the View ➤ Editor Layout menu.
Editors that open to the side by clicking the editor toolbar Split Editor
action will normally open to the right-hand side of the active editor. If you
prefer to open editors below the active one, configure the new setting
workbench.editor.openSideBySideDirection: down.
There are plenty of keyboard commands for adjusting the editor layout
with the keyboard alone, but if you prefer to use the mouse, drag and drop is
the fastest method to split the editor into any direction. In addition, if you
press and hold the Alt key while switching over the toolbar action to split an
editor, it will offer to split to the other orientation. This is another fast way to
split either to the right or to the bottom.
Keyboard Shortcuts
It will also be very beneficial for you to know some handy keyboard shortcuts
to quickly navigate between editors and editor groups. Some of the most
widely used ones are the following:4
Ctrl+PageDown go to the right editor.
Ctrl+PageUp go to the left editor.
Ctrl+Tab open the previous editor in the editor group MRU list.
Ctrl+1 go to the leftmost editor group.
Ctrl+2 go to the center editor group.
Ctrl+3 go to the rightmost editor group.
Ctrl+F4 close the active editor.
Ctrl+K W close all editors in the editor group.
Ctrl+K Ctrl+W close all editors.
Window Management
VS Code has some options to operate to determine how windows can be
opened or restored between sessions. The settings
window.openFoldersInNewWindow and window.openFilesInNewWindow are
used to configure opening new windows or reusing the last active window for
files or folders and possible values by default.
If edited to turn to default conditions, VS Code will restore all windows you
worked on during your previous session. However, there can still be cases
where this setting is ignored (for instance, if using the -new-window or -reuse-
window command-line option).
The window.restoreWindows setting tells VS Code how to restore the
opened windows of your previous session. You can also change this setting to
never reopen any windows and always start with an empty VS Code instance.
We will now take a look at how to set up VS Code for Python development.
Cross-Platform
VS Code is a free code editor that runs on the macOS, Linux, and Windows
operating systems.
For smoother installation you can follow the following platform-specific
guides:5
MacOS
1. Download VS Code for macOS.
2. Open the browser’s download list and locate the downloaded archive.
Linux
VS Code is officially distributed as a Snap package in the Snap Store, and can
also be downloaded from the official site as an RPM or DEB package.
You can install it by running: sudo snap install --classic code # or code-
insiders.
Once installed, the Snap daemon will take care of automatically updating
VS Code in the background. You can also expect to get an in-product update
notification whenever a new update is available.
Windows
1. Download the VS Code installer for Windows.
Updating Cadence
VS Code releases a new version every month with new features and
progressive bug fixes. Most platforms have auto-updating installed, so you will
be prompted to look for the new release when it becomes available. You can
also manually check for updates by running Help ➤ Check for Updates on
Linux and Windows, or running Code ➤ Check for Updates on macOS.
Additionally, you can also disable auto-update if you would like to update VS
Code according to your own schedule.
Portable Mode
VS Code also supports Portable mode installation. This mode ensures that all
data created and maintained by VS Code is stored in close quarters so that
when necessary it can be moved around across environments, even on a USB
drive.
Additional Components
VS Code is an editor with a relatively small footprint. Unlike other traditional
editors that tend to include every other function, with VS Code you can tune
and customize your installation to the development technologies most
important to you.
Extensions
VS Code extensions let third parties add support for the following:
Languages: C++, C#, Go, Java, Python
Tools: ESLint, JSHint , PowerShell
Debuggers: PHP XDebug
Keymaps: Vim, Sublime Text, IntelliJ, Emacs, Atom, Brackets, Visual Studio,
Eclipse
Extensions smoothly integrate into VS Code’s User Interface, commands,
and task running systems, so you will find it easy to operate with different
technologies through VS Code’s shared interface.
Troubleshooting Keybindings
To troubleshoot keybindings problems, you can activate the command
Developer: Toggle Keyboard Shortcuts Troubleshooting. This will help to
perform logging of dispatched keyboard shortcuts and will give access to the
output panel with the corresponding log file.
With it, you can later press your desired keybinding and check what
keyboard shortcut VS Code uses and what command is activated.
Keyboard Rules
Each rule consists of the following:6
a key that defines the pressed keys.
a command containing the identifier of the command to execute.
an optional when clause containing a Boolean expression that will be
calculated depending on the current context.
Two separate keypress actions known as Chords are described by
separating the two keypresses with space. For example, Ctrl+K Ctrl+C.
When a key is pressed:
the rules are assessed from bottom to top.
the first rule that matches, both the key and in terms of when is accepted.
no more rules are processed.
if a rule is found and has a command set too, the command is implemented.
The additional keybindings.json rules are omitted at runtime to the bottom
of the default rules, therefore allowing them to overwrite the default rules. The
keybindings.json file is observed by VS Code, so editing it while VS Code is
running will upgrade the rules at runtime.
The keyboard shortcuts dispatching is completed by analyzing a list of
rules that are stored in JSON. To illustrate with a few examples:7
// Global keybindings:
{ "key": "ctrl+f", "command": "actions.find"
},
{ "key": "alt+left", "command":
"workbench.action.navigateBack" },
{ "key": "alt+right", "command":
"workbench.action.navigateForward" },
Accepted Keys
The key is made up of modifiers and the key itself. The following modifiers are
accepted:
Platform Modifiers
macOS Ctrl+, Shift+, Alt+, Cmd+
Windows Ctrl+, Shift+, Alt+, Win+
Linux Ctrl+, Shift+, Alt+, Meta+
Command Arguments
You can call on command with arguments. This is especially helpful if you
usually perform the same operation on a specific file or folder. You can include
a custom keyboard shortcut to do exactly what you need it to do. The following
is an example of overriding the Enter key to print some text:
{
"key": "enter",
"command": "type",
"args": { "text": "Hello There" },
"when": "editorTextFocus"
}
The type command will receive {“text”: “Hello There”} as its first argument
and add “Hello There” to the file instead of producing the default command.
Conditional Operators
For when clause conditional expressions, the conditional operators in Table 1-
1 are used for keybindings.8
Table 1-1 Conditional operators
Available Contexts
You can see some of the available contexts at hand when clause contexts in the
when clause context reference. The list there is not as exhaustive, and you can
look for other when clause contexts by searching and filtering in the Keyboard
Shortcuts editor (Preferences: Open Keyboard Shortcuts) or reviewing the
Default Keybindings JSON file (Preferences: Open Default Keyboard Shortcuts
(JSON)). Tables 1-2 through 1-12 provides shortcuts for some basic
commands.9
Table 1-2 Basic editing
BEE-FOOD.
Artificial food proper for Bees may be made by mixing coarse, raw
sugar, and good, sound ale, in the following proportions:—
To a quart of ale add a pound and a half of sugar, gently boil them,
in a sweet, well-tinned saucepan, over a fire clear from smoke, for five
or six minutes, or until the sugar be dissolved and thoroughly
incorporated with the ale; and, during the process of boiling, skim off
the dross that rises to the surface. Some persons boil these
ingredients much longer, and until they become, when cool, a thick,
clammy sirup; this not only diminishes the quantity of the mixture, but
renders it rather disadvantageous, to weak Bees in particular, by
clogging and plaguing them, if, as they are almost sure to do, they get
their legs or wings daubed with it. I prefer sirup in a more liquid state.
For spring feeding, I advise—that not more than a pound of sugar
be put to a quart of ale, or sweet wort, if it can be obtained, and that
a small quantity of common salt be added. By a small quantity I mean
—a drachm or two at the most to a quart of the sirup. Salt, it has
been said, is conducive to the health of Bees, and the most efficacious
remedy for the dysentery, which sometimes affects Bees in the spring;
therefore, it may not be amiss to put a little salt into their food, by
way of preventive, rather than to have recourse to it afterwards as a
remedy.
Speaking of the substances which are proper for the feeding of
Bees, Mr. Huish says[I]—"he is perfectly convinced that honey alone is
very injurious to Bees, as it in general gives them the dysentery."
Whether by this extraordinary passage Mr. Huish has, or has not,
subjected himself to the lash of his own ridicule, it would be
hypercritical and unbecoming in me to determine. As an apiarian I
respect him; in no other character am I acquainted with him. His work
on the management of Bees I have read, and have derived
information and occasionally assistance from some of its pages. There
are in it, nevertheless, several untenable positions, of which I consider
the above-quoted passage to be one: and, if what he has remarked
somewhat sarcastically, in a note at the foot of page 31, be read in
conjunction with this passage, it will be for the candid reader, apiarian,
or other, to decide whether Mr. Huish in propriâ personâ does not,
oddly enough, exemplify his own remark. It is there said—that "there
is no wonder in nature which an apiarian has not seen." Professedly
an apiarian himself, he must have seen some, at least, of the wonders
in nature, otherwise he never could have been "perfectly convinced"—
that honey—"honey alone"—the very substance which Bees, guided
by the instinct of their nature, collect with so much industry, and store
up with so much care, for their subsistence, should be "very injurious
to them, and in general give them the dysentery." From this it seems
that the substance, which is the natural food for one stock of Bees, is
physic for another, if not poison!! I cannot but express my
astonishment that a gentleman, so acute and experienced as Mr.
Huish undoubtedly is, should have asserted in the most unqualified
manner—that "honey alone is very injurious to Bees." Were this the
fact, rich stocks, and all stocks that subsist upon "honey alone" during
winter, would "in general" be affected with dysentery in the spring,
which certainly is not the case. "In general" rich stocks are healthy
and strong in the spring. Poverty is the predisposing cause of
dysentery among Bees: a regular supply of their natural—their
peculiar food, does not induce dysentery or disease of any sort. Had
Mr. Huish analyzed the honey given to Bees as food, and which
induced dysentery, he would, I suspect, have discovered that it was
not "honey alone," but—medicated honey—honey and brimstone, or
honey strongly tinctured either with brimstone or tobacco. That honey,
tinctured with the pernicious qualities of those substances, should
have a laxative effect upon impoverished, debilitated Bees, is no more
than might be expected: but then it is not the honey that has the
"injurious" effect, but the essence of the brimstone or of the tobacco
that is administered along with it. What effect honey, that has not
been stoved and saturated with brimstone or with tobacco, may have
upon weak Bees, when given to them for spring food, I pretend not to
determine, because I have never tried the experiment. But I do say
that before the arrival of spring, honey, that has been drained or
expressed from the comb, undergoes fermentation, and that
fermentation may, for aught I know, impart to it physical properties,
which in its pure, liquid, unchanged state, in the warm hive, it does
not possess. I am not chemist enough to venture to assert that it is
so, but I think it highly probable that fermentation may alter the
properties of honey, and perhaps may render it unwholesome to Bees.
But fresh, unfermented honey, even that in the blackest and oldest
combs—the very refuse, and all such as the cottage-housewife makes
into common mead, if spread upon large dishes and placed in an
apiary, will be banqueted upon by the Bees in the most eager manner,
and is apparently much enjoyed by them. They soon carry into their
hives what they do not consume on the spot, and suffer no
inconvenience whatever from the treat. I have feasted my Bees in this
way scores of times, and esteem it the very best mode of autumnal
feeding, and the most profitable way of disposing of broken combs
and refuse honey. "Honey alone" is the natural food of Bees, and if
given to them pure and untainted, in its primitive, limpid state, so far
from being injurious, it is highly beneficial to them; of this I have not
the shadow of a doubt. For autumnal feeding, I prefer honey to all
other substances, and recommend it as the most proper food that can
be given to them.
[I] Huish on Bees, page 272.
CHAPTER XV.
CATALOGUE OF BEE-FLOWERS, &c.
From the account of the mode of supplying Bees with artificial food, to
the enumeration of such trees, plants, and flowers as are most
frequented by Bees, for the purpose of culling from them the various
substances, which their necessities, their nature, or their instinct
(which is a part of their nature) urge them to seek for, the transition is
so easy and natural—is so akin to the subject of Bee-feeding, as to be
rather a continuation thereof than a transition to a fresh one; I
therefore proceed to give a catalogue of those trees and plants which
afford pabulum for Bees. It is furnished principally from my own
ocular observation, and is partly collected from the observation of
others, whose curiosity has led them to pay attention to the subject,
and to make remarks upon it.
Alder-tree Celery
Almond-tree Cherry-tree
Althea frutex Chesnut-tree
Alyssum Chickweed
Amaranthus Clover
Apple-tree Cole or coleseed
Apricot-tree Coltsfoot
Arbutus (alpine) Coriander
Ash-tree Crocus
Asparagus Crowfoot
Aspin Crown-imperial
Cucumber
Balm Currants
Bean Cypress-tree
Beech-tree
Betony Daffodil
Blackberry Dandelion
Black-currant-tree Dogberry-tree
Borage
Box-tree Elder-tree
Bramble Elm-tree
Broom Endive
Bugloss (viper's)
Buckwheat Fennel
Burnet Furze
Cabbage Goldenrod
Cauliflower Gooseberry-tree
Gourd
Ivy Nasturtium
Nectarine-tree
Jonquil Nettle (white)
Kidney-bean Oak-tree
Onion
Laurel Orange-tree
Laurustinus Ozier
Lavender
Leek Parsley
Lemon-tree Parsnip
Lily (water) Pea
Lily (white) Peach-tree
Lime-tree Pear-tree
Liquidamber Peppermint
Liriodendrum, or Tulip-tree Plane-tree
Lucerne Plum-tree
Poplar-tree
Mallow (marsh)
Poppy Tacamahac
Primrose Tansy (wild)
Privet Tare
Teasel
Radish Thistle (common)
Ragweed Thistle (sow)
Rasberry Thyme (lemon)
Rosemary (wild) Thyme (wild)
Roses (single) Trefoil
Rudbechiæ Turnip
Saffron Vetch
Sage
Saintfoin Violet (single)
St. John's wort
Savory (winter) Wallflower (single)
Snowdrop Willow-herb
Snowberry-tree Willow-tree
Stock (single) Woad
Strawberry
Sunflower Yellow weasel-snout
Sycamore-tree
Of these some are valuable for the supply of pabulum they afford
Bees early in spring; as the white alyssum, broom, crocus, furze,
hazel, laurustinus, mezereon, ozier, plane-tree, poplar-tree, snowdrop,
sycamore-tree, the willow-tree, &c. Others again are valuable on
account of the lateness of the season that Bees derive assistance from
them; as the golden-rod, heath, ivy, laurustinus, mignionette,
ragweed, &c. Some abound with honey; as borage, buckwheat,
burnet, coleseed, currant and gooseberry-trees, heath, leek,
mignionette, mustard, onion, thyme, the blossoms of apple, apricot,
cherry, nectarine, pear, and plum-trees, and the leaves of those trees
remarkable for what is called honey-dew, as the aspin, blackberry,
laurel, laurustinus, lime, maple, oak, plane, poplar, and sycamore-tree.
Among those that are rich in pollen, may be classed—the arbutus,
ash, blackberry, box, chesnut, cypress, elder, laurel, marsh-mallow,
turnip, &c.
The cultivation of some of the most valuable of these is too-limited
to be particularly advantageous to Bees, as alyssum, borage, burnet,
golden-rod, laurustinus, mezereon, mignionette, &c. The most
extensive and lasting Bee-pasturage in this country is clover, heath,
and in my own immediate neighbourhood mustard. In short, every
one of the flowers, &c. mentioned in the foregoing catalogue, and
others innumerable, are in their turns resorted to by Bees, and of
course are more or less advantageous to them.
CHAPTER XVI.
HONEY-COMB.
To excite our admiration of the industry and ingenuity of Bees, we
need only take into our hands a piece of honey-comb, and examine it
attentively. Its neatness, its beauty, its construction, the similarity and
exact proportion of its double web of cells, for a honey-comb is, in
fact, a web of cell-work on both sides, are most admirable, and
calculated to lead the contemplative mind from nature's work up to
nature's God.
When a swarm of Bees is put into a hive, or into a box, they
immediately set about constructing combs in it, and proceed in their
building work with a rapidity that is truly astonishing. The cells that
are opposite to each other are advanced alike: the work on one side is
just as forward and in the same state as that on the other side. In the
cells first finished the Queen begins to deposit her eggs. In an
incredibly short space of time, an immense number of cells is
completed, and the Bees store pollen, farina, or Bee-bread, (which are
so many names for the same substance) in some of those not already
occupied by eggs, and in others honey soon becomes visible: all is
activity, industry, and apparently happiness. But, to come to
particulars:—
As Dr. Bevan, in the course of his masterly chapter "on the
Architecture of Bees," has given an engraved representation of a piece
of honey-comb,—and as Mr. Huish also has given a somewhat similar
representation, but better than Dr. Bevan's, inasmuch as it is more
varied, and shows the royal-cells in their different stages to more
advantage, and the drone-cells likewise;—I cannot, perhaps, do the
honey-comb so much justice in any way, as by presenting to my
reader a copy of Mr. Huish's piece of comb, which has been greatly
improved by the skilful hand of my engraver, and by giving along with
it Dr. Bevan's able description. Though after all, a piece of real comb,
to look at and examine, is more beautiful and far better than any
engraving possibly can be, however cleverly it may be executed: and
therefore, notwithstanding the plate, I would recommend it to my
reader to procure a piece of real honey-comb, and with it in his hand
read the following account, which is chiefly from Dr. Bevan's pen.
Royal-cells in different states of forwardness, common-cells, and
drone-cells, are intended to be severally represented in this plate.
The ranges forming the upper half, and marked—a. are intended to
represent common brood-cells and honey-cells—most of them in an
empty state. The lower ranges, marked—b. are drone-cells, and are
represented as closed up, and as they appear when full of brood.
Drone-cells, when filled with brood and sealed up, present a fuller
and more convex surface than the cells containing common brood—
these, that is—the cells containing the brood that becomes working
Bees, are sometimes flat and even, and sometimes rather concave.
The four large cells, attached perpendicularly to the edge of the
comb, and marked—c. d. e. f. are royal-cells in different states of
forwardness; that marked—c. is similar in size and shape to an
acorn-cup, and is supposed to be quite empty; that marked—d. is in
a more advanced state, and is supposed to contain a royal embryo,
in its larva state: the royal-cell, marked—e. is considerably
lengthened, narrowed, and nearly closed, because the larva it is
supposed to contain is about to be transformed into a royal nymph,
in which stage of its existence, as it does not require the assistance
of nurses or common Bees, it is closed up entirely, as in the royal-
cell, marked—f. In this closed cell it progresses from nymph to Bee,
and in due time—that is, in about sixteen days from its being
deposited as an egg, it emerges a virgin Queen. When the
temperature of a hive, or pavilion of nature, is at a proper height—
namely, between 70 and 80 degrees, sixteen days is the period
nature requires for the production of a Queen-Bee,—twenty-one for
the perfection of a working Bee,—and twenty-six for a drone Bee.
But, as Dr. Bevan very justly remarks, "the development of each
species proceeds more slowly when the colonies are weak, or the air
cool,—and that when the weather is very cold it is entirely
suspended."
But to return from this short, though it is hoped, not
uninteresting digression, into which the explanation of the Queen-
cells has led us.
"The combs of the Bee-hive comprise a congeries of hexagonal
cells, formed by the Bees, as receptacles for honey or for embryo
Bees. A honey-comb is allowed to be one of the most striking
achievements of insect industry, and an admirable specimen of
insect architecture. It has attracted the admiration of the
contemplative philosopher in all ages, and awakened speculation,
not only in the naturalist, but also in the mathematician: so regular,
so perfect, is the structure of the cells, that it satisfies every
condition of a refined problem in geometry. Still a review of their
proceedings will lead to the conclusion, as Huber has observed, that,
"the geometrical relations, which apparently embellish the
productions of Bees, are rather the necessary result of their mode of
proceeding, than the principle by which their labour is guided." "We
must therefore conclude, that Bees, although they act geometrically,
understand neither the rules nor the principles of the arts which they
practise so skilfully, and that the geometry is not in the Bee, but in
the great Geometrician who made the Bee, and made all things in
number, weight, and measure.
"Before the time of Huber, no naturalist had seen the
commencement of the comb, nor traced the several steps of its
progress. After many attempts, he at length succeeded in attaining
the desired object; by preventing the Bees from forming their usual
impenetrable curtain by suspending themselves from the top of the
hive; in short, he obliged them to build upwards, and was thereby
enabled, by means of a glass window, to watch every variation and
progressive step in the construction of a comb.
"Each comb in a hive is composed of two ranges of cells, backed
against each other: these cells, looking at them as a whole, may be
said to have one common base, though no one cell is opposed
directly to another. This base or partition, between the double row of
cells, is so disposed as to form a pyramidal cavity at the bottom of
each, as will be explained presently. The mouths of the cells, thus
ranged on each side of a comb, open into two parallel streets (there
being a continued series of combs in every well filled hive). These
streets are sufficiently contracted, to avoid waste of room, and to
preserve a proper warmth, yet wide enough to allow the passage of
two Bees abreast. Apertures through different parts of the combs
are reserved to form near roads, for crossing from street to street,
whereby much time is saved to the Bees.
Evans.
"Bees, as has been already observed, build their cells of an
hexangular form, having six equal sides, with the exception of the
first or uppermost row, the shape of which is an irregular pentagon,
the roof of the hive forming one of the members of the pentagon.
"There are only three possible figures of the cells," says Dr. Reid,
"which can make them all equal and similar, without any useless
interstices. These are—the equilateral triangle, the square and the
regular hexagon. It is well-known to mathematicians, that there is
not a fourth way possible, in which a plane may be cut into little
spaces, that shall be equal, similar, and regular, without having any
interstices." Of these three geometrical figures, the hexagon most
completely unites the prime requisites for insect architecture. The
truth of this proposition was perceived by Pappus, an eminent Greek
philosopher and mathematician, who lived at Alexandria, in the reign
of Theodosius the Great, and its adoption by Bees, in the
construction of honey-comb, was noticed by that ancient
geometrician. These requisites are:—
"First, Œconomy of materials. There are no useless partitions in a
honey-comb, each of the six lateral panels of one cell forms also one
of the panels of an adjoining cell; and of the three rhombs which
form the pyramidal base of a cell, each contributes one third towards
the formation of the bases of three opposing cells, the bottom or
centre of every cell resting against the point of union of the panels
that are at the back of it.
"Secondly, Œconomy of room; no interstices being left between
adjoining cells.
"Thirdly, the greatest possible capacity or internal space,
consistent with the two former desiderata.
"Fourthly, Œconomy of materials and economy of room produce
economy of labour. And in addition to these advantages, the cells are
constructed in the strongest manner possible, considering the
quantity of materials employed. Both the sides and bases are so
exquisitely thin, that three or four placed on each other are not
thicker than a leaf of common writing paper; each cell, separately
weak, is strengthened by its coincidence with other cells, and the
entrance is fortified with an additional ledge or border of wax, to
prevent its bursting from the struggles of the Bee-nymph, or from
the ingress and egress of the labourers. This entrance border is at
least three times as thick as the sides of the cell, and thicker at the
angles than elsewhere, which prevents the mouth of the cell from
being regularly hexagonal, though the interior is perfectly so.
Evans.
"Having just adverted to the ingenuity of Bees in thickening, and
thereby strengthening the mouths of the cells, it may here be
observed—that additional strength is also derived from the Bees
covering the whole surface of the combs, but more particularly the
edge of the cells, with a peculiar kind of varnish, which they collect
for the purpose. At first the combs are delicately white, semi-
transparent, and exceedingly fragile, smooth but unpolished: in a
short time their surfaces become stronger, and assume more or less
of a yellow tint. The deepening of the colour of honey-combs has
been supposed, by some, to be the effect of age; and in part it may
be: but it is principally owing to the coat of varnish, with which the
Bees cover them. This varnish strongly resembles propolis,
appearing to differ from it only in containing the colouring material
which imparts to wax its yellow hue. The source of this colouring
matter has not been discovered: it is insoluble in alcohol, but the
manufacture of white-wax shows that it is destructible by light. But
to return to the construction of the cell-work.
"The pyramidal basis of a cell is formed by the junction of three
rhomboidal or lozenge-shaped portions of wax: the apex of the
pyramid being situated where the three obtuse angles of the
lozenges meet. To the exterior edges and angles are attached the six
panels or sides of each cell. The apex of each pyramidal bottom, on
one side of a comb, forms the angles of the bases of three cells on
the opposite side, the three lozenges respectively concurring in the
formation of the bases of the same cells. This will, I hope, explain
what is meant by "each cell separately weak, being strengthened by
coincidence with others." The bottom of each cell rests upon three
partitions of opposite cells, from which it receives a great accession
of strength.
"As it is desirable that the reader should thoroughly comprehend
this subject, I will re-state it in other words. The partition which
separates the two opposing rows of cells, and which occupies, of
course, the middle distance between their two surfaces, is not a
plane but a collection of rhombs, there being three at the bottom of
each cell: the three together form in shape, a flattened pyramid, the
basis of which is turned towards the mouth of the cell; each cell is in
form, therefore, a hexagonal prism, terminated by a flattened
trihedral pyramid, the three sides of which pyramid are rhombs, that
meet at the apex by their obtuse angles.
"The union of the lozenges in one point, in addition to the
support which it is the means of affording to the three partitions
between opposing cells, is also admirably adapted to receive the
little egg and to concentrate the heat necessary for its incubation.
"Each obtuse angle of the lozenges or rhombs forms an angle of
about 110 degrees, and each acute one, an angle of about 70
degrees. Mr. Maraldi found by mensuration that the angles of these
rhombs, which compose the base of a cell, amounted to 109
degrees and 28 seconds, and 70 degrees and 32 seconds: and the