The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,854 other subscribers

Archive for the ‘Software Development’ Category

Visual Studio Code: enable Python debugging and selecting the Python version used

Posted by jpluimers on 2019/12/18

A few links and screenshots for my archive (assuming development on MacOS):

Enable Python Debugging

  1. Start the debugger: key combination Shift-Command-D, or click the debug icon 
  2. Click on the wheel with the red dot in the debugger pane: , which will generate and open a launch.json file in the current workspace, remote the red dot and fill the drop down with debug configurations

Via:

Selecting the Python version

  1. Key combination Ctrl-Shift-P
  2. Type Select Interpreter
  3. Select the Python version you want; on my system they were at the time of writing:

Via:

Setting command-line arguments

Commandline arguments are set in the same .vscode/launch.json file:

"args": [
    "--quiet", "--norepeat"
],

Though [WayBack] Python debugging configurations in Visual Studio Code: args could have been more clear that you should put that under the Python configuration section you are debugging with, for instance:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--quiet", "--norepeat"
            ]
        },

Setting the startup python program

The page above also has a section on [WayBack] Python debugging configurations in Visual Studio Code: _troubleshooting that you can use to start the same script each time you debug, for instance your integration tests:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            // "program": "${file}",
            "program": "${workspaceFolder}/snapperListDeleteFailures.FileTests.py",

Fazit

I should have read [WayBack] Get Started Tutorial for Python in Visual Studio Code first.

–jeroen

Posted in Development, Python, Scripting, Software Development | Leave a Comment »

Great quote destructors in Delphi development…

Posted by jpluimers on 2019/12/18

No destructor should ever throw an exception. If it does, there’s not really any way to recover from it anyway, so it doesn’t matter if anything leaks because of it.

