Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/02/11 19:24
Read: times


 
#180401 - Language matters
Responding to: ???'s previous message
Some languages was developed to be used for tutoring good programming style.

Pascal is such a language.

It is very good to be able to write elegant programs. But Pascal was originally intended for use on a virtual machine. So the original language did not allow access to any real hardware. Another thing is that the language contains specific "magic" that you can't reproduce yourself. One example is that read(), write() can take multiple parameters of varying type. But the language was designed so that these functions was magical - no way to let you design similar functions yourself.

Some languages was developed to be simple to implement, having very little resources.

BASIC is such a language. It is an interpreted language, because it means you don't need a compiler that have enough memory to see all of the source code at the same time. Instead, everything is based on line numbers so when the program runs, the interpreter just looks to see if it knows any text line with the specified line number. But while the original BASIC uses a very limited syntax (to make it simple to process), it also limits the developer. You can't access the hardware directly unless the specific implementation have added "magic" functions.

Forth is another such language. It isn't interpreted, but instead have removed basically all language structure. It's just a list of commands to push and pop parameters to a stack, and to operate on the data on the stack. Very good for getting good speed on slow hardware with ease of language implementation is way more important than ease of use for the developer.

Some languages have been optimized to allow very light translations from source code into machine instructions, while still letting the developer write structured programs with possibility of data types and (at least moderate) compile-time checking.

C is such a language. It gives very fast programs - in many situations you even get 1:1 relations between C instructions and assembler instructions. The very general support for pointers makes it easier to go wrong. But at the same time, this pointer support is needed to allow good mapping to real hardware since real hardware is all about addresses.

Assembly isn't a real language. It's just a way to use text mnemonics for the machine instructions the processor supports. This means that an assembler program is only valid for a specific processor architecture. And it is even possible that two different assemblers have used separate naming conventions for the op-codes or registers. Some assemblers uses the naming convention from the chip datasheets. Some assemblers are available for multiple architectures and instead uses a "normalized" naming scheme.

It is very likely that a hobbyist can get by without ever writing own code in assembler. There may be a few times when assembler may be needed, but then these specific situatins you can normally cut/paste ready-made code. You might need to be able to enable/disable interrupts, or similar.

You can write more or less organized programs in any language. But a language designed for more structured programming will help a lot. On one hand, it will force the developer to fight a bit extra to write unstructured code ;) But a language with more structure will also allow the compiler to better analyze the code and catch errors.

In assembly, you don't really have data types, so you may mix and match almost in anyway you like. In a HLL, you normally have data types. Some languages have very, very, very strict data types. Some are a little more lenient. But being strict with data types means the compiler with catch errors.

Pascal is way more strict with data types than C. In C, you may get a warning for something that is an error in Pascal. And if you add an explicit type cast in the code you tell the compiler: Yes, I do know I do funny things with the data types but I do know what I'm doing so keep quiet.

The thing is - when doing embedded, the most structured/type checked languages will start to introduce a lot of troubles for a developer. You often need to access hardware directly. You know what you need to do, but don't want to have to sit down and figure out how to best fight the compiler.

Many of the most structured languages requires you to use C or assembler to implement the hw-specific stuff just because the "main" language just doesn't allow it. In Java, you have JNI (Java Native Interface) just to be able to interface between a virtual machine and the real world.

For small microprocessors, it's C that is the #1 HLL choice just because it gives a reasonably good level of structured framework, while still limit the need for a large runtime library. And as mentioned, it maps well to most real hardware.

For larger processors, a lot of people have instead selected C++ - basically all the low-level stuff available from C but with the introduction of object-oriented concepts that can reduce the maintainance costs for really large programs. Remember that even microcontrollers are now able to run programs with 100k+ lines of source or even reach millions of source lines.

The need for software design (computer science) is directly related to the size of the programs. You can do very sloppy 100 line programs without any problem. They are trivial since they are so small you can read through the code one or two times and basically remember everything. Having a language that allows you to structure your code into real functions, with local variables and to create new, customized, data types is what allows you to write larger and larger programs without the maintainance costs going sky high. Now cost may not feel important for a hobbyist, but instead think: "Time to find all critical bugs".

So why you can use a huge number of languages to solve a problem, there will be many different criteria when trying to figure out what is a good language to use (there is almost never a "best" language).

