Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts

Sunday, November 27, 2016

Video: Interview: GoingNative 6: Walter Bright and Andrei Alexandrescu - D Programming Language

By Vasudev Ram


I watched this video (from 2013) a few days ago:

GoingNative 6: Walter Bright and Andrei Alexandrescu - D Programming Language

Going Native [1] is a tech event, and I guess 6 refers to the 6th year or edition of it. I first saw this video on Channel 9, one of Microsoft's technology sites. That site has multiple links to the video, including downloadable, in different qualities, so you may want to check out getting it from there. [2]

[1] There seems to be rising interest in "native" (programming) languages these days (before the rise of "scripting" languages, all languages were native, i.e. they ran, after compilation, on the "metal" (i.e. the CPU), not on a language VM or interpreter, and we just called them languages, no fancy-shmancy names, ha ha :). Part of the reason for the rise in interest, as mentioned in the video, is that we are entering (or have entered) a world of multi-core and concurrency, and due to Moore's law ending (?) Anyway, native languages like D, Go and Rust are picking up these days, whatever the reason. I've used native languages like Pascal and C a lot at work earlier, so I welcome this return of greater interest in native languages, though I'm not stopping using languages like Python anytime soon either.

[2] And to download the video at the command line, check out youtube-dl, a YouTube downloader in Python. Yes, downloading a video about native languages with a tool written in a scripting language - go figure :)

The video shows an interviewer talking to both Walter Bright and Andrei Alexandrescu. Walter, who developed the first native C++ compiler, is the original creator of the D programming language and Andrei, who was a C++ expert and book author, joined him some years later to help in developing the language. The interview was somewhat wide-ranging and a bit long, and quite interesting. Many aspects of the language and the plans and in-progress work for it were talked about.

The video is also embedded below.



Happy holidays to my readers.

- Vasudev Ram - Online Python training and consulting

Get updates on my software products / ebooks / courses.

Jump to posts: Python   DLang   xtopdf

Black Flyday at Flywheel Wordpress Managed Hosting - get 3 months free on the annual plan.

Subscribe to my blog by email

My ActiveState recipes



Sunday, May 8, 2016

Calling C from Python with ctypes

By Vasudev Ram

Python => C

ctypes is a module in the Python standard library. It is "a foreign function library for Python". Such libraries help with calling code written in language B, from language A. In the case of ctypes it helps with calling C code from Python code.

[ Note: There are various other methods of linking between Python code and code written in other languages, such as writing Python extensions using the Python C API, SWIG, cffi, etc. I am only looking at ctypes in this post. It is one of the simpler methods. May look at others later. ]

Here is a small example of using ctypes, to call the time() function in the C runtime library on Windows:

# libc_time.py
# Example of calling C library functions from Python
# using the Python ctypes module.
# Author: Vasudev Ram
# Copyright 2016 Vasudev Ram

from __future__ import print_function
from ctypes import cdll
import time

libc = cdll.msvcrt

def test_libc_time(n_secs):
    t1 = libc.time(None)
    time.sleep(n_secs)
    t2 = libc.time(None)
    print("n_secs = {}, int(t2 - t1) = {}".format(n_secs, int(t2 - t1)))
    
print("Calling the C standard library's time() function via ctypes:")
for i in range(1, 6):
    test_libc_time(i)
And here is the output:
$ python libc_time.py
Calling the C standard library's time() function via ctypes:
n_secs = 1, int(t2 - t1) = 1
n_secs = 2, int(t2 - t1) = 2
n_secs = 3, int(t2 - t1) = 3
n_secs = 4, int(t2 - t1) = 4
n_secs = 5, int(t2 - t1) = 5
Note: libc.time() is the Python interface [1] to the C time() function, and time.sleep() is the sleep function in the time module of the Python standard library.

[1] We obtain that interface using ctypes; see the program above.

I use a call to time.sleep() sandwiched between two calls to libc.time(), to verify that the calls to libc.time() are returning the correct result; as you can see from the output, they are doing so.

