Video problems with FIOS
The other bad surprise, in our 2nd month bill, was $156.03 for a service call we'd placed with Verizon. Multi-room DVR playback to rooms remote from the actual DVR was unreliable. They sent a guy out to trouble shoot the problem, but he didn't fix it and he didn't write it up as a Verizon problem, so they billed us for an hour of labor. I protested and they did deduct the labor and the tax on the labor from that month's bill.
We found more ways to demonstrate the video problem and called for yet another repair visit. The 2nd repair guy was unable to fix the problem too, but we learned a little from chatting with the guy while he was here. In the world of Cablevision, so far as I can discern, data service and television service are quite separate, sharing the same physical cable but traveling in separate channels. But with FIOS, each television set-top box gets an IP address. Some television services depend on being able to talk via the Internet router to get video to the set top boxes. Remarkably, the Verizon service folks don't have any kind of protocol analyzer or even a simple bit-error-rate monitor to give them visibility into what is doing on the home network.
More FIOS Woes - You Own the House Wiring
But we did have other FIOS problems. Cablevision ran a coax cable to a "cable modem" in the front bedroom. There were 2 phone jacks on the cable modem that provided our house phone line and our fax phone line. FIOS doesn't work that way. FIOS mounted a big white box on the outside of the house and ran the fiber to that box. They also installed a large UPS on the wall inside the house and ran power from the UPS to the white box on the outside wall. They then re-used Cablevision's coax cables to connect a coax cable from the FIOS box to the various TV's via a splitter box on the outside wall just below the FIOS box. There is no "cable modem" box as we had with Cablevision, but the Verizon Internet router has a coax connection of its own that it uses to talk to the FIOS network, including the settop boxes. The outside FIOS box also has about 8 phone jacks in it. So, Verizon ran 2 phone lines from those jacks to ancient NY Telephone demarc boxes on the outside wall, to tie the 2 phone lines to the ancient inside house wiring. The deal as I understood it was that as long as Verizon provided dial tone at the demarcation box, that any remaining phone problem was a "house wiring" problem and is only covered by Verizon if you pay them a ridiculous monthly surcharge.
More FIOS Woes - the Fragility of the Fiber from the Pole to the House
But Friday, before we ever got to that Monday service visit, something happened to our FIOS service. We lost everything - TV, phone and Internet. Verizon, contacted via cell phone, agreed to send a repair guy out on Saturday. The FIOS box has an LED in it to tell the repairman if the fiber is delivering a signal to the FIOS box. It immediately told the repairman that there was no signal. Alas, he arrived on a truck with ladders, but the fiber drop cable to our house is connected to the distribution fiber mid-span, between 2 telephone poles, so the junction is only accessible with a "cherry picker" truck.
The future of FIOS??
There's some evidence that Verizon is unhappy with their return on investment in converting their distribution network from copper to fiber. e.g. Wall Street Journal: Verizon to End Rollout of FIOS and DSL Reports: Verizon Again Confirms No Future FIOS Expansion. Will the day come when they try to close down their fiber business? Seems unlikely to me, but we do live in "interesting" times.
Cross the Streams?
I keep forgetting that Ghostbusters was an increasingly long time ago (1984). When our FIOS video problems turned out to be from the mixing of Internet traffic and FIOS video packets, Egon's warning about the dangers of "crossing the streams" immediately sprung to my mind. If you haven't seen Ghostbusters recently, you really should rush out and rent it. But thanks to Youtube, we can give you the relevant clips from the movie. First, the scene where Egon warns "Don't cross the streams!" And, second, the climatic scene where the team makes a slight change of plan and deliberately crosses the streams. A bit of a spoiler, but you still really should see the whole movie.
Message In a Bottle
If you know someone who maybe knows someone in Verizon who'd be in a position to officially react to this note, please pass along the link to this article. I'd be delighted if my woes actually got to the ears of someone who could be properly embarrassed at the lack of network diagnostic equipment in the hands of the Verizon field support staff, or the need for improved field engineering of drop fiber installation and could maybe nudge Verizon in the direction of actually doing something about it.
Friday, June 27, 2014
Home Networking with FIOS - Don't cross the streams.
Sunday, June 22, 2014
How Secure is Your part of the Internet?
Until We Fix Our Connected Homes, Crackers Will Keep Screaming At Babies
Most routers will let you accept only traffic that comes in reply to packets that you sent out to the Internet and that covers most cases. But there are ugly cases where, for example, you initiate an FTP connection and the remote FTP server replies using a different port than the one that you used to initiate the connection. If your router is configured to reject packets that don't look like replies to traffic that you initiated, you're likely going to have trouble doing FTP file transfers.
A stickier problem is do you ever want to access your home Internet from elsewhere? For example, some folks have home security systems (or perhaps a baby monitor) and want to be able to check in on it from their travel PC while away from home. Almost certainly that requires the router to be configured to allow outside Internet traffic, traffic that isn't in reply to inside-traffic, to come into your home. How secure is your home network to outside traffic coming from a wannabe intruder?
I've been on the net since the 1970s, involved in its technology and politics. I don't remember anyone ever saying or promising "and it has to be secure, right?" until the 1990s.
What happened is in the 1990s a bunch of people figured out how to make A LOT OF MONEY off the net, or save a lot of money, same thing.
But most of their plans required the net to be secure.
So security became a BIG ISSUE. Ok.
It's like coming to a river in your car and thinking hmm, maybe I can just slap some wings on this thing and fly across.
The power of the net is that it enables everyone to share information very easily and very widely.
Now, re-read that sentence with security in mind.
Internet security is so bad because it was never particularly designed to be secure.
If you try to engage me in a conversation about computer and network security and I don't know for a fact you're an expert I'm going to check whether you read this article. And if you haven't I will politely ice you out.
Thursday, May 15, 2014
Comparative Programming Languages
Here are a couple of videos from luminaries in the software world that I believe are worth the time to watch.
First is Rob Pike explaining why he created the Go programming language.
OSCON 2010: Rob Pike, "Public Static Void"
That's a short talk of 12.5 minutes.
Far longer at an hour is this talk by "Uncle Bob" explaining what killed Smalltalk and how the same factors could kill Ruby too.
RailsConf 09: Robert Martin, "What Killed Smalltalk Could Kill Ruby too"
Note, that when Bob finishes with the last of his note cards, the talk is NOT over. I urge you to stay in your seat until the end of the video. Patience!
Now to be fair, I'll have to admit that I haven't programmed in Ruby nor Go nor used Rails and I'll even confess to limited experience with Test Driven Development (TDD), but I think I've got to get one of those green wristbands for myself. So if your reaction to the prospect of watching these videos is "Ain't nobody got time for that!", well, as a consolation prize, I'll give you a link to a related, but short to read XKCD comic:
Saturday, April 26, 2014
Penny for NASA?
If you've been paying attention to the social media, you may have noticed that there's a lobbying group called "Penny for NASA" that is pushing the idea that we should double federal spending on NASA from it's current level of 1/2 of 1% of the federal budget to a full penny of each dollar spent by Uncle Sam. Back at the height of the moon program in the 1960's apparently NASA's budget had been as high as 4+% of the federal budget. Penny for Nasa web site.
Space exploration is exciting, and I suppose it is unsporting of me to point out that there are some awfully strong other contenders for priority in allocating the federal budget.
Their video makes mention of a "petroleum industry subsidy" that dwarfs NASA's budget.
So this got me to wondering where exactly to find a line item for "petroleum industry subsidy". Doing a little digging, I find that apparently it is buried in the complexity of the federal income tax and comes in the form of taxes not levied on petroleum industry profits. e.g. See http://thinkprogress.org/climate/2013/01/09/1423351/oil-zero-subsidies/
A presumably harder to sell proposition is: Let's reform the income tax and raise the effective corporate tax rate and then spend more of the revenues on space exploration. If there was a net increase in federal revenues, there are many contenders for the money with deficit reduction at the top of the list. Even if the feds were persuaded to increase the spending on science and technology, I expect NASA would be in for some stiff competition for the money from folks who'd like to see more medical research or more work on alternative energy sources. The old "If we can send men to the moon, why can't we ...", for your favorite choice of "...".
So far, we have visited the moon and established a "permanent" space station in low earth orbit, and done some limited robotic exploration of Mars. Manned exploration of Mars is exciting to discuss, but difficult problems like fatal levels of radiation exposure while in-transit to Mars remain ahead without obvious solutions. Star Trek-ish "shields" and warp drive (to shorten the transit time) don't seem to be in the cards at present.
Perhaps a more do-able objective would be a permanent manned base on the moon to serve as a lower gravity launch platform for deeper space exploration. To be a "Good Idea" I think it would be dependent on showing the base could be built drawing on materials from the moon. Otherwise, maybe the better choice would be an even lower gravity high orbit space station. If nothing else, digging deep to put some of the mass of the moon into use as radiation shielding might make the moon more suitable than a Disney-inspired high orbit permanent space station.
If we're going to have folks be permanent citizens of the moon, it is probably time to re-read Heinlein's "The Moon Is a Harsh Mistress".
Or has Material Science gotten far enough that we should start by building a space elevator?
Certainly there's no shortage of places to spend money, if we have money for such discretionary expenses and the vision and political will for adventure. The politics of the discussion are likely to devolve into debate on the economic stimulus value of the proposed increase in federal spending. An argument for "Investing in the future" sort of demands the context of a long range plan for the future. Even JFK's "we will go to the moon" had more to it than just an intent to go to the moon. http://rdrewd.blogspot.com/2009/07/that-other-thing.html
Am I being too harsh in suggesting that there's much more to consider than just a blind doubling of NASA's budget? The social media would have us believe that the "Penny for NASA" efforts have grass-roots origins. But "Follow the money" is good advice when evaluating any grass-roots movement. If anything, I've over simplified the debate in my article here. e.g. see A Penny for NASA -- or For Congressional Pork
Saturday, April 19, 2014
Bill Gates TED Talks - Ideas Worth Sharing
How State Budgets are Breaking US Schools
Saturday, March 22, 2014
Things your Guidance Counselor Maybe Didn't Drill into You.
I got the exciting news today that the son of my wife's daughter (which modulo the complications of 2nd marriages would make him my Grandson) has been accepted to the University of West Florida. He lives in Florida and I'm up north on Long Island (New York), so I confess to not having ever met the young man nor even knowing about the University of West Florida. But, as usual, Google is my friend when it comes to learning about places not familiar to me. Having now read a bit about the school, I whole-heartedly endorse his choice of college. Wikipedia had nice things to say about the place and it even fared well in the US News tabulation of colleges. But not actually knowing the plans of the gonna-be Freshman, I've got a few things to pass along to him as guidance.
First Things First
College is an important time when many things are going to be going on in your life. It's an investment in your future, but it comes at a cost. There's the obvious expenses like tuition and fees and books and supplies, but there's also an "opportunity" cost. You've elected to defer getting seriously started on your adult life for the number of years that you'll be tied up pursuing a degree. You've picked a 4 year school, so nominally, the long march to a degree should take you about 4 years. If you manage your time properly, and meet the requirements listed in the catalog, then in about 4 years time, you should indeed be graduating and moving on to the next stage of your adult life. If you do it wrong, 4 years will slip into 5 years and perhaps even longer. The price tag on your college education will continue to mount up, but the prize at the end is still that same degree. My point is, your first priority should be to stay on track to completing your degree. Some of the degree requirements may be quite frustrating, but on the bright side, the rules are at least clearly spelled out in the catalog. I assure you that later in life you will have to work your way through many situations where the prerequisites and the completion requirements are not spelled out with anything close to the clarity of your college degree.Note that I said completing your degree is your top priority. By no means did I say it was your only priority. Not so clearly spelled out in the catalog is that your college years are when you seek out what it is that really interests you. You have to discover the degree program and subject "major" that you have a passion for - Something that you'd hope to be doing for the rest of your life, whether or not it was attached to a paying job. Make no mistake about it, to keep body and soul together you will need to find and work a paying job after graduation. Food, clothing, shelter, medical care, cell phone service, high speed internet - none of those are "free of charge", so you will need a job to earn a living. But if you force yourself into a particular career (perhaps "plastics") because you heard that it pays well, yet find that it isn't something that you enjoy, then you've made a grave error in planning your path through college. College is like 4 years, but your career is then the rest of your life, hopefully decades.
But wait! There's more!
Besides picking the right course of study and completing the degree requirements, there's an important social side to college. All work and no play doesn't make for a good, complete, college experience. You'll meet a lot of interesting people during your years in college. Some will be greatly challenging to your intellect. Some will be great fun for parties. Some may be strongly negative influences on your life. With luck, you'll even meet someone who you'll deeply love, someone who makes you a better, happier, person. You need to sort out who is who while not getting too distracted from your top priority.
The good news is that you aren't left entirely on your own to navigate this complex mine field. The same social structures that helped you get through life this far, your family, your church, your childhood friends, and so forth, are still places to turn to when you need guidance. The Internet and so forth makes it relatively easy to keep in touch with your old social supports, even if you are physically separated from them by many miles. Time spent socializing on the Internet is yet another "distraction" from your top priority, but keeping in touch with your roots may have real value to you. So make a conscious effort to spend your time wisely.
School Supplies
Next, a few words about school supplies. If you use a smart phone instead of paper products for these, that's fine, but make sure you have things configured so your information is safely backed up outside of the phone. Phones die or get stolen and you don't want to lose your information. What information? That brings us to the first couple of items on this list:
Calendar - You'll be needing a calendar to remember places you have to be at a specific date and time. In high school life is simple enough that perhaps you are used to tracking such commitments in your head with the backup coverage of reminders from your Mom. In college, your calendar can get a lot more crowded than that.
Address Book - You'll be meeting a lot of people at school. Professors, teaching assistants, lab partners, that hot girl in your Psych class. Take a few moments to jot down their name and contact info in a location where you'll be able to find it later. Loose scraps of paper jammed into your pocket or wallet isn't going to be useful to you in a week when it's faded and crumbled and perhaps even run through the laundry.
Alarm Clock - A smart phone can sound reminders through-out the day, but if you are as sound a sleeper as I am, you'll need a loud, persistent alarm clock to get you out of bed in the morning. I suggest a plug-in model, perhaps even a clock-radio, with a backup battery so it doesn't lose the time or settings across brief power outages. The easier it is to set the alarm time, the better. At the very least, look for an "up" and "down" option on the setting buttons. My favorite clock radio had an actual keypad for direct entry of the time, but I'm not sure that that model is on the market any longer. Do remember to buy appropriate batteries for that backup battery feature. And take some care in picking the location for the clock. The night stand next to your bed has the advantage of being right by your ear, but the drawback of putting the snooze button within arm's reach. I find what works for me is to keep the clock on the dresser where I have to get out of bed and walk across the room to turn it off or hit snooze.
Bank Account - You've got to shop around. College is a time where you'll spend your days somewhere between destitute and flat-broke. Every once in a while, you'll receive some money - perhaps a check for your birthday or for Christmas. Nothing will make that money vanish faster than cashing the check and putting the cash in your wallet. You need to set up a bank account for yourself. You probably should find out what banks (or credit unions) have ATM's on or near campus. Banks near colleges often offer accounts structured to attract students: Low fees, low minimum balance, but probably no interest on your deposit. A debit card is almost as easy to use to drain your account as was cash in your wallet, but at least the debit card gives you a statement so you can see where the money went. If they offer you a credit card, you probably should say "no". It is a lot easier to get into credit card debt than it is to get out of it. A debit card inherently caps your spending at how much you have. Living within your means can be tough, but I strongly recommend it.
Fire-resistant lock box - You need to start being responsible for your own life-documents. Birth certificate, social security card, perhaps even a passport. You don't really need a safety-deposit box for these items, or even a secure safe, but you shouldn't be just tossing them into your dresser drawer under the socks either. Visit Walmart or some such store to find a fire-resistant lock box that you can stash in the back of your closet to hold these hard to replace documents. Note that fire-resistant boxes tend to have water entrapped in the walls of the box, which converts to steam in the event of a fire. The physics of boiling keeps the papers inside the box from reaching the ignition point for paper (until the water boils away). The temperature and humidity in the box is meant to be safe for paper, but not for computer media, so such a box isn't a good place to store backups of your data.
File Folders - For all the years of people talking about "paperless offices" and "paperless classrooms", I think you'll be surprised at how much paper comes into your life every day as a college student. The papers are worthless to you unless you can retrieve them when you need them. As a start on getting them organized, I therefore suggest an investment in file folders. If you don't have a place to stash the folders, then an additional expense to anticipate for you is a small file cabinet. (I recently picked up a flimsy 2-drawer metal file cabinet at Walmart for just over $30). How to organize the papers is a whole other essay that I'm not planning to write here. Cheap 3-ring binders and a 3-hole paper punch can be an alternative to the file cabinet to the extent your papers are 8.5"x11". Keep an eye on the back-to-school sales that come up every year as September approaches. Loose-leaf paper and manila notebook divider sheets can be mighty handy. If you use pencil to label the folders and divider sheets, you'll be able to erase and re-use them as the topics to organize shift as time marches on.
Book Shelf - College brings you more (and heavier) text books than you want to haul around in your back-pack every day. And college doesn't come with a hall-locker for you to stash the books you don't need right now. Make sure that no matter where you plan to live, that your room has a bookshelf where you can store your reference books, text books, note books, etc., etc. in a neat and accessible manner.
I can pretty much guarantee that your first trips home after you've been away at school will not be entirely comfortable for you. Quite likely you'll discover that your family and old friends somehow haven't been aware of the way you've grown up while your were away from home. Don't let that disconnect ruin your visit home. If nothing else, it'll help you appreciate the wisdom of that old adage "You can't go home again".
There are plenty of other ways to ruin your health, though some of them take time. Lack of sleep, for example. Your alarm clock may faithfully remind you when it is time to get up, but it is up to your own self-discipline to remind yourself when it is time to get some sleep. There will certainly be nights when you are cramming for exams or whatever and absolutely have to cheat yourself out of some sleep time, but I assure you that if you make a habit of that, you'll soon find yourself working much less effectively at your college priorities.
Nutrition is another oft-neglected facet of good health among college students. Pizza and coca-cola are a tasty combination, but not a good choice for breakfast. You really need to make an effort to maintain a reasonably balanced diet. Some oranges for vitamin C, milk for healthy bones, all those things they taught you in health class. Somewhere on campus there's a reasonably accurate scale where you can pop by once in a while to keep tabs on your weight. Perhaps somewhere near the gym? Balancing your calorie intake to your level of physical activity is another important part of a healthy diet. (There are free smart phone apps that make it easy to keep track of your weight over time, producing easy to read graphs of your progress or backsliding). Speaking of physical activity, I'll wager that the outdoor weather in Florida is a lot more hospitable to getting out and about than the gloomy slush that was much of the school year up in Ithaca, NY. Ithication we called it. Like precipitation, but greyer and less comfortable.
You're old enough that I'll not subject you to yet another lecture about the dangers of sex. An incurable STD can certainly take a lot of the fun out of college. An unplanned pregnancy can throw quite the monkey wrench into your graduation plans. So have fun in college, but remember there's no "reset" button like in video games, no rehearsals, just one pass through life so make the best of it.
Do your best to plan ahead. There can be long strings of pre-requisites to work through for some majors, so if you don't make yourself aware of those soon enough that 4 year diploma can start slip-sliding off into the future by years. Try to fit some courses into your schedule that'll give you a taste of something completely different from where you think you are going. Be brave enough to change direction if you find where you thought you wanted to go wasn't as interesting as you thought it was going to be. But if you find yourself having to repeatedly change your mind and your direction, do find yourself a trusted advisor who can help you work through why that keeps happening to you.
Do well!
There's a pretty good book called "How Children Succeed" by Paul Tough. If you don't want to take the time to read the whole book, a possible short cut is to read my book-report on my blog from back when I read the book.
I hate to admit it, but there's an awful lot of wisdom (as well as laughs) about the real world of corporate employment to be found in the Dilbert comic strip by Scott Adams. For example (Dilbert, 02/18/2014:
Back in January, 2013, I posted "Advice to Undergraduates". It's basically a link to 3 other articles that I enjoyed. It may be a bit too computer-science-centric for general audiences, I still enjoy reading the linked articles there.
"Education" is a recurring topic on my blog and I won't puff up this references section with links to all the related articles. But I would like to point out the TED Talk linked to my May 2013 article "Education's Future: 'Go Do Something Interesting'"
If my repeated mention of "plastics" makes no sense to you, use your Netflix subscription to hurry up and rent a copy of 1967's movie "The Graduate".
These references would be far from complete if I didn't also include a link to Dave Barry's 2004 "Commencement Address".
Comfie chair and reading light - A startling amount of your college life will be spent on reading. If your habit has been to sit down in the living room with the television on while you read, now is the time to change that habit. It'd be unsporting to tell your family that they aren't to watch television until you graduate. You need a comfortable chair in a quiet place, away from the television, and with a good reading lamp. There are lots of ways to stretch your budget when looking for such items. Some of my college buddies solved the problem by pretty much living in the college library for all their waking hours except for class and meal times. Explore your campus library and find what provisions they have for quiet study space for undergraduates. That wasn't the way that I did it, but I know it can work.
Dorm or commuter student
I see UWF has large dormitories to accommodate students living on campus. They allow Freshmen to park on campus, which implies to me that not everyone is living on campus, some are presumably commuting to school. Home for you is in the Florida Pan-Handle, so I'm guessing that commuting is an option for you. Living at home and commuting to school can be a big cash saving for you. You can forage for food in the kitchen, and your Mom's washer and dryer probably doesn't insist you insert a bunch of quarters for each load. Nevertheless, I urge you to consider living on campus. I believe that moving out of the house is a big step in growing up, and college, if nothing else, is about growing up. Dorm room, meal plan, laundry expenses, ... No doubt living on campus isn't "free", but if you consider the groceries your Mom won't need to buy at home, the gas and car expense that you won't have if you aren't commuting to school each day, maybe you'll be able to manage to live modestly on campus. I think you'll find yourself much more inclined to take advantage of the campus library and of events at school if you are right there.
Your Health
Some fraction of kids go away to college and come back dead. The newspapers love to jump on such stories because the news is so universally distressing to parents. Have fun in college, but take care of yourself. Impaired judgement from chemically enhanced fun can lead to tragedy.
The Requirements for Graduating are in the Catalog
I mentioned up above how you have to consciously pick your path to graduation. You need to find a "major" that really excites you. One of the things I like about UWF is they have a wide variety of options open to you. Teaching, nursing, biology, social work, engineering. My "thing" is computer software, but that isn't exciting to everyone. I'm not going to be that guy whispering "plastics!" in your ear. You'll have to find your own way.
There's more to college than passing classes and graduating
There are many more things happening at your college than just your classes. Take advantage of your being on campus by paying attention to what else is going on and attend some of those events. Back in my college years, when dinosaurs roamed the earth, the walls and hallways of campus tended to get plastered with posters announcing "events". It is possible that the Web has completely replaced those flyers, but I doubt it. Don't blindly rush past announcements of symposia and events on campus.
Happy Trails!
You certainly saw quite a fuss today over your getting into college. Just imagine the excitement in your family when you graduate. I'm wishing you the best for your college years. If I've given you any surprises here or left you with any questions, do feel free to contact me and we can talk.
References
Most all of your college papers will be in for severe criticism if they don't include suitable references at the end. So, I close with a few references here for this article.
Revised 3/31/2014 - Edited to fix a couple of minor typos.
Revised 04/20/2015 - Revised because Dilbert URL's changed around so link to "sleep" comic broke. I fixed it.
Revised 09/16/2019 - Revised because URL to Dave Barry's commencement speech broke. I fixed it.
Monday, February 3, 2014
Python Generators
Background
Back in May, 2013, I posted "Cheap, but not Free, Modular Code has a Price". In that blog article I compared the performance of my solution of Project Euler problem 14 to the performance of Nico Ekkart's solution of that same problem. As I explained in that article last May, Project Euler's guidance on performance is that a solution should be able to complete on a typical PC in less than a minute. My initial solution ran well over a minute and I applied a cache to speed my program up. Once I'd gotten it down below the one minute limit, I had concluded "good enough" and went on to other problems. But Nico honed his solution a little tighter and outperformed my program by a factor of 4.
Looks to me that we had basically the same solution, but his was more of an in-line implementation, while I used a Python generator to produce the sequences of numbers the processing of which is the heart of problem 14. I concluded that the Python structuring facilities like generators do add overhead but I opined that the added clarity of packaging the sequence generation as a "generator" made the overhead worthwhile. Nico's code for his cache was so little code that I didn't really defend my use of a Python "class" for my cache implementation.
Some further experiments with the code to determine how much of my extra overhead came from the generator vs. how much came from my cache implementation might be interesting. I've posted the source code and invite you to experiment and share your findings.
But that isn't what I came here to talk about today
This blog post today is aimed at expanding your knowledge of Python Generators and share with you a neat trick that I've recently learned: a generator of dictionaries.
Python Dictionaries
Back in January, 2013, I posted "Dictionary Implementation". In that article I pointed to where the Udacity CS101 MOOC introduces Python dictionaries and pointed to further places to look to learn how Python implements dictionaries, hash tables. If you aren't comfortable with Python's notion of a dictionary, I'll sum it up as an easy to use collection of name-value pairs, much like an array is an easy to use collection of subscript-value pairs.
Given an integer value as a subscript into an array, you can easily ask for the value associated with that subscript. (In Python such an array is called a "list". But if you have a dictionary of name-value pairs, in Python it is easy to ask for the value associated with a name. e.g. What value is associated with "eggplant", where "eggplant" in this example is a possible "name" entry in the dictionary. If this is all still mysterious to you, my suggestion is to dig for more info on the web. Google search is your friend. A Google search for:
python dictionary
turned up more than 5,000,000 web pages today and Google looks to have done a decent job of sorting the most helpful ones to the front of the search results.
Or perhaps you should work your way through Udacity CS101 to learn this concept of dictionaries and more.
Python Generators
But as I already said, the topic of my blog post today is Python Generators. Rather than take the time and trouble to create a fresh new tutorial about Python Generators, I'll pause here to provide a link to an article from April 2013 from Jeff Knupp: "Improve your Python: 'Yield' and Generators Explained". That article resonated with me as written in an easy to understand way. It's about 19 screens long, so it isn't a quick read, but you can get back to Facebook and YouTube later.
Knupp's article should certainly get you to the point of being comfortable with my Project Euler problem 14 generator.
My generator is very vanilla, just conjuring up a sequence of numbers. The one tricky aspect is my program often doesn't pursue the sequence to the end, but sometimes decides it needs to see a new sequence. I was a little nervous when I did it that way, but now understand that Python doesn't mind dangling generators like that, and even should know enough to be able to garbage collect their saved state, if memory gets tight and it is clear that there's no way the program could get back into that old sequence. Powerful stuff and a feature unlike anything available available in C, Fortran, Basic or Cobol to name 4 examples of older more traditional programming languages.
But Wait! There's more!
If you've read this far but are yawning, thinking that hardly ever do you, yourself, have occasion to use complex logic to generate a sequence of numbers in the programs that you write, well hang on and see what else generators are good for.
Igor Vasilcovsky recently pointed out to me an interesting tutorial from David Beazley about generators. The meat is the slide deck under the presentation link on that page. Even with 2 slides to a page, that slide set runs to 79 pages so it probably is too much to absorb in one sitting. So try to work through it in several sessions. Here's my summary of the key elements I think you should get from wading through that presentation:
-
A generator can return any kind of Python object. That is, it isn't limited to returning the numbers of a sequence. If you paid close attention to my
Pythonic Python
from July, 2013, you may remember that one of the points I made there was that Python functions can return large complex objects, not limited to just a number or just a pointer. Better still, Python takes care of the book keeping to automatically garbage collect the returned object if you are no longer using it.
Beazley has examples with a generator returning strings (lines from log files), and then takes an unexpected turn to have the generator parse the strings into values and stash the values into a dictionary with a name for each value and then return the resulting dictionary as the generator's output. (A dictionary per line of the log file!) My initial reaction to that was to be horrified at the overhead, but if you think about it, looking up a name in a dictionary is quite central to Python's run time modus operandi, so dictionary objects being generated is perhaps more general than generating some more specific Python class object, and looking up values by name is pretty much the same as using a name of a member of a class object to get to a value in the class object. So given that Python is able to get decent performance from run-time interpretive execution, generating dictionaries is a lot more sensible then my initial gut reaction took it to be.
- A generator is just Python software so it can do anything that any Python software might want to do to provide the next value in the sequence. It can compute the next value using a formula, or it could access a file to learn the next value. It is even able to make use of another generator to get an input sequence that it manipulates and passes along. So generators can be chained together into long pipelines.
- If your program is basically about iterative processing of a series of stuff, then chaining together pipelines of generators can fundamentally shape a clean structure for your program and with a little practice you'll soon have a collection of useful reusable filters that you can use to construct future programs that you haven't even thought of yet. Share them with your friends. If you own the code, consider making it (and it's documentation) GPL licensed and freely shared on Github or some other such public place.
aaa.jpg)
