Some reasons to use Emacs

I’m using emacs for several years now and it is by far my favorite editor. Don’t get me wrong, I do use Visual Studio for my MFC programs and don’t mind working with it, but there is just something about emacs. I recently was thinking of why I liked emacs so much and thought I’ll list my reasons to use emacs here.

The beauty of simplicity

Nowadays, there are many powerful and popular editors (Notepad++, Sublime Text, etc.) and IDE’s (Eclipse, Visual Studio, and so on) out there. I just find them often cluttered with buttons, menus, sidebars, etc. Emacs on the other hand (I’m now referring to the command-line and not the GUI version), consists of a simple window and no more.

For example, when I’m using Visual Studio, I hardly use any of the menu buttons (for many of the menu items, I know the key combinations anyhow). Those just take away space from my editing window. Of course, you can customize the toolbars, sidebars, etc. to your liking, but to enable efficient work on VS, I still end up with sidebars. The issue is not, that it prevents me from writing 200-300 character long lines (which, seriously, is highly undesirable), it’s more that it kind of forces me to switch btw mouse and keyboard frequently (though I’m sure there are some people that know how to work under Visual Studio/Eclipse without having to use the mouse hardly at all).

Efficiency

I remember when I started off with emacs. It was not as easy as I thought. I seriously was only able to work for about an hour on emacs without a break. Why? My hands starting aching. Why? I just wasn’t used to having my hands all the time on the keyboard. You don’t realize how often you switch between keyboard and mouse (and therefore wasting time) till you start using emacs (at least that’s how it was for me).

It took me about two to three weeks till I was comfortable working 8 hours a day on emacs. But as soon as I was, I was hooked. I find myself quicker on emacs than on any other editor since I can leave my hands on the keyboard without having to switch to the mouse frequently.

Powerful

Undoubtedly, emacs is a bit more difficult to start with than any other editor. As a beginner, you’ll need to learn at least the basic key commands (like move cursor to left/right/up/down, undo, mark text, etc.) to start using it. I admit that’s a major drawback and the main reason why it will likely remain a bit of a geek editor. But at the same token, as soon as you know the basics, you’ll likely find yourself to be way more efficient in text/code editing.

For example, I don’t have to switch to the explorer window to search for or copy a file. I simply type in the command to open dired in emacs and do whatever file/folder work I need to do. Emacs provides a huge (and still growing) amount of extensions which makes switching between applications almost dispensible. Emacs provides support for most programming languages, calenders, email program, twitter mode, and much more.

Customization

I feel like emacs can be much more customized to your liking than any other editor. You don’t just choose background/text/keyword colors and fonts(as most editors nowadays provide as well), but you can set automatic reminders (from calender, todo list, you name it), start emacs with multiple windows each containing your favorite modes/files (stack exchange, twitter, browser, …), display a clock at all times, and so much more.

Extensibility

This part has been completely neglected by me which I’m going to fix now. I’m finally going to start learning elisp. For way too long, I ignored the possibilities of creating my own extensions or of modifying existing ones.

If you google emacs, you’ll find a lot of beginner tutorials. One blogger, which I would definitely recommend subscribing to (or at least frequently visit her side) is Sacha Chua. She writes quite a bit about emacs (for beginners as well as for novices) and inspires you to use it daily.

Simple Beginner OpenGL programs

I’m currently at the 21st YouTube episode from Jamie King’s Playlist ‘3D Computer Graphics using OpenGL’. So far, I have created 3 little programs which are based on each other. All of them are available on Github.

The best way to learn a new language is by actually using it and that’s why I write little programs based on what I’m learning from the YouTube episodes.

My 2nd beginner program

The 2nd OpenGL program consists of a fixed pipeline (no use of shaders). It sets the background blue and then draws two white triangles.

Setting the background color is done via the glClearColor function.

For the drawing of the triangles, there are a few more steps required. First, you need an array with your vertices. Then you need to create a buffer OpenGL can use, which is done via the glGenBuffer function. This buffer then needs to be bound to GL_ARRAY_ELEMENT (since we have an array of vertices which form two triangles if you connect each of them) via glBindBuffer.

This OpenGL buffer object now still needs the actual vertice coordinates which we provide via the glBufferData function. Now all that’s left is to tell OpenGL that it can use that buffer via glEnableVertexAttribArray and we also still need to tell it how the buffer looks like (how many floats for a vertice, etc.) which is done via glVertexAttribPointer.

The buffer object is now ready to be used by OpenGL. We only have to tell OpenGL anymore about the size of the window to render which we do with glViewport and call the actual drawing function glDrawArrays.

My 3rd beginner program

The 3rd program improves memory usage of the previous program (though admittingly for that tiny array, it doesn’t really matter at all) and uses a simple vertex and fragment shader to actually color those two triangles created.