- Vasudev Ram - Online Python training and consulting

Signup to hear about my new courses and products.

My Python posts     Subscribe to my blog by email

My ActiveState recipes



Thursday, September 5, 2013

Amazon Web Services CLI rewritten in Python


By Vasudev Ram

The Amazon Web Services Command Line Interface (AWS CLI) has been rewritten, in Python.

Saw this news in a thread on the Python Reddit.

According to the thread, it (the AWS CLI) was earlier written in Java, and now uses Python, and either boto or boto-core.

I had blogged about boto here, earlier. boto is a Python library to enable access to Amazon Web Services, written by Mitch Garnaat.

The Google command line tool gsutil also uses boto.

If you are interested in creating command line tools for Unix or Linux systems, you may like to read my tutorial article on the topic, published on IBM developerWorks:

Developing a Linux command-line utility

Though the tutorial uses the C language, many of the concepts discussed in the article are applicable to writing command line tools in Python as well, because, when writing such tools, you will basically be using the C library and Unix features such as standard input, standard output, pipes and I/O redirection, but via Python.


O'Reilly Velocity Conference



- Vasudev Ram - Dancing Bison Enterprises

Contact me

Monday, June 10, 2013

Brian Kernighan uses Python


By Vasudev Ram

This is from the site usesthis.com, a.k.a The Setup :-), which has many interviews of well-known computer (and maybe other) people, about their hardware and software setups (and nowadays device setups too, of course). I've read quite a few of those interviews in the past, and they can be interesting.

Brian Kernighan uses Python. Cool ... [1] [2]

Brian Kernighan page (at Bell Labs)
Brian Kernighan page (at Princeton University)

[1] For those who don't know of Kernighan, he was, at Bell Labs, one of the top contributors to Unix and C (from early on, and for a long time), and is the co-author of the classic computer books "The C Programming Language" (with Dennis Ritchie), also abbreviated as K&R, and "The Unix Programming Environment" (with Rob Pike), abbreviated as K&P. Rob Pike has been working on the Go language for the last few years.

[2] I saw the usesthis.com article about Kernighan via this Reddit thread, which also has some interesting comments.

And I almost forgot to mention, Kernighan also co-invented Awk :-)

I was fortunate to get to read those two books (K&R and K&P) early on in my career. In fact, I should probably say "those four books" or "those six books" :-) because I read them at least twice or thrice. They had a big influence on me, and benefited me a lot in my work over the years, possibly more than any other computer books I've read, before or since then.

- Vasudev Ram - Dancing Bison Enterprises

Saturday, March 2, 2013

Dancing Bison Enterprises - Profile

               Dancing Bison Enterprises - Profile

Dancing Bison Enterprises is a small software company based in Pune, India.

We have done projects for USA-, Europe- and India-based clients in Python, Ruby on Rails, C, Java, PDF and other technologies. We have good skills and experience in Python, C, UNIX/Linux, Java, Ruby, relational databases, PDF creation, and multiple open source technologies, and in software requirements analysis, design and implementation. Development of robust software applications and components is our forte. Open source technologies and UNIX/Linux are two of our key areas of strength - we have been working with UNIX from some time before Linux was first created, and with open source software from before the term "open source" was coined. Have many years of software development experience, including both working with large international and Indian software companies and with small companies, including startups based both abroad and in India.

Please visit our business web site www.dancingbison.com for an overview about us.

The founder of the company, Vasudev Ram, is a nominated / elected member of the Python Software Foundation.

Developed multiple open source software products/projects - please see our Products page , and our Bitbucket page . More such products are in the pipeline.

Packt Publishing of the UK uses our Python product, xtopdf, in their book production workflow. The Software Freedom Law Center of the USA also uses xtopdf as part of their e-discovery work.

Published technical articles on Python, C and Linux; please see:

Using xtopdf (on the Packt Publishing site)

