My husband and my daughter are talking about their respective fantasy worlds. My daughter's is based on Marvel Comics and includes a heavy dose of magic and mythology, as well as a superpowered character she identifies with.
My husband does not have a hero whom he identifies with and his world is full of interesting alien races based on scientific speculation. He does not include magic and includes a lot of adult politcal cynicism. It is assuming to see my daughter mix her creations with my husband's. If an adult mixed magic with my husband's science fiction, it would be butchery, but I'm enjoying my daughter's fluid, though still immature imagination.
Weird stuff, generally tied into writing genre fiction. The tech industry and things relating to parenting will come up ocassionally.
Tuesday, December 14, 2010
Friday, December 3, 2010
Men and Violence -- Writing Escapist Heroes
The other day I read an article on Science Daily suggesting that some kind of female animal, I forget which, loses interest in males who lose fights. Their was a suggestion that human females would feel the same way. For writers the implication would be that to be attractive to female readers, a male hero should never lose a physical fight.
Though I've been attracted to men who I imagined were skilled fighters, I think that human females are a little bit more complicated than this, at least when they are sober. In popular fiction, male heroes can be skilled fighters, but two other intertwined qualities are also important.
The first is having good judgement in stressful situations. The hero shouldn't be an idiot who would charge a tank with a sword, no matter what crimes the tank driver has committed. A writer can even get a little sexist and have the hero's love interest test him by suggesting doing something dangerous. The hero should be able to refuse her. He comes across as a better man if anger, fear and lust are not able to truly corrupt his judgment.
The second quality is honor. While he needn't be and probably shouldn't be a virgin milquetoast goody-goody, he should have some lines that he won't cross. He can drink, swear, and get into some avoidable fights, but he should show fidelity to a personal code, even at some cost to himself.
No doubt men and women who have acted heroically in real life might find the above somewhat silly. After all, a real hero is often an ordinary person who did the best he or she could do in extraordinary circumstances, but I am trying to describe a type of male character that would be entertaining for me to read about, not to dissect real life heroism.
Though I've been attracted to men who I imagined were skilled fighters, I think that human females are a little bit more complicated than this, at least when they are sober. In popular fiction, male heroes can be skilled fighters, but two other intertwined qualities are also important.
The first is having good judgement in stressful situations. The hero shouldn't be an idiot who would charge a tank with a sword, no matter what crimes the tank driver has committed. A writer can even get a little sexist and have the hero's love interest test him by suggesting doing something dangerous. The hero should be able to refuse her. He comes across as a better man if anger, fear and lust are not able to truly corrupt his judgment.
The second quality is honor. While he needn't be and probably shouldn't be a virgin milquetoast goody-goody, he should have some lines that he won't cross. He can drink, swear, and get into some avoidable fights, but he should show fidelity to a personal code, even at some cost to himself.
No doubt men and women who have acted heroically in real life might find the above somewhat silly. After all, a real hero is often an ordinary person who did the best he or she could do in extraordinary circumstances, but I am trying to describe a type of male character that would be entertaining for me to read about, not to dissect real life heroism.
Arsenic Based Life?
Yesterday their was a NASA press release about a bacteria that uses arsenic as part of its DNA. This doesn't really mean that it is based on arsenic, like every other life form on earth it relies of the ability of carbon atoms to form four strong covalent bonds. Instead what is truly interesting is that by using arsenic instead of phosphorus in the backbone of its DNA the bacteria is performing a biochemical trick that nobody ever realized was possible.
The implication for science fiction that is that while realistic aliens will be limited in what they can do by basic physical laws, the details of there metabolisms would be impossible to predict. What we see as toxic minerals or dangerous industrial chemical waste might be lunch for them.
The implication for science fiction that is that while realistic aliens will be limited in what they can do by basic physical laws, the details of there metabolisms would be impossible to predict. What we see as toxic minerals or dangerous industrial chemical waste might be lunch for them.
Wednesday, November 24, 2010
Education -- Some Rambling Thoughts
There is an endless drumbeat on how people in the US need to be better educated. I'm not arguing that education isn't good, but I question the ability of education to help us compete in world markets.
Obviously, if everybody in the US had mathematical skills equivalent to John Von Neuman, a key designer of both the hydrogen bomb and the modern computer, we would have something to sell abroad. However, I don't believe that any type of education could reliably produce that kind of genius unless it also involved some type of invasive brain modifying technology.
Also, though he sufficient social skills to be able to marry and raise a family, he also had some foolish habits such as attempting to drive and read at the same time.
I think that education, while it must be partially aimed at employability, must really be aimed at equipping average people with what they need to live a good life as mature human beings. This means, though I don't knock regimentation and drill, that students cannot spend all of their time studying academic skills, as for many people these will not be the most important aspects of their adult lives.
Ultimately, I fear the problem of what and how to teach can be addressed narrowly in a scientific way. For instance, we can learn, though controlled trials, how best to teach arithmetic. However, in a broad sense it is too large and value laden to ever be perfectly addressed. In particular, national competitiveness seems to be a wrong standard. If my children are reasonably happy and healthy than I simply don't care about whether they or children in China are the best ones at Calculus.
Obviously, if everybody in the US had mathematical skills equivalent to John Von Neuman, a key designer of both the hydrogen bomb and the modern computer, we would have something to sell abroad. However, I don't believe that any type of education could reliably produce that kind of genius unless it also involved some type of invasive brain modifying technology.
Also, though he sufficient social skills to be able to marry and raise a family, he also had some foolish habits such as attempting to drive and read at the same time.
I think that education, while it must be partially aimed at employability, must really be aimed at equipping average people with what they need to live a good life as mature human beings. This means, though I don't knock regimentation and drill, that students cannot spend all of their time studying academic skills, as for many people these will not be the most important aspects of their adult lives.
Ultimately, I fear the problem of what and how to teach can be addressed narrowly in a scientific way. For instance, we can learn, though controlled trials, how best to teach arithmetic. However, in a broad sense it is too large and value laden to ever be perfectly addressed. In particular, national competitiveness seems to be a wrong standard. If my children are reasonably happy and healthy than I simply don't care about whether they or children in China are the best ones at Calculus.
Wednesday, November 10, 2010
Who Doesn't Have To Worry?
Sixty Minutes did a recent story on unemployment in Silicon Valley. Some discussion boards are full of American software engineers complaining that Indians, from the subcontinent not the Navaho Reservation, are taking their jobs. There's a trend to advise young people to go into medicine or law rather than computing.
Several things have contributed to this and offshoring and immigration being only one of many. First, during the dot com bubble more people got into computing than the field could absorb. Second, there is a lot of good software available all ready. Consider, in the mid eighties, someone working for a small business might need a program written to pull data out of a DBase database and perform some analysis on it. Today, the same data would likely be kept in Excel format and easily analyzed by the same person who generated it. The code to do so is already present in Excel and doesn't have to be written by someone else.
This use of building blocks constructed by others even extends to entertainment software. Take Second Life, for instance, Linden Research didn't develop code to simulate physics within their virtual world instead they used the Havoc Physics Engine. While integrating Havoc with the rest of their technology was probably hard, it was likely easier than writing their own physics engine from scratch.
In science, also, there are excellent pre-written tools. Scientists don't need to write or hire someone to write code for storing DNA sequences, they use MySQL. They also often don't need code written to extract specific statistics from their experimental data. Those algorithms are likely to be available as part of numerous statistics packages, including free packages such as R.
So, who doesn't have to worry? The answer for me would be people who work at a high level in computer security as they have human opponents who are always trying to come up with new ways to exploit the internet for ill-gotten gains, software architects with a track record of successful projects, and, in some cases, people with specialized skills such as working with embedded systems. The problem is that you can't just go school to land of these jobs. Everybody I've talked to with such skills has been very smart. My expectation is that at the highest levels software will still be a very good field to be in even in the United States, but that if you are not one of the smartest people around you will trouble making a long term career of it.
As very smart people who are interest in computers rather than something else are relatively rare, despite existence of many average programmers who have less work than they want, companies will still find themselves paying more than they'd like for the kind of talent they need. Thus, I expect both most programmers and many employers of programmers to be dissatisfied with the market for some time to come.
Several things have contributed to this and offshoring and immigration being only one of many. First, during the dot com bubble more people got into computing than the field could absorb. Second, there is a lot of good software available all ready. Consider, in the mid eighties, someone working for a small business might need a program written to pull data out of a DBase database and perform some analysis on it. Today, the same data would likely be kept in Excel format and easily analyzed by the same person who generated it. The code to do so is already present in Excel and doesn't have to be written by someone else.
This use of building blocks constructed by others even extends to entertainment software. Take Second Life, for instance, Linden Research didn't develop code to simulate physics within their virtual world instead they used the Havoc Physics Engine. While integrating Havoc with the rest of their technology was probably hard, it was likely easier than writing their own physics engine from scratch.
In science, also, there are excellent pre-written tools. Scientists don't need to write or hire someone to write code for storing DNA sequences, they use MySQL. They also often don't need code written to extract specific statistics from their experimental data. Those algorithms are likely to be available as part of numerous statistics packages, including free packages such as R.
So, who doesn't have to worry? The answer for me would be people who work at a high level in computer security as they have human opponents who are always trying to come up with new ways to exploit the internet for ill-gotten gains, software architects with a track record of successful projects, and, in some cases, people with specialized skills such as working with embedded systems. The problem is that you can't just go school to land of these jobs. Everybody I've talked to with such skills has been very smart. My expectation is that at the highest levels software will still be a very good field to be in even in the United States, but that if you are not one of the smartest people around you will trouble making a long term career of it.
As very smart people who are interest in computers rather than something else are relatively rare, despite existence of many average programmers who have less work than they want, companies will still find themselves paying more than they'd like for the kind of talent they need. Thus, I expect both most programmers and many employers of programmers to be dissatisfied with the market for some time to come.
Tuesday, November 9, 2010
Let's Forget about UIs For Now -- Opensim
I was going to post about Java Swing as a UI frame work but I got bored with that. Instead I worked on getting an instance of OpenSimulator running on my Mac Pro.
I used use Secondlife, the virtual world developed by Linden Research, a good bit. I am not particularly interested in online role playing in any form, although I used to do table top, and buying tons of virtual clothes doesn't interest me that much, though I admire the artistry behind them.
I enjoyed the surrealism of SL and wanted to find out what went on behind the scenes to make a virtual world work. I quickly learned the basic techniques for building objects out of secondlife primitives and perused the SL Wiki to learn about the basic structure of Linden Scripting Language (LSL) scripts.
I then hit a bit of a wall. To make good looking content you have to be able to upload your own textures and animations into Second Life. Doing this requires making a micropayment to Linden Labs, something I didn't want to do. Also, my children, God bless them, discovered how to use my account to buy virtual goods, something I didn't want.
I probably could have come with a better use of my time, but to be able to privately develop Secondlife content, I decided to load OpenSimulator, an open source package providing similar functionality on to my machine. The first problem with this was that OpenSimulator is written in C# a Microsoft developed language not native to the Macintosh. Now, C#, like Java, compiles not to native machine code, but instead to code for a virtual machine that runs on top of the native hardware.
To run this on a Macintosh, the OpenSimulator web site suggested, you need a program called mono to act as an interpreter for the compiled C# code. I downloaded and installed this and then downloaded an OpenSimulator tar ball. Once I extracted OpenSimulator from the tar ball and tried to run it, it failed, something not unexpected with open source software, which typically doesn't provide a lot of handholding.
Digging around in the opensim.ini configuration file and the OpenSimulator wiki, I discovered the reason for this. OpenSimulator like most modern software uses a relational database to store all sorts of information. Out of the box it was configured to use the SQLite database, the same one provided in IPhones and Droid smart phones.
A version of of SQLite does come with MacOS, however, OpenSimulator is not compatible with it out of the box. The three choices available were to, configure it work with the older version on the Mac, upgrade my Mac's SQLite software, or install MySQL, an open source database widely used in industry to store small to medium amounts of data. As I'd worked with MySQL before, I chose that route. Along the way I found out that though MacOS Server has MySQL installed out of the box, vanilla MacOS does not. Fortunately, it was easy enough to install from the MySQL website.
Since OpenSimulator seemed to want to log in to a database named opensim under MySQL, I created this and also created an account under MySQL with all privileges for that database. After more futzing around with OpenSimulator configuration I was able to get two regions, a few square miles of virtual land, up and running. What will I do with it, I'm not sure yet.
I used use Secondlife, the virtual world developed by Linden Research, a good bit. I am not particularly interested in online role playing in any form, although I used to do table top, and buying tons of virtual clothes doesn't interest me that much, though I admire the artistry behind them.
I enjoyed the surrealism of SL and wanted to find out what went on behind the scenes to make a virtual world work. I quickly learned the basic techniques for building objects out of secondlife primitives and perused the SL Wiki to learn about the basic structure of Linden Scripting Language (LSL) scripts.
I then hit a bit of a wall. To make good looking content you have to be able to upload your own textures and animations into Second Life. Doing this requires making a micropayment to Linden Labs, something I didn't want to do. Also, my children, God bless them, discovered how to use my account to buy virtual goods, something I didn't want.
I probably could have come with a better use of my time, but to be able to privately develop Secondlife content, I decided to load OpenSimulator, an open source package providing similar functionality on to my machine. The first problem with this was that OpenSimulator is written in C# a Microsoft developed language not native to the Macintosh. Now, C#, like Java, compiles not to native machine code, but instead to code for a virtual machine that runs on top of the native hardware.
To run this on a Macintosh, the OpenSimulator web site suggested, you need a program called mono to act as an interpreter for the compiled C# code. I downloaded and installed this and then downloaded an OpenSimulator tar ball. Once I extracted OpenSimulator from the tar ball and tried to run it, it failed, something not unexpected with open source software, which typically doesn't provide a lot of handholding.
Digging around in the opensim.ini configuration file and the OpenSimulator wiki, I discovered the reason for this. OpenSimulator like most modern software uses a relational database to store all sorts of information. Out of the box it was configured to use the SQLite database, the same one provided in IPhones and Droid smart phones.
A version of of SQLite does come with MacOS, however, OpenSimulator is not compatible with it out of the box. The three choices available were to, configure it work with the older version on the Mac, upgrade my Mac's SQLite software, or install MySQL, an open source database widely used in industry to store small to medium amounts of data. As I'd worked with MySQL before, I chose that route. Along the way I found out that though MacOS Server has MySQL installed out of the box, vanilla MacOS does not. Fortunately, it was easy enough to install from the MySQL website.
Since OpenSimulator seemed to want to log in to a database named opensim under MySQL, I created this and also created an account under MySQL with all privileges for that database. After more futzing around with OpenSimulator configuration I was able to get two regions, a few square miles of virtual land, up and running. What will I do with it, I'm not sure yet.
Thursday, October 7, 2010
How to actually make things run
My example code has been in C and Java, however I've not said how to get a computer to run either a C or a java program.
To run java code you first place it in a file with the extension ".java" on the end.
This file must contain one and only one class declared public and that class must contain a method named main which is declared like this:
The file also must contain a package declaration at the top like:
Once you have these, you call the java compiler, either through using the build menu item in eclipse or on the command line. If you use the command line, you type "javac yourfile." If your program compiles without errors, the compiler will produce a directory with the name declared in your package declaration. Inside this directory their will be a file with the extension ".class" and the same base name as your original file. To run it, type "java PackageName/yourfile." Do not use any extension with name of the file you want to run.
With C you must have a main function. As pure C is not object oriented the main function is not part of any object. The incantation for compiling your file varies. If you are using GNU C on the command line, it is gcc filename. If your file is error free the compiler will produce a file called "a.out" in the same directory your source file was in. To run it, just type "./a.out" and away you go.
Now you may wonder what good all this does, after all I've given no way to get output from your code. I've delayed this longer than I should have because I wanted to discuss library routines and input and output at the same time.
To have your program print anything, you need to include or import prewritten code that does output for you. How does that code work? It directly manipulates the hardware interfaces connected to your screen and keyboard. Writing it is both highly specialized and fairly tedious for most people, which is why if you aren't an embedded systems hacker you usually don't bother with it.
Anyway the library used for input and output in C is called stdio. To gain access to it you use a preprocessor directive. The particular directive is
Which means get the file called "stdio.h" from one of a few standard places. You can use this include other libraries such as the C Math library. Included in stdio are definitions for the C functions printf and scanf. Printf is used like
The first argument to the printf function is called the format string. %d means insert an integer value into the format string. The "&" in front of the variable dogs, means that we are passing it's address rather than it's value into printf, another example of a C pointer.
In Java output is a little easier. Instead of using a format string you would just type
System.out.println(dogs," silly dogs played with the ball\n");
The "\n" used in both examples is just a sign for a carriage return.
Now, while raw text output is perfectly good for some things like program logs, most programs written today have other, more intuitive, ways of interacting with a user. How to make a GUI, a graphical user interface will be discussed in my next post.
To run java code you first place it in a file with the extension ".java" on the end.
This file must contain one and only one class declared public and that class must contain a method named main which is declared like this:
public static void main(String args[])
The file also must contain a package declaration at the top like:
package MySillyJavaPackage;
Once you have these, you call the java compiler, either through using the build menu item in eclipse or on the command line. If you use the command line, you type "javac yourfile." If your program compiles without errors, the compiler will produce a directory with the name declared in your package declaration. Inside this directory their will be a file with the extension ".class" and the same base name as your original file. To run it, type "java PackageName/yourfile." Do not use any extension with name of the file you want to run.
With C you must have a main function. As pure C is not object oriented the main function is not part of any object. The incantation for compiling your file varies. If you are using GNU C on the command line, it is gcc filename. If your file is error free the compiler will produce a file called "a.out" in the same directory your source file was in. To run it, just type "./a.out" and away you go.
Now you may wonder what good all this does, after all I've given no way to get output from your code. I've delayed this longer than I should have because I wanted to discuss library routines and input and output at the same time.
To have your program print anything, you need to include or import prewritten code that does output for you. How does that code work? It directly manipulates the hardware interfaces connected to your screen and keyboard. Writing it is both highly specialized and fairly tedious for most people, which is why if you aren't an embedded systems hacker you usually don't bother with it.
Anyway the library used for input and output in C is called stdio. To gain access to it you use a preprocessor directive. The particular directive is
#include<stdio.h>
Which means get the file called "stdio.h" from one of a few standard places. You can use this include other libraries such as the C Math library. Included in stdio are definitions for the C functions printf and scanf. Printf is used like
printf("%d silly dogs played with the ball\n",&dogs);
The first argument to the printf function is called the format string. %d means insert an integer value into the format string. The "&" in front of the variable dogs, means that we are passing it's address rather than it's value into printf, another example of a C pointer.
In Java output is a little easier. Instead of using a format string you would just type
System.out.println(dogs," silly dogs played with the ball\n");
The "\n" used in both examples is just a sign for a carriage return.
Now, while raw text output is perfectly good for some things like program logs, most programs written today have other, more intuitive, ways of interacting with a user. How to make a GUI, a graphical user interface will be discussed in my next post.
Monday, October 4, 2010
Who can see data?
Now one way to program in C is to put all the data outside of your methods, called functions in plain vanilla C. To do this C you write a bunch of declarations like:
By doing this you are declaring what are called global variables. These can be accessed by any function declared in the same file of program code and ,if certain conventions are followed, also by functions declared in other files. At first glance this seems like a good idea, as it easy to pass data between your functions, but it has pitfalls. Without going over the code with a fine tooth comb it's impossible for someone reading your code to know if a particular function alters a particular global.
One way to deal with this is to declare local variables:
In this pointless snippet of code a,b, and c are all local variables
in AverageThem. Outside of AverageThem those particular storage locations are not associated with the names a,b, and c or the type int. In fact a,b, and c are recreated every time the computer executes the AverageThem function. In C you can declare local variables in every block. A block is anything between two curly "{}" brackets so
First prints a "3" and then a "2."
Now suppose you have a different function:
Because this function will behave badly if Greeting is longer than fifty characters or is not terminated by a NULL character don't copy it. However, it illustrates the use of the keyword static what static does is cause the value stored in the string CurrentGreeting to persist between in invocations of GreetUser and only change if a non-null pointer is past to the function.
What is this pointer thingy which hasn't been mentioned before? It's a variable which, instead of storing a numerical, character, or object value, stores the location of that value. In C an array is equivalent to a constant pointer. While pointers are useful, and are used a lot C programs, I intend to use C examples to illustrate programming with C-like languages in general so I won't go into C pointers in detail. Puts and strcpy are simply C library functions. They, again, have certain problems and would probably not be used by a contemporary programmer, I'm just using them here for simplicity's sake.
Now object oriented languages have a different approach to deciding who can see information and who can't. While they still have local,global,and static variables. The creator of an object gets to pick what fields and methods are visible to other code. To do this a C++ or Java programmer uses the keywords private,public, and protected.
For example in my last post I created class PetRecord
The public modifier means that any method could contain a call GetOwner and the other methods I defined. It doesn't whether that method is part of class PetRecord or not. The data fields, however aren't declared public. Therefore they can only be seen by methods that are part of the same Java package as PetRecord. If you don't want anything outside of PetRecord to see them a better choice might be to declare them private.
I have no static methods or fields in the version of PetRecord above. Let's add one.
The method I added, called a constructor initializes a PetRecord at the time one is created. The variable PetCount is also incremented. Why do this? Because PetCount is a static variable there is one PetCount shared between all instances of the PetCount class. By incrementing it, we can keep a count of the number of pets we have.
There are also a protected access specifier in Java and C++, but it isn't used as much as public or private.
In my next post I'm going to back up from the micro-level stuff I've been discussing and talk about how you can actually get programs to compile and produce output.
int age;
double temperature;
char Name[20] = "Maria\0";
By doing this you are declaring what are called global variables. These can be accessed by any function declared in the same file of program code and ,if certain conventions are followed, also by functions declared in other files. At first glance this seems like a good idea, as it easy to pass data between your functions, but it has pitfalls. Without going over the code with a fine tooth comb it's impossible for someone reading your code to know if a particular function alters a particular global.
One way to deal with this is to declare local variables:
int AverageThem(int a, int b)
{
int c;
c = (a + b)/2;
return c;
}
In this pointless snippet of code a,b, and c are all local variables
in AverageThem. Outside of AverageThem those particular storage locations are not associated with the names a,b, and c or the type int. In fact a,b, and c are recreated every time the computer executes the AverageThem function. In C you can declare local variables in every block. A block is anything between two curly "{}" brackets so
main()
{
int a = 2;
{ int a = 3;
printf("%d\n",a);
}
printf("%d\n",a);
}
First prints a "3" and then a "2."
Now suppose you have a different function:
GreetUser(char *Greeting)
{
static char CurrentGreeting[50];
if (Greeting != NULL) {
strcpy(CurrentGreeting,Greeting);
}
puts(CurrentGreeting);
}
Because this function will behave badly if Greeting is longer than fifty characters or is not terminated by a NULL character don't copy it. However, it illustrates the use of the keyword static what static does is cause the value stored in the string CurrentGreeting to persist between in invocations of GreetUser and only change if a non-null pointer is past to the function.
What is this pointer thingy which hasn't been mentioned before? It's a variable which, instead of storing a numerical, character, or object value, stores the location of that value. In C an array is equivalent to a constant pointer. While pointers are useful, and are used a lot C programs, I intend to use C examples to illustrate programming with C-like languages in general so I won't go into C pointers in detail. Puts and strcpy are simply C library functions. They, again, have certain problems and would probably not be used by a contemporary programmer, I'm just using them here for simplicity's sake.
Now object oriented languages have a different approach to deciding who can see information and who can't. While they still have local,global,and static variables. The creator of an object gets to pick what fields and methods are visible to other code. To do this a C++ or Java programmer uses the keywords private,public, and protected.
For example in my last post I created class PetRecord
public class PetRecord {
Date Birthday;
String Name;
String OwnerLastName;
Date RabiesDue;
public void UpdateRabiesDue(Calendar LastShot);
public String GetOwner() {return OwnerLastName;}
public void SetOwner(String NewOwner);
};
The public modifier means that any method could contain a call GetOwner and the other methods I defined. It doesn't whether that method is part of class PetRecord or not. The data fields, however aren't declared public. Therefore they can only be seen by methods that are part of the same Java package as PetRecord. If you don't want anything outside of PetRecord to see them a better choice might be to declare them private.
I have no static methods or fields in the version of PetRecord above. Let's add one.
public class PetRecord {
Date Birthday;
String Name;
String OwnerLastName;
static integer PetCount = 0;
Date RabiesDue;
public void UpdateRabiesDue(Calendar LastShot);
public String GetOwner() {return OwnerLastName;}
public void SetOwner(String NewOwner);
public PetRecord(String theOwner,String theName) {
Owner = theOwner;
Name = theName;
PetCount = PetCount + 1;
}
};
The method I added, called a constructor initializes a PetRecord at the time one is created. The variable PetCount is also incremented. Why do this? Because PetCount is a static variable there is one PetCount shared between all instances of the PetCount class. By incrementing it, we can keep a count of the number of pets we have.
There are also a protected access specifier in Java and C++, but it isn't used as much as public or private.
In my next post I'm going to back up from the micro-level stuff I've been discussing and talk about how you can actually get programs to compile and produce output.
Friday, October 1, 2010
More About Data And A Bit About Methods
In my last post I had something called 'a'. 'a' was a variable. In computing, unlike math, a variable is not a name for an unknown quantity, instead in denotes a particular location in the computers memory. What a variable can contain depends on the the language you are programming in.
In strongly typed languages, such as C and Java, you tell must declare your variables, telling the computer what kind of thing it will contain before you use it. You can also define a variable when you declare it, setting it's initial contents to what you want it to be. For example:
One can also declare variables to hold text data as well numbers. In C one would do so with the lines like:
In the second example C is an array, chunk of several consecutive memory locations. The [10] tells the C compiler to reserve enough memory for ten alphanumeric characters. The '\0' represents a null character necessary to tell some C functions that the character string is complete. The use of such special values was commonplace in the late 1960s when C was invented but these days is considered an obsolete approach.
So we have arrays, yay! Now what good are they actually? Well, with arrays one can program something like:
The stuff inside the "/* */" delimiters are comments, bits of text met to be read by humans that computer removes before processing the actual program code. By using arrays a programmer can elegantly have a computer repeated perform the same operation on large blocks of data.
But what if several different types of data should go together. In modern terms you use something called an object. Here's one, declared using Java rather than C syntax since plain, vanilla C, while still excellent for some purposes, doesn't really have objects.
Once you've defined a PetRecord, you can declare variables, including arrays of that type.
To access individual fields of a PetRecord, you'd write code like:
What in bleep are things with parentheses on the end? Getowner() and UpdateRabiesDue() are methods called functions in C. In Java every method is attached to a certain object of class of objects. This isn't the case in C or even C++ where standalone methods, called functions can be declared. What's special about methods is that the same method can be called with different parameters. For instance if Fluffykins is given to Mrs. Jones, because it urinated on the carpet too much at its old house you can call "Fluffykins.SetOwner("Jones");".
Now you may have noticed that the methods in my PetRecord class had the word "public" as part of their declarations. What exactly is that about? My next post will discuss the notions of scope and encapsulation.
In strongly typed languages, such as C and Java, you tell must declare your variables, telling the computer what kind of thing it will contain before you use it. You can also define a variable when you declare it, setting it's initial contents to what you want it to be. For example:
int a = 23;Now, in computer hardware numbers that humans would handle similarly can be handled very differently. Int means that the variable should contain an integer, a number with no fractional part. If the number must be capable of holding a fractional part, it should be declared as float or a double if you are using C or Java.
One can also declare variables to hold text data as well numbers. In C one would do so with the lines like:
char C = 'a';or
char C[10] = "Told ya!\0";Now we come to something more interesting. Why did I put '[10]' in the second line and '/0' at the end of "Told ya!\0"?
In the second example C is an array, chunk of several consecutive memory locations. The [10] tells the C compiler to reserve enough memory for ten alphanumeric characters. The '\0' represents a null character necessary to tell some C functions that the character string is complete. The use of such special values was commonplace in the late 1960s when C was invented but these days is considered an obsolete approach.
So we have arrays, yay! Now what good are they actually? Well, with arrays one can program something like:
/* Toy example, first 100 Fibbonaci numbers */
int fibs[100];
int index;
fibs[0] = 0; /* C array indices start with 0 not 1 */
fibs[1] = 1;
for(index = 2 ; index <= 100 ; index = index + 1) { fibs[index] = fibs[index - 1] + fibs[index -2]; }
The stuff inside the "/* */" delimiters are comments, bits of text met to be read by humans that computer removes before processing the actual program code. By using arrays a programmer can elegantly have a computer repeated perform the same operation on large blocks of data.
But what if several different types of data should go together. In modern terms you use something called an object. Here's one, declared using Java rather than C syntax since plain, vanilla C, while still excellent for some purposes, doesn't really have objects.
public class PetRecord {
Date Birthday;
String Name;
String OwnerLastName;
Date RabiesDue;
public void UpdateRabiesDue(Calendar LastShot);
public String GetOwner() {return OwnerLastName;}
public void SetOwner(String NewOwner);
};
Once you've defined a PetRecord, you can declare variables, including arrays of that type.
To access individual fields of a PetRecord, you'd write code like:
PetRecord Fluffykins;
Fluffykins.UpdateRabiesDue(Calendar.getInstance());
What in bleep are things with parentheses on the end? Getowner() and UpdateRabiesDue() are methods called functions in C. In Java every method is attached to a certain object of class of objects. This isn't the case in C or even C++ where standalone methods, called functions can be declared. What's special about methods is that the same method can be called with different parameters. For instance if Fluffykins is given to Mrs. Jones, because it urinated on the carpet too much at its old house you can call "Fluffykins.SetOwner("Jones");".
Now you may have noticed that the methods in my PetRecord class had the word "public" as part of their declarations. What exactly is that about? My next post will discuss the notions of scope and encapsulation.
Thursday, September 30, 2010
More On Programming
I learned programming in the nineteen seventies and nineteen eighties. Since then a lot has changed with the advent of graphical user interfaces and object oriented programming, but the basic constructs of procedural programming are still relevant.
The most basic operation is the assignment, usually denoted with an "=" sign. For instance in C,Java, Perl , and Python , the statement "a = 2 + 5" means stick the result of adding 2 and 5 into a memory location named "a."
Another of statement controls in what order pieces of your program are executed. C and C-like languages have several of these. "if..else", "while","do..while","for", and "switch" statements all exist.
If and switch statements are used to choose between two or more alternative paths of execution. For example:
While, do..while , and for statements are used to repeatedly execute a block of code until a certain condition is met. For example:
As you may have noticed all three looping constructs are more or less equivalent in meaning but in any given situation, one of the three is likely to be more intuitive than the others. Before the nineties, these constructs plus function calls and data aggregates , which I'll cover in my next post, were close to all there was to programming languages. Once I cover these basics, I'll start getting into more modern and maybe more interesting ideas, involving GUIs, object oriented programming, and event driven programing.
The most basic operation is the assignment, usually denoted with an "=" sign. For instance in C,Java, Perl , and Python , the statement "a = 2 + 5" means stick the result of adding 2 and 5 into a memory location named "a."
Another of statement controls in what order pieces of your program are executed. C and C-like languages have several of these. "if..else", "while","do..while","for", and "switch" statements all exist.
If and switch statements are used to choose between two or more alternative paths of execution. For example:
if (a <= TOO_BIG) {
a = a + result(a, do_some_stuff(a,b, uncertainty);
} else {
ErrLog.write("a too big\n");
clean_up()
}
switch(a) {
case 1: do_thing_1();
break;
case 2: do_thing_2();
break;
default:
}
While, do..while , and for statements are used to repeatedly execute a block of code until a certain condition is met. For example:
for (a = 0 ; a <= 10 ; a = a + 1) {
do_some_stuff();
}
a = 0;
while ( a <= 10) {
do_some_stuff();
a = a + 1;
}
a = 0;
do {
some_stuff();
a = a +1;
while ( a <= 10);
As you may have noticed all three looping constructs are more or less equivalent in meaning but in any given situation, one of the three is likely to be more intuitive than the others. Before the nineties, these constructs plus function calls and data aggregates , which I'll cover in my next post, were close to all there was to programming languages. Once I cover these basics, I'll start getting into more modern and maybe more interesting ideas, involving GUIs, object oriented programming, and event driven programing.
Wednesday, September 29, 2010
Multiple Strategies for Learning to Program on Your Own
Programming at a basic level is easy to learn on your own. There are many references on the Internet. Things I've done or heard about.
1. PostgreSQL is easy to download for all platforms, Oracle Express is free for download, and MySQL comes with MacOS. Why learn to use an SQL database? Because most systems use them to store persistent data.
2. Installing the optional XCode tools on a Mac is easy and gives you access to C, Objective C, C++, and Java compilers. For a few bucks you can get Apple's professional compiler and intregrated development environment (IDE.) Another IDE I've used Eclipse, which is again open source and have many useful features for Java development.
3. Even without XCode, Macs come with Python, Perl, and Ruby installed if you want to code in those languages.
4. Finally, one can program JavaScript in your browser itself.
All these tools can help you master the syntax and semantics of a programming language. Of course, once you know a language or languages you need also to learn the best ways of expressing ideas a programming language, tracking and fixing bugs, and testing your code. All go over some tools for that in another post.
1. PostgreSQL is easy to download for all platforms, Oracle Express is free for download, and MySQL comes with MacOS. Why learn to use an SQL database? Because most systems use them to store persistent data.
2. Installing the optional XCode tools on a Mac is easy and gives you access to C, Objective C, C++, and Java compilers. For a few bucks you can get Apple's professional compiler and intregrated development environment (IDE.) Another IDE I've used Eclipse, which is again open source and have many useful features for Java development.
3. Even without XCode, Macs come with Python, Perl, and Ruby installed if you want to code in those languages.
4. Finally, one can program JavaScript in your browser itself.
All these tools can help you master the syntax and semantics of a programming language. Of course, once you know a language or languages you need also to learn the best ways of expressing ideas a programming language, tracking and fixing bugs, and testing your code. All go over some tools for that in another post.
Some Basics
There are some basic things that everybody needs to know if they want to submit writing essentially anywhere.
1. Get the mechanics right. This one is hard for me as I seem to have some kind of attention disorder and consistently produce manuscripts with doubled words, typos, omitted words, and other mistakes. Despite the fact that it is tedious and hard, the struggle to produce clean copy is necessary.
2. Read the guidelines. Submitting work that's in the wrong format, is the wrong length, or with the wrong theme is a path to rejection.
3. If you write a book length manuscript get an agent. Not all published authors start with one but most successful authors acquire one.
4. Hardcopy self-publishing rarely works and is expensive. No one would look down on you for self publishing a chapbook of poetry, but outside of that it's not accepted.
5. Get a thick skin. Especially if you are just starting out multiple rejections are the norm.
1. Get the mechanics right. This one is hard for me as I seem to have some kind of attention disorder and consistently produce manuscripts with doubled words, typos, omitted words, and other mistakes. Despite the fact that it is tedious and hard, the struggle to produce clean copy is necessary.
2. Read the guidelines. Submitting work that's in the wrong format, is the wrong length, or with the wrong theme is a path to rejection.
3. If you write a book length manuscript get an agent. Not all published authors start with one but most successful authors acquire one.
4. Hardcopy self-publishing rarely works and is expensive. No one would look down on you for self publishing a chapbook of poetry, but outside of that it's not accepted.
5. Get a thick skin. Especially if you are just starting out multiple rejections are the norm.
Tuesday, September 28, 2010
Avoiding Science Howlers
How do avoid people throwing your book across the room because they have an issue with your science. First avoid the urge the proselytize for a fringe position. Avoid turning your story into an argument for the existence of immortal souls, intelligent design, the falsehood of climate change, the reality of extraterrestrial UFOs, or other fringe positions. Oddly, making any of these true in your fictional world won't cause problems for any reader but avoiding using your story as a soapbox to argue the truth of these propositions in the real world.
Second, know what you don't know. If you have an idea you want to use in a story think about and research it. One writer created a story based on the idea that all biochemical changes are reversible. Without that idea he had the makings of a good adventure, but he needed to come up with another device to do the work that idea was doing in his story since it is clearly silly.
Finally when you make stuff up, do so wildly. If characters nanotechnology then readers may balk at being used to summon ancestral spirits. If you go ahead and call it magic than most readers won't have a problem.
Second, know what you don't know. If you have an idea you want to use in a story think about and research it. One writer created a story based on the idea that all biochemical changes are reversible. Without that idea he had the makings of a good adventure, but he needed to come up with another device to do the work that idea was doing in his story since it is clearly silly.
Finally when you make stuff up, do so wildly. If characters nanotechnology then readers may balk at being used to summon ancestral spirits. If you go ahead and call it magic than most readers won't have a problem.
Monday, September 27, 2010
Women Priests
I've been reading a book by an American convert to Orthodox Christianity. He finds the Idea of women priests absurd and the existence of women priests in the Anglican Church is one of the reason he, as well as some other Orthodox converts I've known, has left the Anglican fold.
Now this puts me in a girlish snit, as I don't see why somebody with the same kind of body I have can't legitimately be a priest.
The question is, however you feel about the idea of women priests, can you use the idea in a story. If you are indifferent to religion, a woman who wanted to be a priest would seem as absurd as he would find her, though not ungodly. In a story written from an atheistic viewpoint such desires could be used to show a female character as power hungry, overly fascinated with religion, or simply immature.
In a story written from an Orthodox viewpoint one could use a desire to be a priest as an indication of a woman's spiritual immaturity. As she matures her ambitions could change, she could lose interest in religion, which from a Christian viewpoint would be a further fall, become a novice monastic, decide to marry someone and forget about the priesthood, or go though some other spiritual metamorphosis.
Another possibility, though not one an Orthodox Christian would consider correct would be for her to become a Pagan or Anglican priest. While Orthodox Christians wouldn't see this as at all positive, others would.
Depending on an author's beliefs, her or she can take the fairly simple idea that a woman wants to be a priest and run in several directions with it. Science and Science Fiction of course could add other wrinkles, for instance the woman could choose to be masculinized in her quest for ordination, or the woman could be an intersex. The key to a good story in a case like the one above which deals with a complex topics is to make all the characters complex. In a good story, the woman could not simply be an ungodly feminist and Orthodox tradition should not be presented as just mindless patriarchy.
Now this puts me in a girlish snit, as I don't see why somebody with the same kind of body I have can't legitimately be a priest.
The question is, however you feel about the idea of women priests, can you use the idea in a story. If you are indifferent to religion, a woman who wanted to be a priest would seem as absurd as he would find her, though not ungodly. In a story written from an atheistic viewpoint such desires could be used to show a female character as power hungry, overly fascinated with religion, or simply immature.
In a story written from an Orthodox viewpoint one could use a desire to be a priest as an indication of a woman's spiritual immaturity. As she matures her ambitions could change, she could lose interest in religion, which from a Christian viewpoint would be a further fall, become a novice monastic, decide to marry someone and forget about the priesthood, or go though some other spiritual metamorphosis.
Another possibility, though not one an Orthodox Christian would consider correct would be for her to become a Pagan or Anglican priest. While Orthodox Christians wouldn't see this as at all positive, others would.
Depending on an author's beliefs, her or she can take the fairly simple idea that a woman wants to be a priest and run in several directions with it. Science and Science Fiction of course could add other wrinkles, for instance the woman could choose to be masculinized in her quest for ordination, or the woman could be an intersex. The key to a good story in a case like the one above which deals with a complex topics is to make all the characters complex. In a good story, the woman could not simply be an ungodly feminist and Orthodox tradition should not be presented as just mindless patriarchy.
Friday, September 24, 2010
Geeky Gamer Stuff and Observations About Creating Secondary Worlds
I used to play role playing games and still have several game books. My most recent purchase is volume one of the sixth edition of the Hero System. From a while ago, I also have a d20 3.5 Player's Handbook. To entertain myself I've looked at converting a few 3.5 spells into hero system powers. For the most part, I've found doing so workable if you don't ask for 100% compatibility.
Back to writing. One thing that makes many game worlds seem a bit silly is the extent of magic powers characters develop and the fact that having so many spells and powers make's it difficult to give a game world a coherent flavor. Like in a superhero comic book, everything is true. Looking at monsters, rather than spells, you have dragons and gryphons which are inspired by heraldry and legend but you also have shambling mounds which have a much more twentieth century biological feel. Looking at character classes you have enough combinations of special powers to make one's head spin.
In writing fantasy or science fiction you really should avoid a lot of that. While you can have strange things that don't tie into anything else in the world in a way the reader or the characters understand, you need to keep control of such aspects of your world or risk it descending into incoherence. If your characters have magic powers, there should be a sense that limits to magic exist. Even if there are no real rules and a powerful adept could warp reality in any way he or she chooses, there should be interesting dangers and consequences involved in using powerful magic. You see this in the Lord of the Rings where both the Ring itself and the Palantiri had problems associated with there use.
Back to writing. One thing that makes many game worlds seem a bit silly is the extent of magic powers characters develop and the fact that having so many spells and powers make's it difficult to give a game world a coherent flavor. Like in a superhero comic book, everything is true. Looking at monsters, rather than spells, you have dragons and gryphons which are inspired by heraldry and legend but you also have shambling mounds which have a much more twentieth century biological feel. Looking at character classes you have enough combinations of special powers to make one's head spin.
In writing fantasy or science fiction you really should avoid a lot of that. While you can have strange things that don't tie into anything else in the world in a way the reader or the characters understand, you need to keep control of such aspects of your world or risk it descending into incoherence. If your characters have magic powers, there should be a sense that limits to magic exist. Even if there are no real rules and a powerful adept could warp reality in any way he or she chooses, there should be interesting dangers and consequences involved in using powerful magic. You see this in the Lord of the Rings where both the Ring itself and the Palantiri had problems associated with there use.
Thursday, September 23, 2010
A Beginner's Error in Writing
An error I've made and also seen in the work of other's is to have a tag-along character. This is a character, often the protagonist's husband or wife, who is there strictly to watch the action and comment on the protagonist's doings.
Because they don't actually do anything they are hard for the reader to sympathize with or even remember. There are two solutions to this. One is to have other character stay home and simply have the main character think about them. The other, obviously, is to give the tag-along something of his or her own to do. This doesn't mean the tag-along has to go fight the bad guys but he or or she should be portrayed as acting somewhat on their own.
A good example of a well done secondary character is Abigail Adams in the musical 1776. She does not play a part in writing the US Declaration of Independence, something that would be historically and culturally inaccurate, but neither does she passively admire her husband or hesitate to bother him for more detail on what do when he casually suggests that she and her friends manufacture salt peter without explaining how they should do so.
Wednesday, September 22, 2010
Energy Beings
Beings made of pure energy are trope that occasionally occurs in science fiction. They speak to our desire to leave behind the decaying wet mess of organic life. I also think they appear only occasionally for good reasons.
Energy in real physics appears to me to be more of an accounting device than a thing in itself. The closest thing in real life to fictional energy beings in real physics is electromagnetic radiation. Could an intelligence be made of this? Not really. There is no internal structure to hang a brain on. Now I confess that I haven't studied quantum electrodynamics, but nothing I've ever seen in written about suggests electromagnetic fields are capable, by themselves, of the kind of complex interactions that brain cells engage in.
I also think that their may be good story reasons not to over-use energy beings or other immaterial forms in fiction. An energy being's invulnerability, while a pleasant fantasy, distances it from us. We have both the physical intuition that they are not real and a certain emotional distance from them based on the fact that they do not share the difficulties of our form of life. I think this is why when energy beings are seen in fiction, they are almost always depicted as falling into or leaving our matter bound form of existence. The circumstances where they touch are realm are more interesting to us than the idea of their existence.
Tuesday, September 21, 2010
Aliens freak me out. Not most aliens you see in the media but the idea of actual aliens freaks me out. While other mammalian species on this planet do posses a modicum of empathy with us, an alien being would have no taxonomic relationship to us and would probably be completely nearly unreadable to us except on an intellectual level.
There are some things that I imagine all biological beings having in common. For example, you have to look at something to attack it, so I can imagine an alien finding a stare threatening if they can recognize our eyes. This though, is a very crude type of empathy. I doubt their'd be mutual recognition of signs of affection or most displays of status.
Other things that aliens might share with us are hierarchical forms of organization. I'm convinced these come about not simply because of desire of some humans to dominate others, but also because a tree structure is an efficient way to share information. However, hierarchies can be permanent or impermanent and all encompassing or only encompass a few activities.
The boss alien on Tuesday might not be the boss alien on Wednesday and we'd have a difficult time understanding that.
Subscribe to:
Posts (Atom)