Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

c, assembly or java?

Status
Not open for further replies.
c is nice to read, very logical, very well designed, and generates quite short assembly code after compilation.

asm is rough to read (*1) , very very logical, highly maths based, and damn fast.

can java be used to program an pIC? Hmmm... That's just a guess, but i think you'll need a sort of processor which is equipped with a java interpreter to be able to run the precompiled java source code.

Addition (*1): Regarding the few instructions a programmable IC can have, this point can be neglected.
 
Last edited:
assemby is EXTREAMLY fast. The fastest programming language out there.
 
Marks256 said:
assemby is EXTREAMLY fast. The fastest programming language out there.
.... if used properly

Addition:
I've heard about languages called "High-level assembly".
They seem to wrap asm commands into high-level style functions and sytaxes.
This could be a nice variant to plain asm text......
 
Last edited:
I would go with C. it is the most widely used, you can find a C compiler for almost any processor. I find assembly to be very fun myself, but assembly changes from processor to processor, some only having 30 or so instructions, and others having hundreds. Assembly also takes longer to program in though, the effort usually results in a program that runs faster, but you will want to question if that is worth the extra effort in the project. you can also do inline assembly in most C compilers so it is useful to understand. I still am working on java, but I dont see much use for it if you are programing embedded processors.
 
hmmm... or you could take the compiled c code ( which is actually asm ) and optimize it.
 
_nox_ said:
c is nice to read, very logical, very well designed, and generates quite short assembly code after compilation.

Interesting ideas?.

But more like:

C is very difficult to read, and can be impossible.

C is very illogical.

C is very poorly designed, and encourages bad programming practices.

C generally generates quite small code after compilation.

This was why Pascal was always the language of choice at University!.
 
Nigel Goodwin said:
Interesting ideas?.

But more like:

C is very difficult to read, and can be impossible.

C is very illogical.

C is very poorly designed, and encourages bad programming practices.

C generally generates quite small code after compilation.

This was why Pascal was always the language of choice at University!.
C is only difficult to read if the author of the program is lazy, has bad planning skills or doesn't quite know what he's doing. If you're willing to spend the time, plan your projects properly and put comments where they're needed then I find that C programs can be very well laid out and easy to understand. In contrast, I often find it difficult to understand someone elses Assembly program even when they have taken the time to lay out and comment it properly!

I've never tried Pascal, so I couldn't comment on that one. I'm quite happy using Assembly or C and until I come across a barrier which I can't cross without changing languages, I probably won't change. That's a hobbyist's prerogative :)

Brian
 
Nigel Goodwin said:
Interesting ideas?.

But more like:

C is very difficult to read, and can be impossible.

C is very illogical.

C is very poorly designed, and encourages bad programming practices.

C generally generates quite small code after compilation.

This was why Pascal was always the language of choice at University!.

Actually, C is more logical to read- just don't treat it like an English novel which you can kind of do with Pascal. What's more logical? The English language or math? C is more like math and Pascal is more like English. Reading complex code is almost impossible with Pascal because there are so many phrases everywhere. Pascal has fewer brackets and like to separate one thing from another which makes it harder to read.

Pascal is the one that promotes bad programming practices because it lets you get away with so many inconsistencies such in your code like capitalization, among other things. C requires more discipline than Pascal (and most other languages). If you don't have that discipline when you code in C, it's not C's fault- it was the fault of the less strict language you learned before. C doesn't let you get away with bad programming practices, Pascal does- so logically, Pascal promotes bad practices more than C does. But if you REALLY want the elimination of bad programming practices (such as never making any errors anywhere), go with Assembler!).

Pascal is not even mentioned at my university. You can go from C to Pascal and not fall into any of the bad programming pitfalls, but I have seen many people who learned Pascal first and then were miserable coding for C because they had to keep their syntax and variable names consistent which they did not have to do in Pascal.
 
Last edited:
dknguyen said:
Actually, C is more logical to read- just don't treat it like an English novel which you can kind of do with. Pascal is the one that promotes bad programming practices because it lets you get away with so many inconsistencies such in your code like capitalization, among other things.

Quite the opposite, Pascal forces (not just encourages!) good programming practice - C on the other hand allows you to write incredibly poor code, that can be completely impossible to understand, even for the person who wrote it.

C requires more discipline than Pascal (and most other languages). If you don't have that discipline when you code in C, it's not C's fault- it was the fault of the less strict language you learned before.

But it's C that is the least strict of the languages, certainly C requires disipline to write good readable code, but Pascal doesn't require such 'disipline', as it forces you to write good code by it's implementation.

C doesn't let you get away with bad programming practices, Pascal does- so logically, Pascal promotes bad practices more than C does.

Bizarre idea?, C lets you write almost anything you want - Pascal forces you to abide by good practice, in many respects even a modern BASIC is more strict than C.

But if you REALLY want the elimination of bad programming practices (such as never making any errors anywhere), go with Assembler!).

Looked for the smilie but couldn't find it?.
 
Add smiley at the end.

