Repost: Negative File Size

December 22, 2015 · Posted in Fun Things · Comment 

This is a repost of content from this blog before I decided to take down the existing content and start from scratch.

A couple of years ago, I was having trouble with a hard drive that did not want to function the way it was supposed to. Some data was lost, and some of it I was able to recover using file recover tools.

However, the files it recovered had some curious issues. Aside from being corrupted, some files seemingly gained the capability to store millions of terabytes of information inside them:

File size: 4.44659e-323 bytes

This is also a good example of why I think strongly defining data types is important: it would prevent strange appearances like this (along with all the potential problems that such a file might cause because no other code expects to ever see such a thing). If the developers at Microsoft had chosen to use an unsigned integer to handle file sizes (rather than blindly grabbing an int) — after all, a file can never be less than zero bytes in size — things like this could simply not happen.

Programming Linguistics #3 — Functional Functionality

December 15, 2015 · Posted in Programming Linguistics · Comment 

Part two of this series went into a few things about the compilation process, modules, and established some of the basic data types and operators that our little programming language would have. In part 3, we’re looking at namespaces and functions.

As I’ve stated in part 1, my hypothetical language would be object-oriented. To me, it only seems natural that this is a thing, because any kind of usable data doesn’t limit itself to one or two variables. Instead, it consists of many variables grouped together into logical structures. The first thing that people try to do in a purely functional language is figure out a way to represent their data structures, and what you end up with is typically something similar to an object-oriented approach, but a lot less pretty.

Read more

Programming Linguistics #2 — Second Things… Second?

December 8, 2015 · Posted in Programming Linguistics · Comment 

In the first post of this series, I started outlining some of the basic underlying concepts of a programming language if I were to design and build it. In part 2, we’ll be looking at the first little glimmers of actual code!

If you’re familiar with languages like C or C++, you’ll understand the concept of header files. In languages like these, header files contain definitions for variables, types, classes, and functions, which are then implemented in source files. Other source files that would like to make use of the things defined somewhere else include just that header file to get the definitions, leaving it up to the linker to actually piece things together.

When you look at how compilers for these languages work, it’s understandable why a mechanism like this is needed. If you were to simply include the full implementation of a class or function in each source file that needed it, it’d take a lot longer to compile the project, and the linker is left with dozens of copies of the same code, not knowing which one to actually use. But especially if you’re not a seasoned programmer, understanding why header files are needed, how to write them, and what things belong in which file, can be very confusing subjects. And dealing with things that depend on eachother can quickly become a nightmare even for experienced developers.

Does it really need to be that difficult?

I think not.

Read more

PHP date()-style formatting for JavaScript

December 1, 2015 · Posted in Bits & Bobs · Comment 

If you’ve ever had to work with the JavaScript Date object, you might have come accross the same problem that I had recently: formatting dates and times in a nice way is difficult to do. The options you get for producing date and time strings are limited, at best: aside from a few predefined, not very pretty formats, no functions are provided at all for this type of thing.

At the other end of the spectrum, PHP provides a function called date(), which takes a format string somewhat reminiscent of printf-type functions, along with a Unix timestamp, and provides a wide variety of options for formatting dates and times to your heart’s content. So I figured, why not take that concept to JavaScript?

Read more

Programming Linguistics #1 — First Things First

December 1, 2015 · Posted in Programming Linguistics · Comment 

Programming is something I’ve been doing since I was in elementary school. Maybe back then it wasn’t quite what it was today — but from a young age I’ve started experimenting with making computers do the things I’d like them to do. For one of the first things I’ve ever tried, I started out crafting batch files that used all kinds of weird hackery to accomplish simple tasks. I slowly moved into HTML, a little bit of JavaScript and after some time gradually learned to write PHP (I only learned about CSS later on because at the time, CSS didn’t even exist yet).

As the years passed I’ve learned plenty of other languages. I still do a lot of PHP, but I also like using C/C++ (which, despite their similarities, are also very different languages). But, as with most things, over time things have started to bother me about the tools I use — and invariably, sooner or later the thought comes up — “I could do better”.

Read more

« Previous PageNext Page »

A Soul Waking