2010-06-17

Back to hardware

When I was very little I was used to copy a lot of circuits from electronics magazines my father bought, and also from his own diagrams. To me they meant nothing at all, but I found them beautiful and I sensed that there was a meaning in all those symbols. Growing, strangely my interests shifted more towards software, even after I studied those symbols and assigned their proper meanings. At some point in time, I can't remember exactly where, I thought it would have been cool to be able to create a computer; I focused this idea when I studied more deeply digital electronics, but indeed I never planned to realize it for real.

Now it is almost time to get back the idea... It is renewed as something a little bit different: since to create the hardware for real is pragmatically hard (maybe FPGA could do, but...), what if I create a software simulation? The simulation "models" the digital components that "are" the microprocessor, properly interconnected.

Excited by this approach, that seemed possible and not so hard, I've created a new task for Rosetta Code, Four bit adder. The C "model" seemed to me to work greatly, I thought "It can be done", but the task is just a very short step towards the final aim, proved to be not so well written, and the code showed some limits this morning, when I've taken a look at how I could implement a latch using basicall the very same "ideas" already used in the four bit adder.

A little bit demoralized, I began searching the net for similar stuffs... And of course I've found very interesting things, and more "realistic" and done by people more gifted for hardware — I used SPICE once upon a time, but indeed never ever gone into hardware projecting for real, universitary laboratory apart, where however we did not too much complex circuits, in fact we have not done any ambitious project at all; and I know of the existance of languages like VHDL and Verilog, but never used them (I started to take a look at them since today).

I am swinging between two position. In one position, I want just a "simulator" realized in a known language like C (even though OO languages in this case could make things easier). In the other position, I am taking into account the hypothesis of using VHDL for real... and this second position started to exist when I've installed FreeHDL, which has a VHDL to C++ "translator"!!

So even my idea of writing the simulator in code is not so new... Well, the original part could be that I would like to realize an emulator for the processor, using as core the finished simulation. In practice, I would like to run something like myemul ROM where ROM is a file that provides the ROM, and myemul does not realize the emulation as Bochs or QEMU (which have performance needs), but realizes it at a low-level, through logic gates emulation...

Ok, too much for now. I've installed FreeHDL, gEDA, GtkWave and also ngspice. I think I have everything I can have for free (and mostly free, too). But I still does not know VHDL and Verilog, and I have not the slightest idea from where to begin. Luckly, the net is full of informations and experiments, like The Harp Project.

Note: discussing several arguments on Rosetta Code about the task (and a replacement for its description, since the current does not satisfy me) I've discovered that there could be a certain interest in having Brainfuck code running in gate-logic; maybe it would be not a bad idea to start projecting the processor so that it can "host" BF easily.

2010-06-10

Q/A sites

Question/Answer sites are always the same. I mean, there they happen always the same kind of things that can be summarized with few words: biased subjectivity, misunderstandings, personal battles using the voting system. I am not saying I don't fall in those traps too, except for the last one and the first one(!): I do not use the voting or flagging system to fight my personal battles or to "destroy" an answer that does not convince me, but which I recognize as having its own "rightness". Instead, I use often the possibility of commenting (our freedom of speech).

My english is far from being perfect, perfectly unambiguous and grammatically correct, maybe sometimes the hurry makes it even worse...; nonetheless it seems to me it is not so bad. But it seems to me sometimes I get misunderstood because of it.

Recently I am losing a little bit of my time on StackOverflow. Appearing as a site for technical questions, it seems free from all those absolute crap often existing in many low level Q/A sites (I mean question like: where I can get The Program registration key, how can I cancel a file, how can I program a word-processor like Commercial-Wordprocessor in few lines of code, ...), and in fact it is.

But as said, it is run by people, who are defective by design and so the typical aspects of social interactions can arise, altogether with all kind of possible misunderstandings and arbitrariness.

I have a good example where of course I am the protagonist.