But talking about C, you get quite a long list of "good":
- huge amounts of sample code available
- huge amounts of developers who can help
- lots of cheap compilers, books, debuggers, ...
- possible to run on PC while learning
- fits well to most common processor architectures
- results in small and efficient programs
- adds decent amount of compile-time type checking if developer thinks a bit about design choices
- adds enough structured support to work well even for quite large projects (the Linux kernel isn't exactly small)
- allows mixing with assembler - but different way depending on used tools :(
- allows most hw access directly without bringing in assembly
- ...

List of 76 messages in thread
TopicAuthorDate
Partial decoding of external memory...            01/01/70 00:00      
   8 bit DATA Space            01/01/70 00:00      
      aka "PDATA"            01/01/70 00:00      
   Adres Latch            01/01/70 00:00      
      corrections to all the above replies            01/01/70 00:00      
         Partial decoding of external memory...            01/01/70 00:00      
            There are two locations in the LCD            01/01/70 00:00      
               Re: There are two locations in the LCD            01/01/70 00:00      
                  timing is the reason ...            01/01/70 00:00      
                     one fact expanded            01/01/70 00:00      
                     Thanks for the advice...            01/01/70 00:00      
                        still?            01/01/70 00:00      
                        Maybe it wouldn't hurt to spend time reading the datasheet            01/01/70 00:00      
                           Checking out the Datasheets...            01/01/70 00:00      
                              That's interesting ...            01/01/70 00:00      
                                 Not all BASIC are the same            01/01/70 00:00      
                                    does that apply to BASCOM?            01/01/70 00:00      
                                       "improvements" or extensions?            01/01/70 00:00      
                                          Modern versions of BASIC            01/01/70 00:00      
                                 Re: That's interesting ...            01/01/70 00:00      
                                    Programming on the Fringe            01/01/70 00:00      
                                       Re: Programming on the Fringe            01/01/70 00:00      
                                          To PC or not - but avoid dead ends            01/01/70 00:00      
                                          I'd recommend you think some more about all that            01/01/70 00:00      
                                             That's the key!            01/01/70 00:00      
                                             Brain pollution            01/01/70 00:00      
                                                re: teaching language            01/01/70 00:00      
                                                   Introduce a computer or introduce how to program            01/01/70 00:00      
                                                Initial attraction is fundamental flaw            01/01/70 00:00      
                                    Which concepts do you find particularly hard to grasp?            01/01/70 00:00      
                                       Pointers are normally the main problem when learning C            01/01/70 00:00      
                                          Is the problem specifically 'C', though?            01/01/70 00:00      
                                          pointers aren't unique to 'C'            01/01/70 00:00      
                                             Pointers            01/01/70 00:00      
                                             Big difference in concept - C actually unusual            01/01/70 00:00      
                                                Remember PEEK and POKE            01/01/70 00:00      
                                                Pointers            01/01/70 00:00      
                                                   Pointers and type-safety            01/01/70 00:00      
                                          big problems            01/01/70 00:00      
                                             Wrong direction            01/01/70 00:00      
                                                goes both ways            01/01/70 00:00      
                                       Re: Which concepts do you find particularly hard to grasp?            01/01/70 00:00      
                                          Not a casual subject            01/01/70 00:00      
                                             Re: Not a casual subject            01/01/70 00:00      
                                                I think it's already been said in this thread...            01/01/70 00:00      
                                                one C book should do            01/01/70 00:00      
                                                   Manzi?            01/01/70 00:00      
                                                   It might not hurt to do this in a different sequence            01/01/70 00:00      
                                                   Re: one C book should do            01/01/70 00:00      
                                                      Language matters            01/01/70 00:00      
                                                      you haven't seen ...            01/01/70 00:00      
                                                         Yes, but...            01/01/70 00:00      
                                                            Languages helps but isn't enough            01/01/70 00:00      
                                                         Re: you haven't seen ...            01/01/70 00:00      
                                                            RE: been looking at snippets            01/01/70 00:00      
                                                               Re: been looking at snippets            01/01/70 00:00      
                                                                  Details in standard + compiler manual            01/01/70 00:00      
                                                                      a book doesn't detail everything            01/01/70 00:00      
                                                                     You need to study the compiler documentation            01/01/70 00:00      
                                                                        You need to lean the language first!            01/01/70 00:00      
                                                                           my point was ...            01/01/70 00:00      
                                                                        Re: You need to study the compiler documentation            01/01/70 00:00      
                                                                           Go directly for C            01/01/70 00:00      
                                                                              i second this            01/01/70 00:00      
                                                                              Re: Go Directly to C            01/01/70 00:00      
                                                                                 C support            01/01/70 00:00      
                                                                           the big advantage of PASCAL is            01/01/70 00:00      
                                                                              C isn't that dangerous if caring for compiler warnings            01/01/70 00:00      
                                                                                 So ... C++ is not of interest in this context            01/01/70 00:00      
                                                                                    It's about bracketing claims            01/01/70 00:00      
                                                                                       I did say, "in this context", didn't I?            01/01/70 00:00      
                                                                                          Be careful with your asides!            01/01/70 00:00      
                                                                                          Always give enough context to statements            01/01/70 00:00      
                                                                                             OK ... I stand corrected            01/01/70 00:00      
                                                                                                Separate thread!            01/01/70 00:00      
                                                                                                   I hoped someone would do that            01/01/70 00:00      

Back to Subject List