Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Newbie programming questions

by newbio (Beadle)
on Mar 01, 2005 at 13:12 UTC ( [id://435399]=perlquestion: print w/replies, xml ) Need Help??

newbio has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have some very newbie kind of questions. Thought, you guys explain things beautifully, so here I come to Perl Monk Land to seek some divine knowledge.

From practical perspective, I generally remain confused when it comes to the following terms in relation to, say C language/visual studio. Please explain to me from a practical, easy to understand, perspective.

1. API - what are they? Are these also known as DLLs or Libs or header files? Can .exes be called APIs?

2. Build - Process of compilation. Right?

3. Compilation - Does compilation in C produce .exe or .DLL or anything else? What I understand by compilation is that source code gets converted to some binary format and some linking takes place. I don't understand what all gets linked in this process. What exactly happens in the computer memory in this process?

4. Linking - Linking of necessary fucntions. Right?

5. Run - Run is used to execute the binary (.exe or .dll?) produced by Compilation. Do other functions/system resources required by the source code (that generates the .exe) reside within the .exe or are they used externally as and when when .exe requires them? What exactly happens in the computer memory in the Run process?

6. DLL - Not too clear about it. How and what are being linked here. Also, what's the motivation, necessity of making a DLL in the first place? Why shouldn't I make an .exe instead of this?

7. Exe - A standalone program. But, can such programs function in the absence of compiler say visual studio or something?

8. Libs (library) - It is a collection of functions. Right? Does that mean that it is a single file that contains definitions of other functions in a project? What is its importance, motivation of having it? Are they used through some header file?

9. Header file - Its a collection of functions. Can it also be called a Lib? What's the difference between Lib and header file?

10. Function/subroutine/method - I guess loosely they all mean the same. Right?

11. Broadly, what are the associations and differences between APIs, DLLs, Header files, Libs, linking etc.

Also, please suggest links to any good tutorial, material on the above subject.

Thank you very much in advance.

Raj

Considered by holli: mark as off-topic

20050303 Unconsidered by Corion: Too many keep votes: edit:34 keep:12 del:5

Replies are listed 'Best First'.
Re: Newbie programming questions
by ikegami (Patriarch) on Mar 01, 2005 at 15:04 UTC
    1. API - what are they? Are these also known as DLLs or Libs or header files? Can .exes be called APIs?

    The "I" is for Interface. It covers anything that allows one program to call functions in another program. APIs are sets of rules, not files.

    2. Build - Process of compilation. Right?

    Yes, and linking and any other step needed to create the executable or deliverable. Furthermore, sometimes build can also mean to compile (and such) everything unconditionally, as opposed to make, which would mean to only compile (and such) missing and outdated files.

    3. Compilation - Does compilation in C produce .exe or .DLL or anything else? What I understand by compilation is that source code gets converted to some binary format and some linking takes place. I don't understand what all gets linked in this process. What exactly happens in the computer memory in this process?
    4. Linking - Linking of necessary fucntions. Right?

    Compilation is the process of going from source code to machine code. The output is usually an object file (.obj in Windows). The object files are linked together into an executable (.exe), a statically linked library (.lib) or a dynamically linked library (.dll).

    5. Run - Run is used to execute the binary (.exe or .dll?) produced by Compilation. Do other functions/system resources required by the source code (that generates the .exe) reside within the .exe or are they used externally as and when when .exe requires them? What exactly happens in the computer memory in the Run process?

    Code and data can be embedded into the executable, or kept seperately. The answer to the last question is dependant on OS and architechture, dependant on how much detail you want, and does not need to be known by 99.9% of programmers.

    6. DLL - Not too clear about it. How and what are being linked here. Also, what's the motivation, necessity of making a DLL in the first place? Why shouldn't I make an .exe instead of this?

    Loosely, it's a bunch of compiled functions. A program can load a dynamicly linked library into memory at run-time and call the functions within it. Each of the following two paragraphs are an example where DLLs are useful.

    Plugins. A program to be expanded without having the source code for the program just by creating a DLL containing functions expected by the program. (These functions are an example of an API.) Perl uses this concept to allow people to build modules without having to rebuild perl everytime. The module is compiled into a DLL, which perl tries to locate when DynaLoader(?) is used.

    Operating System Calls. Every call to Windows is actually a DLL call. Without the Dynamic aspect provided by Dynamically Linked Library, the whole OS and every program you will ever use would need to be compiled at once into one big executable.

    7. Exe - A standalone program. But, can such programs function in the absence of compiler say visual studio or something?

    The compiler is no longer needed. This is the difference between interpreted programs from compiled programs. Nowadays, we also have programs that run in a virtual machine, which I won't get into unless asked.

    8. Libs (library) - It is a collection of functions. Right? Does that mean that it is a single file that contains definitions of other functions in a project? What is its importance, motivation of having it? Are they used through some header file?

    Similar to a DLL, in so much as they are a collection of compiled function. However, these are linked into the .EXE (or .DLL) at compile-time, so you don't need to have the library file present at run-time.

    9. Header file - Its a collection of functions. Can it also be called a Lib? What's the difference between Lib and header file?

    Header (.h) files are no different then .c (or .cpp) files. They can contain anything that can be found in a C/C++ source file. The only difference is how they are used: .h files are not compiled by themselves; they are inlined into the .c or .cpp file that #include them. Conventionally, they include function prototypes, declerations of types and defintions of constants.

    They are not libraries; they are just C or C++ source code.

    10. Function/subroutine/method - I guess loosely they all mean the same. Right?

    Function and subroutine usually mean the same thing. In some languages (Pascal, QBasic, maybe Visual Basic), functions return a value, whereas subroutines do not.

    Methods are a special type of functions. They are functions that belong to an class, and supply a "hidden" argument (known as this or self) holding a reference to the object on which the method is currently acting.

    11. Broadly, what are the associations and differences between APIs, DLLs, Header files, Libs, linking etc.

    They're are no relations except those mentioned above.

    Sounds like you'd find a C (or C++) course interesting. You'd probably also enjoy a course in assembler programming.

Re: Newbie programming questions
by samizdat (Vicar) on Mar 01, 2005 at 14:57 UTC
    These are questions about the process of programming, more than Perl-related, but I'll take a stab at them as I'm in wait-4-interrupt mode.

    An API is the conceptual interface between parts of a computing system. It is the definition of how information is passed from one subsystem, module, or program to another.

    'Building' is an inexact term often used for the process of compilation and linking, yes.

    Programs can be separately compiled, either as standalone binaries or as libraries which are meant to be shared. In the Windows world, shared libraries, i.e., common libraries meant to be used by multiple programs, are called DLLs. People use shared libraries so as not to waste memory. For example, if you have two programs running that need to parse Unicode characters, would you want to include the same code in both programs, or would you want to just access one copy of the same code with both programs, as needed?

    Header files are source files which generally are used to define data structures or include definitions of such, as opposed to code files, which define the algorithms. That distinction is blurring these days, however.

    The distinction between functions and subroutines is less important and less-often preserved these days. Originally, functions were subroutines that returned values and subroutines were just packaged actions. Either can have side effects, such as I/O or changes in global variables. 'Method' is the new name which is used in describing object-oriented actions. The object paradigm generally includes a requirement that object methods not have side effects, but, especially in C++, this can be broken.

    You have asked this in a Perl forum, and none of this except API has anything to do with Perl. Perl is an interpreter, as opposed to a compiler. In Perl, the perl interpreter is the binary, and you feed it your source program. The Perl language is the conceptual API, and your program while being interpreted (also "run") by perl may have its own API as an interface between you and it, or it and other programs and resident services on your computer.

    These topics are included in any computer science 101 course, although you are asking them in a Windows context. Any beginning CS textbook will give you this and more. The suggestion has already been made that you look for basic C books, and that's a good one. There are numerous books which cover C in a VS/Windows context.
Re: Newbie programming questions
by cbrandtbuffalo (Deacon) on Mar 01, 2005 at 13:34 UTC
    Well, first things first:

    1. API--in the most generic sense stands for application program interface. It is used very liberally to describe the way a piece of software wants you to interface with it. It can be a set of functions or methods you can use to activate functionality in a 'black box' software product. Or it can be a toolset provided by a company to allow you to use some of their services. For example, Amazon has web services that have an API. You can use this write programs that leverage Amazon data.

    Update: Link to definition in the webopedia and wikipedia.

Re: Newbie programming questions
by Joost (Canon) on Mar 01, 2005 at 13:50 UTC
Re: Newbie programming questions
by darkphorm (Beadle) on Mar 01, 2005 at 19:05 UTC
    A lot of what you're referencing here is more specific to compiled languages. Perl is not a compiled language, but rather an interpreted one (although I believe there are some programs to compile perl code).

    Compiled: The file is not human-readable (binary). It is executable in its own right as an EXE without needing other programs, or may be included in other programs as a library/DLL/etc

    Interpreted: The language is generally human-readable (in the sense that it's not binary). When run, the interpreter (say perl.exe) reads the code through processes it. The code cannot run without the interpreter program.

    Libs: In perl I suppose these would be the perlmodules. They're really quite similar to plain 'ol Perl code but with a little extra (and are still human-readable).

    Functions/Subroutines: Functions in perl work similarly to other languages. They can be called with variables to do some work and/or return a result. It saves you from replicating the same code constantly or using nasty loop statements.

    You're talking a lot about C here, but Perl is not C - though at times the syntax is similar. Perhaps this answers some of your questions though.
Re: Newbie programming questions
by manav (Scribe) on Mar 01, 2005 at 17:33 UTC
    Also, There are 2 kinds of libraries. static and dynamic. DLL or dynamically linked libraries are loaded once and they make thir definitions available to all object which include them. This saves memory by having only one instance of a function definition in the memory at all times.

    You shoud seriously get into C/C++ if you are interested in this sort of things.

    Manav
Re: Newbie programming questions
by zakzebrowski (Curate) on Mar 01, 2005 at 17:48 UTC
    It sounds like the questions you are asking are homework questions... but looking at your previous posts, it's looks like you're interested in building / extending windows applications. Perhaps, rather than focusing on the windows platform (which can be confusing) consider using a different operating system all together...
    PS. Consider changing the subject of your post next time to something like windows programming...


    ----
    Zak - the office
      Consider changing the subject of your post next time to something like windows programming...

      ObJoke: But maybe he WANTS to program newbies. ;)

      --
      [ e d @ h a l l e y . c c ]

      consider using a different operating system all together...
      Becausing linux is *so* simple and easy to use. Really. I swear.

        No, linux is not simple and easy.

        It's just that, when you have a question, there usually is a straightforward (albeit not always easy) way to find the answer.

        Most (all) configuration is in plain text files, for example. Each with a slightly different syntax, but most of the time readable (sendmail.cf notwithstanding).

        Most programs come with documentation and source code, which is not always easy to read, but at least it's possible.

        Windows systems have this maddening tendency to try to protect the user from himself... I prefer a good length of rope, even if it means I will, sooner or later, hang myself.

        -- 
                dakkar - Mobilis in mobile
        

        PS: written in Firefox on a Macintosh ;-)

        Most of my code is tested...

        Perl is strongly typed, it just has very few types (Dan)

Re: Newbie programming questions
by newbio (Beadle) on Mar 02, 2005 at 11:33 UTC

    Thank you very much Monks! As always, hats off to you all for your nice and patient suggestions!

    Reagarding, why I posted this question which I agree is less relevant to Perl directly is because lately I started to integrate this low level "ugly" language of C with "pretty" perl using a broker known as "inline:c.

    And, why would I go to any other C-forums and all when I have such lovely guys out here...:)

    regards, raj

Re: Newbie programming questions
by crypix (Acolyte) on Mar 04, 2005 at 03:40 UTC
    hmm... It might not be pure perl related, but it could be a good idea for a "Programmer Newbie Term FAQ". just .02
    ~crypix

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://435399]
Approved by RolandGunslinger
Front-paged by RolandGunslinger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found