Greate quote by [WayBackUser Rob Kennedy answering [WayBackinterface – Avoiding nested try…finally blocks in Delphi – Stack Overflow

It’s a basic development pattern for writing Delphi destructor code.

–jeroen

Posted in Delphi, Design Patterns, Development, Software Development | 6 Comments »

shell – Should I put #! (shebang) in Python scripts, and what form should it take? – Stack Overflow

Posted by jpluimers on 2019/12/17

It is very important to get the shebang correct. In case of Python, you both need env and the correct Python main version.

Answer

Correct usage for Python 3 scripts is:

#!/usr/bin/env python3

This defaults to version 3.latest. For Python 2.7.latest use python2 in place of python3.

Comment

env will always be found in /usr/bin/, and its job is to locate bins (like python) using PATH. No matter how python is installed, its path will be added to this variable, and env will find it (if not, python is not installed). That’s the job of env, that’s the whole reasonwhy it exists. It’s the thing that alerts the environment (set up env variables, including the install paths, and include paths).

Source: [WayBack] shell – Should I put #! (shebang) in Python scripts, and what form should it take? – Stack Overflow

Thanks GlassGhost and especially flornquake for the answer and Elias Van Ootegem for the comment!

The answer is based on [WayBack] PEP 394 — The “python” Command on Unix-Like Systems | Python.org.

The env is always in the same place, see env – Wikipedia and Shebang (Unix) – Wikipedia.

–jeroen

Posted in Development, Python, Scripting, Software Development | Leave a Comment »

InplaceExeWrapper for those tools that do not allow specifying an output file – twm’s blog

Posted by jpluimers on 2019/12/17

In my bin directory from [WayBack] InplaceExeWrapper Project Top Page – OSDN: [WayBackInplaceExeWrapper for those tools that do not allow specifying an output file – twm’s blog:

There are a lot of command line tools that are very useful, but have one flaw: They directly modify a file in place and do not allow you to specify an output file instead.

Enter InplaceExeWrapper which called as

InplaceExeWrapper --expectfilenameonstdout c:\path\to\dprojnormalizercmd.exe input.dproj output.dproj

does the following:

  1. Create a temporary directory under %TEMP%
  2. Copy the input file input.dproj there
  3. Call the tool as dprojnormalizer tempfile.dproj
  4. Copy the modified file to the output file output.dproj
  5. Delete the temporary directory

So basically it replaces the missing functionality of specifying an output file for the tool it calls.

Here is the full help on command line parameters and options:

Synopsis: InplaceExeWrapper [options] Executable InFile [OutFile]

Parameters:
Executable        : Executable to call (if set to "copy" we only copy InFile to OutFile)
InFile            : input filename
OutFile           : output filename, defaults to infile

Options:
--CheckResult=value : If set, the executable must return the value given for this option (must be a number)
--debug           : if given, some debug output is written to error.txt in the temp directory and the temp directory will not be deleted.
--ExpectFilenameOnStdout : if set, the output of the executable must contain the filename
--help
-?
-h
-H                : display parameter help
--ShowCmdLine     : Show command line as passed to the program.
--StartupLog=value : Write a startup log to the given file.
--TempDir=value   : directory to use for temporary files (must exist)
--toStdOut        : if set, output is written to stdout and infile is not changed

Via [WayBack] There are a lot of command line tools that are very useful, but have one flaw: They directly modify a file in place and do not allow you to specify an o… – Thomas Mueller (dummzeuch) – Google+

–jeroen

Posted in Delphi, Development, Software Development | 2 Comments »

Delphi: “Override method %s.%s should match case of ancestor %s.%s (H2365)”

Posted by jpluimers on 2019/12/17

If you write consistent code, you will never see [WayBackOverride method %s.%s should match case of ancestor %s.%s (H2365), but a long while ago I bumped into a project where some the developers had trouble using their shift key and failed to use code completion in quite a few parts of the source code.

So next a lot of lines containing things like Begin, whIle, repeaT, wrong indentations (not just at the wrong level, but even getting things indented at the same level wrong).

Code formatted like this was no exception, not even for methods bound to events:

procedure  TForm1.Button1CLick(SendeR  : TOBJect ) ;
 Begin
  Button2Click  (Sender );
end;

You cannot disable this hint individually as it is not on the list at [WayBack] Delphi XE2’s hidden hints and warnings options | Marc Durdin’s Blog, so you either have to fix the code (which I prefer), or disable all hints with {$ HINTS OFF} as per [WayBackcompiler construction – Can specific Delphi hints be disabled? – Stack Overflow (thanks Lars Truijens).

The above occasion was the first and only time I saw the hint H2365 until recently when I again bumped into a project that had grown over a long time needing some maintenance.

This reminded me I should have blogged about it, found back [Archive.is] H2365 Override method %s.%s should match case of ancestor %s.%s (Delphi) Today was the first time I have ever seen this compiler hint. Why does Delphi… – Graeme Geldenhuys – Google+ and dug a bit deeper.

Read the rest of this entry »

Posted in Delphi, Development, Software Development | Leave a Comment »

Borland’s legendary development tools…

Posted by jpluimers on 2019/12/12

From [WayBack] Borland’s legendary development tools Do you remember Turbo Languages from Borland? There are Pascal, C, Assembler, Basic, Prolog and many other produc… – Jaroslav Beran – Google+:

Borland’s legendary development tools

Do you remember Turbo Languages from Borland? There are Pascal, C, Assembler, Basic, Prolog and many other products. Here there is link to directory containing original documentation of many these products:

http://bitsavers.informatik.uni-stuttgart.de/pdf/borland/

Did you work with some of them? Which one was your favorite?

[WayBack] Bitsavers Index of /pdf/borland:

[ICO] Name Last modified Size Description

[DIR] Ads/ 2011-09-01 20:47
[ ] BRIEF_for_DOS_and_OS2_Version_3.1_Users_Guide_1992.pdf 2009-06-30 22:57 8.9M
[ ] Borland_Brochure_1987.pdf 2009-11-05 02:18 2.1M
[ ] Borland_Turbo_BASIC_Owners_Handbook_1987.pdf 2009-07-30 05:33 15M
[ ] Eureka_The_Solver_Owners_Handbook_1987.pdf 2011-03-20 23:56 8.5M
[ ] Superkey_Owners_Handbook_1986.pdf 2011-02-04 02:01 7.1M
[ ] Turbo_Languages_Brochure_1988.pdf 2011-01-25 04:26 4.0M
[ ] Turbo_Vision_Version_2.0_Programming_Guide_1992.pdf 2010-06-18 19:07 25M
[ ] Windows_API_Guide_Reference_Volume_1_1991.pdf 2009-07-01 03:16 28M
[ ] Windows_API_Guide_Reference_Volume_2_1991.pdf 2009-07-01 03:16 8.7M
[ ] Windows_API_Guide_Reference_Volume_3_1992.pdf 2009-07-01 03:17 24M
[DIR] borland_C++/ 2013-01-17 00:07
[DIR] objectvision/ 2011-06-06 23:47
[DIR] paradox/ 2011-06-06 23:43
[DIR] quatro/ 2014-12-11 03:04
[DIR] quatro_pro/ 2011-06-06 23:47
[DIR] reflex/ 2011-06-06 23:37
[DIR] sidekick/ 2011-06-06 23:38
[DIR] sprint/ 2011-06-06 23:42
[DIR] turbo_assembler/ 2013-01-17 00:07
[DIR] turbo_c/ 2011-06-06 23:37
[DIR] turbo_pascal/ 2011-09-01 19:23
[DIR] turbo_prolog/ 2011-06-06 23:43

Via: [WayBack] Borland’s legendary development tools Do you remember Turbo Languages from Borland? There are Pascal, C, Assembler, Basic, Prolog and many other produc… – Adrian Marius Popa – Google+

–jeroen

Read the rest of this entry »

Posted in Development, History, Pascal, Software Development, Turbo Pascal | Leave a Comment »

Every programmer should read this at their own pace: From design patterns to category theory

Posted by jpluimers on 2019/12/12

Slowly but steadily, I’m now ready to continue reading [WayBackFrom design patterns to category theory.

I found it two years ago after stumbling into [WayBack] Semigroups accumulate and [WayBack] Monoids accumulate. Both articles indicate they are part of two distinct series: [WayBack] Semigroups and [WayBack] Monoids which both in turn indicate the same super-series: [WayBack] Monoids, semigroups, and friends.

That intrigued me, as from a casual interest in Semigroups I got into a really structured coverage of many related topics leading all the way to design patterns. How cool is that!

Back than, I lacked some of the vocabulary I needed to fully grasp this, as part of the posts use the functional programming perspective which – for geeks like me that grew up in the procedural, object-oriented, and interface-polymorphism eras – takes some time to wrap their head around.

I did learn a thing or two back then, for instance the series taught me that some semigroups are not monoids. The diagram on the right shows how the various groups are related. But I could not replicate that knowledge, clearly lacking the words to explain it to myself.

What I really liked is the humble way in which the author – Mark Seeman – indicated that when he first thought about these topics himself, he too had still a lot of things to learn, including acquiring the vocabulary:

My first attempt at answering these questions was in 2010, but while I had the experience that certain abstractions composed better than others, I lacked the vocabulary. I’ve been wanting to write a better treatment of the topic ever since, but I’ve been constantly learning as I’ve grappled with the concepts.

Like me, he is on a life long quest in learning new things every day.

Now that I’ve done more functional programming (mainly from object-oriented code bases), I think I’m more equipped to digest his writings, better understand them and maybe even explain them.

By now there also should be more topics than these ones:

Time to do some reading over the next weeks…

–jeroen

Posted in Design Patterns, Development, Software Development | Leave a Comment »

Delphi ^A syntax: Documented, implied, or undocumented? – Stack Overflow

Posted by jpluimers on 2019/12/12

The syntax is documented. In the Turbo Pasal 3 documentation, i.e. the Z80 era.

Source my answer to [WayBackDelphi ^A syntax: Documented, implied, or undocumented? – Stack Overflow (I have added some WayBack Internet Archive links below) as it is from the Turbo Pascal era where the caret was introduced to support control characters:

This is from long ago as an escape character to enable you to have consts for control characters in a more readable way.
const
  CtrlC = ^C;
begin
  Write(Ord(CtrlC));
end.

This defines a Char constant with value #3, then writes 3 in Borland Pascal 7, and I remember seeing it years before that too.

I just checked the Turbo Pascal 5.0 and Borland Pascal 7.0 languages guides, but could not find it, so it seems undocumented.

Edit: I do remember this was a Borland thing, and just [WayBack] checked: it is not part of the ISO Pascal standard (formerly this was ANSI Pascal Standard, thanks Sertac for noticing this).

It [WayBack] is documented in the Free Pascal documentation [WayBack].

SGI uses the backslash as escape character, as per their docs [WayBack].

More Edit: I found it [WayBackdocumented in Delphi in a Nutshell and the [WayBackDelphi Basics site.

Found it: Just found it on page 37 of the Turbo Pascal 3 Reference Manual [WayBack].

(Marco van de Voort found the Free Pascal documentation)

It in fact originates in the 1984 Turbo Pascal 1 edition, as per the [WayBack] Turbo_Pascal_Reference_Manual_Feb84.pdf:

Read the rest of this entry »

Posted in Borland Pascal, Delphi, Development, FreePascal, History, Pascal, Software Development, Turbo Pascal, Z80 | 1 Comment »

Exceptional Safety

Posted by jpluimers on 2019/12/11

I think I tend to forget with [WayBack] Exceptional Safety is this:

object destruction process must not cause or raise any unhandled exceptions or you will have memory leaks beyond your ability to fix them.

Particulary, that means the BeforeDestruction method – and destructors themselves – must never ever allow exceptions to escape them. Any escaping exception there will always cause memory leak. Period.

–jeroen

via [WayBack] Single or nested try…finally blocks? None will prevent the memory leak if your destructors are broken. – Dalija Prasnikar – Google+

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi/GDIPBitmap at master · tothpaul/Delphi · GitHub

Posted by jpluimers on 2019/12/11

Next time I don’t need something like TPngImage any more:

this little unit let you load any GDI+ supported graphic format (BMP, JPG, PNG or TIF) into a Delphi TBitmapit’s a TBitmap helper, so just add the unit to you’re project and call the method GDIPLoadFromStream

Source: Delphi/GDIPBitmap at master · tothpaul/Delphi · GitHub

Found via: [WayBack] Let’s extend TBitmap with a GDIP loader :) TBitmap.GDIPLoadFromStream can load any GDI+ supported format (JPEG, PNG, TIFF) https://github.com/tothpaul… – Paul TOTH – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »