Hope you find this interesting. Happy Shelling....Write a mini-shell with a following features
- The shell should receive command from the user and execute it. If the user just gives the command, you have search the command in all of directories defined in the environment variable PATH. If you are not able to find the command, you have print "no luck, seems like your program is toasted". If the user specifies the path along with the program, it is enough if you just load and execute it.
- You should store the last command that is execute and its exit status.
- You should implement a facility to run the program in background.
- You should remember last “N” commands and print it upon user request.
- You should name your shell and it should appear as the prompt.
- When you type "quit", you must quit from your shell with a greeting.
Showing posts with label Design for Fun. Show all posts
Showing posts with label Design for Fun. Show all posts
06 March 2012
Do-It-Yourself (OpenGyan) - Write a (your own) shell
04 April 2011
Design Patterns - How to Learn
Most often we encounter people whom they call themselves as expert in design patterns. They start off with the discussion saying that they know Singleton pattern - knowing little bit of what is singleton and completely ignorant of why Singleton is needed. While design pattern helped experts to improve their productivity and the quality of software they write, it hasn't done anything to novice designers like us. Right away, let me say that it is not the problem with the design patterns. It shows that the way we learn design patterns isn't right.
Learning design patterns starts with getting hands dirt with abstraction, hierarchy, encapsulation and loose coupling. All these attributes do not come easy and they evolve over a period of time with imagination. We have to visualize how a solution is better than the other and if we can solve by writing code, it really helps us to understand deeper.
Keeping that mind, i started to put together series of puzzles on software design to improve my design knowledge - particularly on object oriented software design for quite sometime. I would say that this method is changing the way i think. If you also want to get your hands dirt, you can find puzzles tagged as "Design for Fun".
Let me tell you, more puzzles are on the way.
27 March 2011
Software Design Puzzle #8 - Manufacturing Soaps
Assume that you are an expert in manufacturing many varieties of soaps - bath soaps, detergent soaps and all soaps in the earth. You have a magic recipes of soap making right from procuring raw materials till manufacturing soaps and shipping to stores. There are many processes involved in soap making and there are various flavors for each process. And some of the processes are optional and specific types of soaps. For example, you know that you to have add a lot of scents for bath/toilet soap and lot of whitening material for detergent soaps.
The puzzle is to design the soap manufacturing with lot of processes/steps and all these processes/steps are sequential meaning that one process cannot start until the previous processes are complete. For instance, the process of shipping cannot happen until you make soap and you cannot make soaps until you form soap base and you cannot start soap base without raw materials.
Can you design soap manufacturing process where one step depends on so many previous steps. To induce your thinking, let us assume that you have the following processes/steps
- Buy raw materials (can be different based on the soaps)
- Mix raw materials
- Form soap base
- Make soaps
- Package soaps
- Ship It
You are free to add more steps but the key is to come up with a process that can be changed dynamically based on soap types that are going to be invented in future :-)
16 February 2011
Software Design Puzzle #7.2 - Thread Pools & Tasks
Please refer to previous two posts on the same problem - Implementing Thread Pools and Tasks. Here is the link for your convenience.
Yesterday, i added a requirement that i want to have a priority for tasks (a problem on data structures and algorithms). Today, i thought about another feature that gives a lot of flexibility (real OO design). In the above examples, we didn't talk much about the threads in thread pools. Can we try to make threads in thread pool dynamic entity - based on the need, the number of threads in thread pool should grow or shrink. Here are my next set of questions.- What are the design decisions that i should take so as to make thread pool dynamic.
- How can i make threads, tasks, thread pool at the topmost level of abstraction and yet get many different concrete implementations.
- How can i ensure that the code I am going to develop after two years (due to new requirements) doesn't affect my code now (seal the code from modification for new requirements)
- How can i bring in hierarchy, levels of abstraction and modularity for better design?
- Do i have any design patterns?
15 February 2011
Software Design Puzzle #7.1 - Thread Pools & Tasks
Refer to the previous post, Software Design Puzzle #7 - Thread Pools & Tasks. This post is an addendum to the previous post.
I m going to add one more enhancement to the thread pool design. The enhancement is to come up with a priority queue for tasks. Each task will have certain priority, an integer that increases as priority increases. At any given time, the task with highest priority has to be selected and run by threads in thread pool.
Can you refactor your design?
13 February 2011
Software Design Puzzle #7 - Thread Pools & Tasks
We know what is thread. The thread is an independent execution path or entity in a process. When you want to exploit multi-core (increased processing) or do some blocking operations, the thread is the default destination (increased interactivity, heavy input/output operations). In any programming language that supports multi-threading, you run the code that can be run as independent execution path as thread with each having its own context. The infrastructure that is needed to run threads in parallel like stack, program counter, registers are tightly coupled with the code that runs. Due to this tight coupling, each time you need an independent path (let us call it as task), you create a thread (the infrastructure) which has its own overheads. Is it possible to change code of the thread?Obviously the next step is to separate out the infrastructure and the task which is achieved using thread pools. Here is the next problem.
Write a simple thread pool in Java with following requirements
- Have a fixed but configurable number of threads in thread pool. At any point of time, you can run up to N threads.
- Have a task queue (or a suitable data structure). This can be much bigger than number of threads. The tasks wait in the queue for their turn.
- The thread should consume tasks from the task queue and execute it. It can be any task (but you have to ensure some fairness). The role of the thread is to run task without bothering too much on what it does and how it does.
26 January 2011
Why Loose Coupling is Strong Coupling?
Often, senior programmers insist us to have a loose coupling. In order to appreciate those words - "go for loose coupling", we need to understand what does it mean by loose coupling.
There is another good practice encouraged by senior developers which is modularity. Often, they want us to write function or methods which is just a screen's length (by the way for 14 inch monitor :-)). How can loose coupling be possible when you have modularity? When your application is highly modularized, you heavily depends on many modules to accomplish things.
The concept of modularity in fact leads to loose coupling. By modularity, we make a part of the code to do one critical thing. We don't want any part (or technically a unit) of the code to do two things. We want to restrict to a critical thing and by modularity we also want to hide the gory details underneath. When modularity is practiced in a structural programming, we tend to get loose coupling in a structural language/programming and when we follow right abstraction in object oriented paradigm, we get right loose coupling in object orientation. The modularity mean do one thing that is appropriate to the level of abstraction.
The loose coupling is not restricted to a specific programming types but rather has to be seen as a concept. The application of concept can be different in different programming language types like modularity, abstraction (having hierarchies of abstraction, each level of abstraction marries to a same level of abstraction to realize the functionality).
So, loose coupling helps us to realize strong coupling between objects but avoids tight coupling (which is a code smell).
What do you think?
30 December 2010
A Question on Java Exception?
In Java, there are two types of exceptions - checked and unchecked.
Java compiler ensures that "checked" exceptions are handled and flags compilation error when checked exceptions are not handled. But it does not flag errors when "unchecked" exceptions are not handled. The subclasses of "RuntimeException" and the subclasses "Error" are "unchecked".
Why does Java have this as a thumb rule?
28 December 2010
Software Design Puzzle #6 - Design A Dictionary
For example, when you type "sim", it should display first "N" closest match with the prefix supplied. I don't need to emphasize that the first word should be the exact match (if any) and then followed by list of words that matches closely.
Assume that you have many data store in which the words are stored (database, XML file, txt file, CSV file etc). It is enough to perform the search/auto-suggestion on the data in local database. If the user is willing, the user can also hear the word through audio and for doing that you have to contact a remote web service that gives a audio file for a specific word. You can also assume that there exists a audio file for every word in the database.
Can you design the application, come up with set of classes, assign responsibilities to the classes and a brief architectural diagram too.
Put your design patterns knowledge in action :-)
Put your design patterns knowledge in action :-)
15 December 2010
Software Design Puzzle #5 - Ice Cream, Ice Cream, Ice Cream
Uncle John is very tired working for a software company. It is his childhood dream to be a entrepreneur and so he resigned his job and started a ice cream business. His business idea is very simple. Like coffees, teas, milkshakes, he wants to do ice cream vending machines and sell ice creams along with ice vending machine. Being a Java developer, he wants to develop a highly flexible ice cream vending machines (and eventually patent it). He wants to give few varieties of ice creams - cone, cup and stick and so many flavors.
The question here is, how will you design the ice cream vending machine (time being forget the fact how various ice creams base/flavors are mixed and ice cream is made which by itself is a separate design problem to solve).
How will you design the vending machine?
08 December 2010
Software Design Puzzle #4 - Apple Farm
This time, it is producers and consumers. Here is the story
There is a apple farm and the season is at its peak. The farm has many trees and each tree has numerous apples. The owner decides to harvest the apple and invites bids from various folks who are interested to buy apples. Some of them want the apples to be sent to their places and some of them are ready to reach the farm to procure the apples. So, the farmer plans for the harvest. He employs few hundreds of people - some to pick apples from the tree and some to package/transport apples. And by the way, the farmer sends apple as package of 500 apples.
Can you bring out classes and their relationships to fulfill the above requirements?
03 October 2010
Presentation on "Basics Things on Objects"
Last week i shared with you one of my old presentations on Security. From this week and for few weeks, i ll be writing/sharing few presentations on "Objects", "Design", "Design Principles" and "Design Patterns". I m not sure whether i ll be regularly posting every week. At this point of time, i m trying to find my consistency to post the presentations every week. Please bear with me until i find my consistency.
Each deck will have
Each deck will have
- slides focusing on only one thing
- short recap of things that are discussed
- drill for the week (you can try to reflect on the problem until i post the next presentation)
- the topic of next week
Here goes the first presentation. This is just a curtain raiser to help us to set in same frequency. [ I would love to hear from you - what do think and how can we make this much better.]
Basic Things on "Objects" - Part 1
20 September 2010
Can you Really Teach Abstraction?
I was talking to one of my friends about OOPS. While talking to him, a question suddenly flashed in my mind about OOPS and more specifically about abstraction - how can you teach abstraction and the methods to be used to abstract ideas. In order to answer this question, we need to understand the real meaning of abstraction - "a concept or idea that is not associated with any specific instance". In other words, it is our ability to take our learning to higher level so that it becomes independent of specific instances.
Let us try to understand whether it is possible to teach abstraction with a help of simple mathematical addition. 1 + 1 = 2, 1 + 3 = 4, 6 + 5 = 11. Each of these additions are specific instances of addition. When we are learning "addition", we focus more on "+" (and put it in long term memory, yep that is abstraction) and we just remember the numbers until we solve the problem. Once the problem is solved, we just forget the numbers (short term memory). When we are early stages of learning, we tend to believe that specific instance is ultimate truth. When we practice, we face many types of similar problems and start to change our perspectives. The change of perspectives is critical that leads abstraction. With practice, we are programmed to abstract concepts (eg: addition).
So, i tend to believe that abstraction is directly proportional to practice and more specifically the number of "wow" moments that you create on specific subject and i agree if someone says "abstraction cannot be taught but can only be felt or facilitated".
19 September 2010
OOP - Bending, Stretching, Thinking My Mind
The past two days, the Saturday and Sunday, were really exciting. I lived in this world with a lot of imagination and i would say it was good exercise for my brain. When it comes to Object Oriented Programming, nothing comes near to practice (of course, practice with head/brain/mind or whatever we call it). Object thinking was good testimony that one has brain and trying to use it.
I started off with a nice relaxation at Marina Beach with Sandy (an amazing guy and rock star) who often gives you a lot of challenges in the form of questions. It is not so easy to answer him as it is quite difficult to convince him (i bet, if i have a presentation now, i ll be more comfortable in answering questions than i used to be few months back). We spent around two hours in Marina beach (and we both thanked each other for making a good start) and later an hour in Saravana Bhavan. Dropped of Sandy at Guindy and from Guindy, i started my week on OOP.
I was trying to come up with a design for a problem and so far came up with at least five designs. Whenever i tried redesigning, i got to go back and reread the requirements/problem statements. I m a poor guy and i got to read the requirements many times. But yet to settle down with a design. I believe, i ll change the design five more times :-)
I expect to complete the design and coding of the problem this week and hope the next Saturday morning will be intense with some OO discussion.
@Sandy
I hope, you will join me next Saturday too :-). But the next time, we will be more technical and let us make sure that there is good amount of learning. What do u think?
20 August 2010
Software Design Puzzle #3 - Modeling TCP/IP Stack
You would have heard about TCP/IP Stack in Networking (if you haven't or want help in refreshing, please refer here). The puzzle to identify and come up with set of classes with properties and functionalities to represent TCP/IP model using object oriented principles. Also, identify the list of design patterns that can be used while you are designing the classes.
The answers to previous two puzzles on algorithm is out. Please check out all the puzzles here. Will be publishing the answers to all outstanding puzzles this weekend.
Also, please do let me know your comments/feedback/suggestions.
The answers to previous two puzzles on algorithm is out. Please check out all the puzzles here. Will be publishing the answers to all outstanding puzzles this weekend.
Also, please do let me know your comments/feedback/suggestions.
11 April 2010
Software Design - Puzzle #2
Here goes another design puzzle.
There are varieties of creatures (example Man, Lion, Tiger, Monkey) each exhibiting varieties of walking behaviors (Walk, Slow Walk, Chasing, Running, Jumping). The walking behavior changes based on the mood of the creatures. (Hint: This forces us to bring in different walking behaviors to our objects dynamically).
Can you analyze this requirement and come up with design pattern(s) that could solve this problem and set of classes to model this requirement.
14 March 2010
Software Design - Puzzle #1
You are sitting in a boardroom of a famous gaming giant. They have invited you to discuss about the design of their next product - a strategy game. The game is "Konquer" in which a king tries to rule the entire world and takes the world towards prosperity. The gaming giant is planning to give the responsibility of modeling classes. Here is the requirement one
Since the area is very large, the king is trying to split his kingdom into more manageable parts. He needs idea on making his entire region into more manageable regions. The requirement is that you have to come up with list of regions and model them into set of classes. After this, the king goes for the hunting asking you to meet him after two days to discuss your ideas.With this example, we will learn few object oriented principles that leads to better software design.
Subscribe to:
Posts (Atom)