The StackOverflow (SO) question is here. My original answer was downvoted by someone (later the downvoter declared himself and it was the same asker), and this was disappointing to me since another answer, containing basically the same kind of informations/proposals, was voted up (I don't know by who).

I loose time, ok, my choice, but I am not prepared to loose time for an answer that is not appreciated and moreover I can't understand why, since compared to others (voted up) it appears of the same quality. So I wrote a comment, knowing no the voter nor understanding the reason.

The comment was:

can I vote myself up? I find this -1 really stupid, expecially since basically I am saying the same thing of an answer that's got +1 and say no word at all about refactorying the if with a subroutines. I've already said that: no matter the techinicalities, Q/A sites are frequented by the same kind of voters.


and I started writing it before the asker comment (As stated, CAN'T CHANGE RULE) appeared. The long "dialog" that follows in the comments came from two facts: my distraction, and their distraction. As usual I am not interested in pointless debates, I just try to understand.

My recognized distraction was that he stated already he could not modify Rule class, while unluckly I focused my "defense" on the fact that he did not, instead of focusing the attention on the fact that, no matter if he specified it or no, my answer contained already a possible solution that fit the requirement, exactly as another answer. Indeed, better than another answer, the one that was upvoted anyway!!

The original asker felt uncomfortable with my comments and decided to remove the downvote (since it was causing "issues"), later pointing out however that the requirement my answer did not talk about was in the original post. Unluckly I noticed I proposed an answer also for that requirement, but not focused it in time, and another thing that happens on Q/A sites is the lost of attention where things get complicated or too long to read.

As the following Original Poster comment shows, he focused on the "first" part of my answer, which talked about changing Rule class (exactly how another answer did, but was upvoted... again)

My downvote is because that your answer ignores my question. Yes, refactoring the Rule class to use an int would be useful, and in fact, I could keep the "else if(flag == "EXCLUDE") { included = false" given your example. So it's a very good answer to a completely different question


The fact is that my original answer contained already at the beginning the following excerpt:

Now if you want the whole [CODE] as a subroutine, you can make it return boolean value and check for it. The caller "decides" if break/return or not. Of course the caller must pass i also (if looping over i for get_op changed as described before).


This shows that indeed I've not totally ignored the requirement. My if looping over i for get_op changed a described before means exactly that: if (i.e. you are not required to) you change get_op as described, you have to pass i. If you do or not, no matter: you can turn the [CODE] into a subroutine returning true or false, and according to this returned value, the caller decides if to return directly or continue looping.

Moreover the OPer edited the question and added a code that basically do what I suggested, wanting as arguments get_opN and get_niN instead of N to allow the subroutine to pick the right get_op(N) and get_ni(N), but apart this detail (due to the requirement) the code is what one programmer can take from the suggestion I quoted before.

While another downvoter chimed in my answer, another up vote was given to the answer that contained same suggestion of mine (and no citation at all to the subroutine possibility); the author of this answer "defended" me some way, thanks. But of course my critics are not against him, but the illogical incoherence of the voters...

The brand new downvoter wanted also to explain its -1. And someone put +1 to its comment.

@Shin: I think the OP's downvote was fully justified. You wrote an answer entirely based on an assumption that the question clearly specifies is invalid. That means your answer doesn't solve the problem.


This confirms that jalf (the nick of the previous commentator) coherently should have downvoted another answer too (the one similar to the mine), but he did not. He downvoted mine instead, because of comments. Talking about what it can be just or not, it is a subjective thing. But also an imperfect "justice" needs to appear coherent: if A-by-X is wrong, it must be wrong also A-by-Y. An answer can't deserve a downvote where another answer, saying the same thing, deserve an upvote. A coherent "just" person can't vote down an answer A-by-X and let untouched A-by-Y (and A-by-Z and so on...). If he does, the only explanation brings us to the fight personal battles using the voting system, which is unfair. In this case, my "complainings" likely was what have driven jalf to the downvote. He did not evaluate the answer deeply, otherwise he wouldn't have used fully and entirely, and he would have noticed that I talk about subroutine with an if that allows for the other explicitly missing case. At least another answer doesn't solve the problem (here of course it should have been "does not try to solve the problem", or I should see that jalf has a huge amount of downvotes!), but is ignored, meaning this is not the real point.

Unluckly when I read that biased comment I have not realized what's wrong in all the "defense line" (i.e. the fact that indeed I treated also the case matching the requirement)... and when I did, it was too late: attention focus was lost and likely jalf won't realize and recognize his error, and this is normally what makes me put an user on my personal black list (in the sense I have to watch out when they are around, to avoid wasting time and get also downvoted unjustly).

Talking about incoherence, it could seem incoherent the fact that I am focusing on jalf and not the asker. It is not because he retired the downvote (I did not pretend him to do so, but to explain, at least why he did not downvote similar answer); it is because he interfered in the dialog like if he was the Knight of Justice (Restoring the Justice, i.e. the just downvote by the asker), unaware of his incoherence and moreover without reading carefully what was already written. People like that rarely come back and re-ponder, it would be wasting too much time on a single question, or even worse: on comments about an answer to a question.

I am not saying jalf is a bad guy to me of course. I am saying he bahaved the way I don't like people to behave on Q/A sites. Commenting is fine. Voting up or down should be more pondered on the current answer, not biased, and coherent. Since these people could make my "wasted time" less pleasant, I mark them for my black list.

The irony is that the asker mixing up answers or by himself produced a code that is already an answer, and that is contained, as idea, already in my criticized and downvoted answer (and not in the one similar to mine and upvoted)... so that my last vote mixed everything and proposed a solution, which fits fully the requirement. But jalf has not wasted time checking for updates, and no other readers have (currently) upvoted me, except who did it at the beginning (and gave the upvote purposely because of the part of the answer that does not meet the requirement, which is a poor bad requirement after all!)... while as said the other answer, talking no about refactoring in subroutine at all, has 2 votes!