Developing a Linux command-line utility (on the IBM developerWorks site)

A vi quickstart tutorial (in Linux For You magazine)

How Knoppix saved the day (in Linux For You magazine)

Our article on Developing a Linux command-line utility - the 2nd link in the list of articles above - was published on IBM developerWorks, and translated by IBM for the Chinese and Japanese versions of their developerWorks site. More than one organization has used the article as a basis for developing production command-line tools.

We are available for web or non-web application development, open source and related consulting/contract work, and for corporate software training in the areas of our skills.

Please visit our Contact page to get in touch with us or to request a quote.

Tuesday, January 29, 2013

BareMetalOS, x86-64 OS in assembly language

Return Infinity - BareMetal OS

It is being written purely in assembly language, with plans to let apps for it be written in assembly or C.

Programming in assembly language is interesting and fun, because you work very close to the actual hardware, dealing with registers, memory locations, addressing modes, bit manipulation, etc.

I've only done a little of it, much earlier, on the  Commodore-64, the BBC Micro, and PCs running DOS, but enjoyed it.

I once bought a book that had the entire listing for a C-64 assembler, written in BASIC, using POKE, and entered it into the machine, including re-entering a large part of it due to finding bugs, probably due to typos while entering the hex codes. IIRC, it took me the better part of a week to complete that job and get a running assembler, but it worked :)

Saturday, November 24, 2012

pinger utilities have multiple uses

Python | Host/Device Ping Utility for Windows

Saw the above pinger utility written by Corey Goldberg a while ago. It is in Python and is multi-threaded.

Seeing it reminded me of writing a pinger utility some years ago for a company I worked for at the time; it was for Unix systems, and was not multi-threaded.

It was written in a combination of Perl (for regex usage), shell and C.

The C part (a program that was called from the controlling shell script) was used to overcome an interesting issue: a kind of "drift" in the times at which the ping command would get invoked.

The users wanted it to run exactly on the minute, every n minutes, but it would sometimes run a few seconds later.

I used custom C code to solve the issue.

Later I learned (by reading more docs :) that the issue could probably have been solved by calling a Unix system call or two (like gettimeofday or getitimer, I forget exactly which right now) from my C program.

Anyway, the tool ended up being used to monitor the uptime of many Unix servers at the company. The sysadmins (who had asked me to create the tool) said that it was useful.

As Corey says in his post, pinger tools can be used to monitor network latency, check if hosts / devices are alive, and also to log and report on their uptime over an extended period, for reporting and for taking corrective action (as my utility was used).

Also check out pingdom.com for an example of a business built on these concepts. Site24x7.com is another such business; it is part of the same company as Zoho.com. They were (and still are)  into network monitoring / management before they created the Zoho suite of web apps.

I use both Pingdom and Site24x7 on my business web site www.dancingbison.com, from over a year or more now, to monitor its uptime, and both are fairly good at that.

Thursday, September 20, 2012

bitly talks about Python, C and Go (languages)

word

Didn't understand some parts of the post, but was interesting overall.

Monday, July 16, 2012

The origin of a.out

Sunday, April 29, 2012

Using Java Runtime.exec to invoke UNIX commands

http://jonisalonen.com/2012/runtime-exec-with-unix-console-programs/

Nice tip. Java's Runtime.exec() method can be useful to invoke external tools from your code.

I once had the idea for, and created, a utility that had a Java servlet (with an HTML form as front-end) calling a UNIX (HP-UX) C setuid program that enabled developers in my team to stop and restart Informix database servers without knowing the DB server admin password. UNIX C setuid programs are quite useful for giving less privileged OS users restricted / controlled access to privileged operation, as in my example.

Writing C setuid programs involves many potential security issues, though. Mine was deployed in a corporate environment behind firewalls, so had relatively less risks. If you're writing a setuid program for public Internet use, make sure to do a lot of research about the issues and how to mitigate them.

- Vasudev Ram
www.dancingbison.com