When creating an array of vertices, it is likely that you have a lot of duplication. E.g. one vertice of the first triangle could be the starting point of the second triangle. To avoid unnecessary duplication, you can use additionally to the GL_ARRAY_BUFFER also the GL_ELEMENT_ARRAY_BUFFER. That means I remove all duplicated vertices in the one array and create a second array with the indices. For that array, I generate again an OpenGL buffer and this time bind it to GL_ELEMENT_ARRAY_BUFFER. Last but not least, I have to give the new buffer object the indices array.

The drawing function glDrawElements is now a different one, since the indices array tells OpenGL which vertice comes next.

For the coloring of the triangles, we need to add the RGB floats to each vertice in the first buffer array. Then we tell OpenGL that the buffer array contains those color vertices as well via glEnableVertexAttribArray and glVertexAttribPointer.

Last but not least, we need to write simple vertex and fragment shader code (minimal.vert and minimal.frag in my example program) and then tell OpenGL to compile, link and use the shaders.

Pretty unspectacular what I’ve produced so far, but I’m looking forward to learning more and more.

Do. Or do not! There is no try. – Yoda

Database/table information

In the last few weeks, I improved/corrected lots of my existing stored procedures for my current project. It feels good knowing that my understanding of inline views has definitely improved. I’ve additionally learned a few SQL queries that provide me with database/table information.

I also faced a few issues while trying to use views in SQL Server. I have a few views in SQL Server that I can’t actually use because as soon as I save them, the content gets automatically formatted and changed. I’d be fine with it if the change didn’t influence the outcome, but it does. When I have several joins and then a WHERE clause, SQL Server always changes it to joins with an AND instead of the WHERE. That’s really annoying since the outcome with the AND is wrong. I hope I can figure out what’s going on soon but till then, I’ll end up saving those queries in a stored procedure directly (where it doesn’t get auto-formatted and changed).

A few things I’ve learned lately:

SQL Servers sys.sql_modules

In my current project, I ended up having quite a lot of stored procedures. I started getting a bit overwhelmed. For example, I knew I had used certain keywords (like TRANSACTION) in some procedures, but how could I quickly find them. Going through each stored procedure is an option, but a very slow, annoying, and frustrating one. Then I found out about the sys.sql_modules table. It has a ‘description’ column which contains SQL scripts for creating each existing view and stored procedure.

I started using following search

SELECT definition FROM sys.sql_modules 
WHERE definition LIKE '%TRANSACTION%'; 

That helped me tremendously in finding certain stored procedures very quickly.

SQL Servers sys.objects

The SQL query above helps in finding the wanted stored procedure/view since each ‘description’ column contains the name of the stored procedure/view within a few words. But I figured it would be nicer if I could just get the stored procedure/view name instead. And that’s where the sys.objects table comes handy.

SELECT DISTINCT o.name FROM sys.sql_modules sm 
INNER JOIN sys.objects o ON sm.object_id = o.object_id
WHERE sm.definition LIKE '%account%';

Other useful SQL queries to learn more about the database

The more tables/columns/views/stored procedures/functions/etc., the harder it gets to maintain the database and to keep an overview.

I found querying the Information Schema views very useful. For example, if you want to quickly know the columns of a table or view, use following query:

SELECT TABLE_NAME, COLUMN_NAME
FROM my_database.INFORMATION_SCHEMA.COLUMNS;
WHERE TABLE_NAME = 'my_table'

I’ve already mentioned how to search for certain keywords in views/stored procedures via sys.sql_modules. Another way of doing exactly this is via the Information Schema views. The following code snippet shows all CREATE VIEW/PROCEDURE functions for your database:

SELECT TABLE_NAME, VIEW_DEFINITION
FROM my_table.INFORMATION_SCHEMA.VIEWS;
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM my_table.INFORMATION_SCHEMA.ROUTINES;

Example usage

During development, I often have more than one database of the same thing. I have the main database which will eventually be deployed and which I use for all kind of tests. Then I have for each person that plays around with my software (for testing purposes or other) an additional copied database.

During development, I often need to correct some views or/and stored procedures which I update on my database and then retest. As soon as I’m happy with the changes, I need to also make my ‘testers’ happy and provide them with the latest version. I wrote a little script extra for that purpose to make updating the other database views/stored procedures so much easier and quicker.

use tester_x_db;
DECLARE @row int = 1;
DECLARE @sp varchar(8000);
DECLARE @maxViews int = 
    (SELECT COUNT(*) FROM my_db.INFORMATION_SCHEMA.VIEWS);
WHILE @row <= @maxViews
BEGIN
    SELECT @sp=REPLACE(VIEW_DEFINITION, 'CREATE', 'ALTER') FROM (
        SELECT ROW_NUMBER() OVER (ORDER BY TABLE_NAME ASC) AS 
            rownumber,VIEW_DEFINITION
	    FROM my_db.INFORMATION_SCHEMA.VIEWS
	) AS tmp
    WHERE rownumber = @row;
    EXEC (@sp);
    SET @row = @row + 1;
END

DECLARE @maxRoutines int = 
    (SELECT COUNT(*) FROM my_db.INFORMATION_SCHEMA.ROUTINES);
