Libraries · Bibliotecas
| English | Español |
|---|---|
| library/ˈlaɪbrəri/ | biblioteca |
| from scratch/frɒm skrætʃ/ | desde cero |
| API/ˌeɪ piː ˈaɪ/ | API |
| documents/ˈdɒkjuːmənts/ | documentos |
| functionality/ˌfʌŋkʃəˈnælɪti/ | funcionalidad |
| abstraction/əbˈstrækʃn/ | abstracción |
Reusing code others have written
- A library 库 is a collection of procedures you can reuse across programs.
- Rather than write everything from scratch 从头开始, you use code others have already written and tested.
- That saves time and reduces bugs.
- Almost every real program leans on libraries.
Reutilizar código escrito por otros
- Una biblioteca es un conjunto de procedimientos que puedes reutilizar en diferentes programas.
- En lugar de escribir todo desde cero, utilizas código que ya han escrito y probado otras personas.
- Esto ahorra tiempo y reduce los errores.
- Casi todos los programas reales se apoyan en bibliotecas.
A library is: · Una biblioteca es:
It lets you reuse code instead of writing from scratch. · Te permite reutilizar código en lugar de escribirlo desde cero.
Reading the API
- To use a library well, you read its API 应用程序接口 — the application program interface.
- The API documents 记录 how to use the library: which procedures it offers, what arguments they take, what they return.
- You do not need to see the library's inside code.
- The API is the contract between you and the library.
Leer la API
- Para usar bien una biblioteca, debes leer su API (interfaz de programación de aplicaciones).
- La API documenta cómo usar la biblioteca: qué procedimientos ofrece, qué argumentos aceptan y qué devuelven.
- No necesitas ver el código interno de la biblioteca.
- La API es el contrato entre tú y la biblioteca.
Which library for the job? · ¿Qué biblioteca para la tarea?
Pick the library that matches your task: a maths library for numbers, a graphics library for drawing, a random library for random values. · Elige la biblioteca que se adapte a tu tarea: una biblioteca de matemáticas para números, una biblioteca de gráficos para dibujar, una biblioteca de aleatoriedad para valores aleatorios.
A library's API tells you: · La API de una biblioteca te indica:
The API documents usage; you never need the inside code. · La API documenta el uso; nunca necesitas el código interno.
A well-chosen library saves time and reduces bugs because its code is already tested. · Elegir bien una biblioteca ahorra tiempo y reduce errores porque su código ya está probado.
You reuse tested code instead of writing and debugging your own. · Reutilizas código probado en lugar de escribir y depurar el tuyo propio.
Adding functionality fast
- Libraries add functionality 功能 to your program quickly.
- A maths library gives square roots; a graphics library draws shapes; a random library gives random numbers.
- Pick an appropriate library for the part you need.
- A well-chosen library saves time and reduces bugs, because the code is already tested.
Añadir funcionalidad rápidamente
- Las bibliotecas añaden funcionalidad a tu programa de forma rápida.
- Una biblioteca matemática proporciona raíces cuadradas; una biblioteca gráfica dibuja formas; una biblioteca aleatoria genera números aleatorios.
- Elige una biblioteca adecuada para la parte que necesites.
- Una biblioteca bien elegida ahorra tiempo y reduce errores, porque el código ya ha sido probado.
Calling sqrt(9) and getting 3 without knowing the method inside is an example of: · Llamar a sqrt(9) y obtener 3 sin conocer el método interno es un ejemplo de:
The library hides its implementation behind a simple call. · La biblioteca oculta su implementación detrás de una llamada simple.
To draw shapes on the screen, you would choose a: · Para dibujar formas en la pantalla, elegirías una:
Match the library to the kind of job you need. · Asigna la biblioteca al tipo de trabajo que necesitas realizar.
r ← sqrt(2) stores about 1.414, using a ______ library. · r ← sqrt(2) almacena aproximadamente 1.414, usando una biblioteca de ______.
The maths library provides the tested square-root procedure. · La biblioteca de matemáticas proporciona el procedimiento probado de raíz cuadrada.
Libraries and abstraction
- Like procedures, libraries support abstraction 抽象 by hiding complex implementation.
- You call
sqrt(9)and get 3 without knowing the method used inside.
Square root of 2. Instead of writing your own algorithm, call a maths library: r ← sqrt(2) stores about 1.414. The API tells you sqrt takes one number and returns its square root. The whole task becomes one line.
Bibliotecas y abstracción
- Al igual que los procedimientos, las bibliotecas permiten la abstracción ocultando una implementación compleja.
- Llamas a
sqrt(9)y obtienes 3 sin necesidad de conocer el método utilizado internamente.
Raíz cuadrada de 2. En lugar de escribir tu propio algoritmo, llama a una biblioteca matemática: r ← sqrt(2) almacena aproximadamente 1.414. La API te indica que sqrt toma un número y devuelve su raíz cuadrada. Toda la tarea se convierte en una sola línea.
A library is reusable, tested code, so you don't build everything from scratch. Read its API to learn which procedures it offers and what they return — you never see the inside. Libraries add functionality fast and provide abstraction: sqrt(9) gives 3 without you knowing how.
Una biblioteca es código reutilizable y probado, por lo que no construyes todo desde cero. Lee su API para saber qué procedimientos ofrece y qué devuelven — nunca verás el código interno. Las bibliotecas añaden funcionalidad rápidamente y ofrecen abstracción: sqrt(9) da como resultado 3 sin que tengas que saber cómo funciona.