Code Libraries - Computerphile

preview_player
Показать описание
Standard progamming #INCLUDEs libraries - but how do they work? Dr Steve Bagley links us to the details.

This video was filmed and edited by Sean Riley.

Рекомендации по теме
Комментарии
Автор

I already regularly use libraries but I always enjoy a new computerphile video even if I don't necessarily learn something new. Never be complacent, there may be a gap in your knowledge that you weren't even aware of.

FortoFight
Автор

Been programming for years, still watch this.

DamaKubu
Автор

This really nicely brings linkers, static libraries, and dynamic libraries together

Guitarmn
Автор

Libraries are very very important. I use a lot of libraries for my code, and even abstracted a lot of recurring stuff in my own library, to link to my different small programs.

TheSpinTensor
Автор

C can be used in environments where you just don't need "print". Like perhaps on bare-metal embedded systems. On such systems you also want your program to be tiny as well, in which case "print" just becomes superfluous.

mavhunter
Автор

Those classic vintage PCs in the background! Those things had personality!

joedeshon
Автор

I can't stop looking at that Amiga 1000 in the background.

JaccovanSchaik
Автор

TIL this channel is the most subscribed Tech channel in GB

ambhaiji
Автор

Thanks for an interesting introduction to the subject. I’m an old school programmer from the 70s. Back then using libraries was pretty fraught because often they didn’t perform as specified. Now I’m retired and mostly program embedded systems for fun. Even now it’s not uncommon for a library to have faults. Even something as innocent as recompiling with a different version of a compiler can alter the way a library behaves.

StephenFarthing
Автор

4 years of college and 4 years of industry work, but it took one video to finally really understand what a library is trying to do. Thanks for this video, I feel a little less like a horse at the steering wheel now.

Infantry
Автор

Elegant description of static and dynamic libraries. I wish Youtube was around during my CS undergrad days. Or this channel.

bariswheel
Автор

I want that shirt. Well, not that particular one, but one exactly like it.

philwatts
Автор

Compilation error. Your function must return int, but it does return nothing.

JeeMorpheus
Автор

Finally after two or three decades I (partially) understand what a .dll is.

replicaman
Автор

7:50 It allows the shared library to be updated separately from your executable. For example, a newer version with newer features, bug fixes etc ... so long as it remains backward compatible, you don’t need to recompile or relink your executable to take advantage of it.

lawrencedoliveiro
Автор

I hope you never stop making videos. I watch a lot of YouTube channels, but I get excited for a new Computerphile video in a completely different way than most of the rest.

ImSquiggs
Автор

I think, #include or similar things like \input in LaTeX is the most powerful tool in computing. Splitting up files and even organizing it into subdirectories helps a lot, when you want to find a part of your code. With this you only need a simple texteditor, but today many source-code files of codebases on the internet get too large and you need an advanced IDE to find specific functions again.
I personally make a file for every bigger function or structure/class definition, if it takes more than 10 lines. The "subfiles" are saved in a subdirectory with the name of the module and included by a header file with the same name. The header file also contains forward definitions before the deeper includes(C/C++), which creates an overview of all elements in the module and even can solve cyclic dependencies, which should only happen inside a module and never escape it (however you should avoid cyclic dependencies).

Here is some sample code:

structs.hpp

#pragma once
// this is the root file of the module structs
namespace structs {
// overview
struct a;
struct b;
void connect(a* lhs, b* rhs);
};

// implementation in some subfile depends other modules:
#include <iostream>
#include "utilities.hpp"

// subfiles
#include "structs/a.hpp"
#include "structs/b.hpp"
#include "structs/connect.hpp"


structs/a.hpp


#pragma once

namespace structs {
struct a { b* p; };
};


structs/b.hpp


#pragma once

namespace structs {
struct b {
a* p;
void foo() const;
};
};

// include function definition
#include "b/foo.hpp"


structs/connect.hpp


#pragma once

// this submodule/function depends on the actual implementation, not only the typename, which can be used for pointers without definition -> opaque pointers

#include "a.hpp"
#include "b.hpp"

namespace structs {
void connect(a* lhs, b* rhs) {
a->p = b;
b->p = a;
};
};


structs/b/foo.hpp


#pragma once

namespace structs {
void b::foo() const {
std::cout << "Hello\n";
};
};



Also, with this technique you should never include files upper in the directory tree, include it in the parent file with the same level. Never include files in subdirectories other than in the subdirectory with the same name as the current module.

cmdlp
Автор

Most of, if not all librarys for visual basic are written in C or C++. I started with C and when I started playing with visual basic I wrote libraries for it because I wanted to do something or didn't know it existed in VB. I found C and VB worked great together. I think the first few versions of windows the code started in Pascal. Mixing Pascal and C/CPP can be a pain because they put the arguments in function on the stack backwards. Lol . Thanks, always great videos!

kardeef
Автор

its always good to have either a review of your toolbox... or if needed nice to add a new tool to your toolbox / tool belt. =D

MikelNaUsaCom
Автор

I'm fond of the way that NEXT and macOS use structured .framework folders to group the headers along with the compiled libraries and other resources. It's more sensible than the old-school *nix approach of scattering the components among several folders, such as within the /usr/local folder.

It's worth mentioning that dynamically-linked libraries are at the heart of all modern operating systems, and that software applications are nice and small because they only need to contain their own logic, and are linked to the system resources they need when they are loaded for execution.

ScottLahteine