|
About
My Infrequently Updated Blog. The web-based journal of M. Forde, computer nerd, endurance athlete, and DeLorean owner
contact
Subscribe
Subscribe to a syndicated feed of my weblog,
brought to you by the wonders of RSS.
Flavors
There's more than one way to view this weblog; try these flavors on
for size.
index
circa 1993
Sections
main
musings
running
DeLorean
code
unix
album
TBM
Archives
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011
2010
2009
2008
2007
Disclaimers, Copyrights, Privacy, Etc.
ToS
Copyrights
Links
olix0r.net
netmeister.org
Giraffes
Eat. Run. Sleep.
|
|
|
Looking back...
As I look back at code I wrote a decade ago as an undergrad, I often
find lots of little things that can be done better. For instance, in one
file I found that reversing the order in which two functions were called
would have eliminated a half dozen conditionals from one of the
functions and would have resulted in the same expected behavior, but
with fewer lines of code and a lower cyclomatic complexity.
[/code]
[permanent link]
Thoughts on National Computer Science Education Week
This week is apparently National Computer Science Education Week.
Code.org is organizing the "hour of code"
to promote teaching of Computer Science and Programming in schools.
They're also organizing petitions to make CS courses count as credits in
Mathematics or Science for High School graduation requirements.
In High School, my CS courses were by far my favorites, Programming in
Pascal, AP Comp Sci in Pascal, Programming in C++, and AP Comp Sci in C++ (
the language for the exam switched my junior year). I learned a lot
about structured code, elegant, efficient code. I learned enough about
Data Structures and Algorithms that I didn't have to study for my
college CS classes until Computational Structures (Discrete Math II with
Scheme, essentially) in my third semester. I had an amazing Computer
Science teacher who also taught me Calculus and the proper order of
precedence in life: God, Family, Math. I wouldn't be where I am today
without that educational opportunity I had in High School. I want others
to have that opportunity too.
However, this is where I differ with the opinion of the Code.org folks.
I do not believe that CS classes should count toward the Math or Science
requirements. In this state, CS counts toward the "practical or
performing art" requirements, I'm assuming under the "practical" label.
I think this is a better place for it at the High School level.
Computer Science is not a hard Science. It's not Physics. It's
not Biology. It's not Chemistry. There's a saying that if the subject
has science in its name, it's not really a science. That is true with
Computer Science. It's not studying the how and why of atoms, of
molecules, of living systems, of anything really. It's not science.
Computer Science is really applied mathematics. I am very fortunate that
the college program I went through was very strong in mathematics: Calc
I and II, Linear (Matrix) Algebra, Discrete Math, Discrete Math II in
the guise of Computational Structures, Probability and Statistics,
Theory of Computation, Algorithmic Analysis... the list goes on. All of
these mathematical foundations were then applied to a machine, to make
the machine carry out a task in an efficient manner. It's those
mathematical foundations that are the true core of Computer Science.
While mathematics is the core of Computer Science and Computer Science
is essentially applied mathematics, I do not believe it should count
toward the Math requirements. The CS classes would likely detract
from other mathematics courses such as Geometry, Trigonometry, and
Calculus. These courses are far too important to an education to be
replaced by a Computer Science course. Many, maybe even most, High
School Computer Science courses focus more on "programming" than the
fundamental mathematical theories. They will pick the language du jour
and teach you the syntax and semantics. They'll teach about basic data
structures like arrays, and linked lists. The AP exam currently focuses
not on implementing lists, trees, stacks, queues, and sorting and searching
algorithms, but on arrays and lists using Java library calls. This is
not math. This is learning Java syntax.
[/code]
[permanent link]
unHide
After a friend's computer became infected with some malware that hides
files in your home directory and tries to extort money from you in order
to "recover" your data, I was inspired to write this little
program.
All it does is search for hidden, non-system files and unhides them. It
defaults to the user's home directory (My Documents), but other
directories can be chosen.
If anyone wants to try it out, please do. If you do try it, let me know
what parts I can do better. I primarily work on embedded systems and
Unix daemons professionally; the user only knows my software exists when
it isn't working. As such, I have very little experience with GUIs or
human-computer interactions. Any feedback would be much appreciated.
The Windows executable can be found at:
http://www.skinnymf.com/~mforde/unHide/.
Source code is available upon request.
[/code]
[permanent link]
Just a Question
Given the following code fragment, I was asked to implement foo such
that the program would output "America." How would you do it?
int main()
{
char *p = "Hello";
foo( );
printf("%s",p);
return 0;
}
My solution involved allocating new memory from the heap to store the
new string, and changing p to point to that buffer. They didn't like
that answer. They preferred the method of putting the new string in the
data segment as well.
I personally would always avoid that, whenever possible. "Hello" is
stored in a read-only area of memory as is "America" in their preferred
solution. Any attempt to alter those strings will trigger a segfault.
This is an accident waiting to happen.
[/code]
[permanent link]
It's not magic, it's C.
I love reading comments like
/* These defined magically in the linker script. */
I found that in the GNU Standard C Library implementation when GCC told me the
the variables to which the comment referred were undefined. I guess that linker
script isn't magic after all...
[/code]
[permanent link]
C#, XNA, and 8 Queens
I spent some time this weekend learning some C# and getting working a
bit with the XNA framework. I implemented a solution for the 8 Queens
problem in C++, then ported that class to C#. After getting that working
in Windows, I started moving it to the Xbox.
It works there with little issue, but, as expected, writing to
system.console doesn't produce useful output. My next step is to get
some sort of graphical representation of the chessboard displayed with
the solution set.
[/code]
[permanent link]
Self Documenting Code
Despite what you think about your code, it is not self documenting. When
writing code add comments, describe what a function does, explain why
you're using that convoluted pointer arithmetic and bit shifting. I'm
sure it makes sense now, but someday you'll have to go back and look at
it and figure out what the hell you were doing. Or worse, I'll
have to go back and look at it and figure out what the hell you were
doing.
Sometimes it is important to have some sort of separate documentation
for the code; maybe some UML or ER diagrams, maybe some English text.
Use what ever it takes to explain what you were doing. Do not paste
snippets of your code into the text and call it documentation.That
is not documentation, that is code.
[/code]
[permanent link]
|
|