SET @row = 1;
WHILE @row <= @maxRoutines
BEGIN
    SELECT @sp=REPLACE(ROUTINE_DEFINITION, 'CREATE', 'ALTER') FROM (
	SELECT ROW_NUMBER() OVER (ORDER BY ROUTINE_NAME ASC) AS 
            rownumber,ROUTINE_DEFINITION
	    FROM my_db.INFORMATION_SCHEMA.ROUTINES
	 ) AS foo
    WHERE rownumber = @row;
    EXEC (@sp);
    SET @row = @row + 1;
END

OpenGL with MFC ‘Hello world’ tutorial

For my first ‘Hello World’ program, I decided to use OpenGL with MFC since I’ve created OpenGL apps with just glew and freeglut before and there are lots of tutorials on the net for just that. I just wanted to know how to integrate OpenGL in an SDI MFC app and it turned out to be quite easy.

I’ve written a few starter OpenGL programs in the past but never really continued studying it for very long. This time, my goal is to actually finish the 3D Computer Graphics Using OpenGL YouTube series by Jamie King.

Jamie’s videos are awesome since he is really good in explaining things. The nice thing about YouTube tutorials comparing to real-life lessons is that you can fast forward when a subject is already known or repeat a section when you didn’t pay attention or just didn’t quite get it.

I’m also using other sources for studying OpenGL. I’m going to use the book ‘OpenGL Programming Guide’ by Dave Shreiner and Graham Sellers as a reference book. Furthermore, I’m going to read through Introduction to Computer Graphics material. Last but not least, I just recently found the ‘OpenGL & Vulkan’ podcast by Kai Niklas. That podcast is perfect to listen to while I play with my son.

Why am I interested in OpenGL? During university and years after, I haven’t really paid much attention to computer graphic design. I mean there was a reason I specialized in embedded systems. After years of microcontroller programming, I started getting a bit bored with it. I still enjoy it, but I just started missing the beauty of object oriented programming languages.

Then I started programming in GDI+ which I actually began to enjoy a lot. Now, I feel like I really want to get deeper into the guts of 2D and 3D graphics, which means OpenGL.

In this series, I’d like to document my OpenGL programming progress and also link to my created programs in github.

I’ve used following sites to guide me create my first MFC OpenGL program:

  • For GLEW and freeglut installation, I followed the ‘Installing freeglut’ and ‘Install GLEW’ guides in ‘Introduction to Computer Graphics’ installation guide.
  • Instead of using the OpenGL helper classes/functions freely accessible from the course site above, I decided to use the GLRenderer class from opengl.org.
  • Now, all I needed to do was call several GLRenderer functions from my SDI view class. I created message handlers for
    • WM_CREATE
    • WM_ERASEBKGND
    • WM_SIZE
    • WM_DESTROY

    and also overloaded OnInitialUpdate().

The code for this first program can be found in github.

For this first program, I wasn’t really concerned about the drawing functionality. My goal was to just have a basic OpenGL with MFC skeleton for future programs.

My impression of Canadian Christmas markets

I’m living for about 7 years in Canada now and I haven’t visited any Christmas markets up until a couple weeks ago. I’m from Austria where we have awesome Advent markets (if you’ve never been in Austria, I’d suggest visiting it anytime between middle of November and end of December – in my opinion the best time to visit – apart from it being a bit cold and you’ll likely search for the sun without successful) and I figured it’s time to visit some markets over here.

Every year around this time, I miss home a lot. Walk through Vienna and you don’t only see the all-year-around beautiful architecture, but also awesome Christmas lights, stands with hot drinks and my absolute favorite, hot chestnuts. This year, I decided to give Canadian Christmas markets a chance. It’s kind of weird, but apparently lots of Canadians don’t ever visit these markets here. My husband has never been at one before and I’ve met many people here that haven’t either.

We’ve visited a smaller Christmas market in a nearby city and a week after a big one with about 200 stands. I was actually positively surprised. I really like that at those markets you see mostly local sellers and you find a lot of nice stuff. Unfortunately, you pay entry for many markets (the ones we went to, but there are also free ones). On the one side, I understand that it costs a lot of money to have those markets inside (since honestly, who wants to be surprised by -20 degrees Celsius or worse outside), but on the other side, it prevents people to visit those markets more than once a year.

The whole family enjoyed the trips (especially to the big one), but it wasn’t quite the same as at home. I asked my husband, why he didn’t enjoy it quite that much and he stated that Austrian Advent markets are very social events. You pretty much always meet friends at those markets, walk a bit through, drink a few hot wines to warm up (not the best if you’re on a diet considering the amount of sugar in them, but they are just delicious), maybe have hot chestnuts as a snack and chat for a few hours.

I remember, I used to spend frequently time at the market in front of the university with a few colleagues. We drank one, two hot wines and then we walked to the math tutorial. It didn’t make it more fun, but at least a bit more bearable (I do enjoy math, but those tutorials were definitely hardcore).

Nevertheless, I’m planning to visit more markets over here in the coming years. They aren’t what I’m used to but some of them are definitely worth visiting.