C doesn't seem as strict because it so more powerful and flexible than Pascal or Basic, but you need discipline to use it because if you don't have it, it will boomerang you. Your code may compile, but it may not work. You can be forced to write good code and have limited power, or get some discipline and have more control. But the syntactically (a real word?), C is much more consistent, logical, and compact than the Pascal syntax (as far as symbols and variable name restrictions go).

I am not sure what you mean by Pascal forcing you to have good code means unless you are referring to structure, but I learned C first so I never had those problems. As for understanding code? Use comments. It's just good programming practice- you can't expect someone to totally understand your process from the code alone.

It's like Lego vs woodworking (I dunno, I just like analogies). You can have it easy so you can't make mistakes, but you can only stick the blocks in so many places. Or you can have some discpline, and make your own blocks.

What you should be doing is not smacking C, but smacking the people who write bad code! [insert toothed smiley]
 
Last edited:
Nigel Goodwin said:
C on the other hand allows you to write incredibly poor code, that can be completely impossible to understand, even for the person who wrote it.

Quite right - if the author chooses he can write very very confusing programs which although look awful and are impossible to understand, are completely legal in C!
But people who write programs like that are stupid, and the lazyness is counter productive because everytime he wants to make a modification to that program he'll have to spend days, weeks or months deciphering the mess he's made.
Provided you take the time to plan the structure of your C programs you can make very readable and easy to understand code.

Brian
 
dknguyen said:
I am not sure what you mean by Pascal forcing you to have good code means, but I learned C first so I never had those problems. As for understanding code? Use comments. It's just good programming practice.

I learned Assembly first and I found it to be a huge head start when I began to study C. Understanding Assembly is like understanding what goes on underneath the bonnet of a C program, and if ever your compiler generates code which a) doesn't work properly or b) isn't as efficient as you'd like, you've always got the option of modifying the resulting code manually.

If anyone else on this forum is interested in C, and you have the time, I'd definately advise you to get your feet wet with Assembly first.

Brian
 
Lol, yeah, learning assembly first is kind of like learning how to build a car before learning how to fix one. I learned a bit of assembly in university and it did provide a bunch of insight into the memory, registers, and stuff like that. There was on project where it was a really brutal assignment and we had to rush the code to get it done but did it really sloppily (just enough so it worked) and demo'd it. But then we sat down and figured out a much much better, faster, streamlined (and easier to understand) way of doing it for the report and got 100%...woohoo!
 
Last edited:
Another advantage with learning Assembly first which I forgot to mention is that Assembly FORCES you to understand what it going on at the hardware level, which is a HUGE advantage when you come to design a project.

Brian
 
ThermalRunaway said:
Another advantage with learning Assembly first which I forgot to mention is that Assembly FORCES you to understand what it going on at the hardware level, which is a HUGE advantage when you come to design a project.

I always suggest learning assembler first for a PIC (or any other micro-controller), simply because you can't use the compiler (C, BASIC, or anything else) without at least a minimum knowledge of assembler. To write assembler you HAVE to know the hardware, there's no choice - high level languages on the PIC shield you from the hardware, but you still need to know what's there in order to use it.

This doesn't apply so much to a PC, particulalry under Windows, the hardware is effectively hidden from you, and you access it via calls to existing system libraries. Even under DOS, you didn't often 'hit the hardware', mostly you used BIOS calls - and this accomodates the different hardware used in PC's.
 
reply

Very true, the quality of a c code is very much related to how disciplined the programmer is. Adding comments, using "typedef's" and "define's" do increase a c program's readability. And besides, c allows you to write modular programs and break your code into structures and functions. C can be readable.

But C is not very strict (though not really it's fault). It is not strongly typed and this allows for run-time errors (type mismatches for example). C++ gives answers to many of C's inadequacies (but it's slower! well that's a topic for another day!)

But having said that writing bad codes/good codes in C is just a choice
 
I've been writing software since the early 70s and have used a lot of languages, some strongly typed (for example pascal, modula, simula, PL/whatever) and weakly typed (C, of course). I've used all the above languages to write significant chunks of system software. There is a reason that C is, far and away, the language of choice for system software (think OSes, debuggers, etc) - it is very efficient. I can't imagine writing an OS in Pascal because the strong typing makes it a hassle to deal with pointers other than exactly as Wirth intended, for example. In C, it's trivial, you cast/diddle a pointer to look, for example, at the next byte, regardless of what type it points to. but it is important to keep the power tools out of kids' hands.

Years ago, I watched a group of coworkers try to write an OS in a certain strongly typed language. This was during the heyday of the "its the tool not author" trend in the industry. They never met their performance and size goals. A project post-mortem I attended identified strong typing as a significant contributor to the problem. their defect rate was not significantly lower than other projects written in C. Another finding was that the tool does not improve the quality of the product: good programmers write good quality code regardless of the tools and mediocre programmers write mediocre code no matter what.

saying C is bad because it allows you write bad code is like saying English is a bad language because it is easy to write gibberish (or rap lyrics) in it.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top