Code Monkey home page Code Monkey logo

ft_ls's Introduction

ft_ls: List directory

Introduction

ft_ls is the introductory project to the world of UNIX systems programming branch in Hive Helsinki. The assignment is to reimplement one of the first shell commands one encounters: ls, listing directory entries.

Learning objectives

The project serves as a reminder of some previously used system API functions, and brings in multiple new ones. Similarly, it's an exercise in error handling: the UNIX file system has multiple file types, of which some have special characteristics in terms of errors and the general display. Simply exiting upon minor errors isn't the case here. Good design from the get-go was suggested, in which I succeeded pretty well.

Learning outcomes

  1. UNIX file system & permissions

    As an introductory project to UNIX programming, the project was the first to really dive into the workings of UNIX concerning its file system. Handling (all) permissions and links carefully was crucial for succeeding in this project, teaching about UNIX as a whole.

  2. Manuals (i.e. patience)

    Handling multiple essential system level functions regarding navigating file permissions and extracting status information reliably was feasible only by reading and comprehending the mans concerning those functions. Especially understanding the types of errors thrown by functions like readdir(3) gives a more intimate understanding of UNIX as a system.

  3. Good design mentality

    It was important to make good and informed decisions at the very beginning of a project. In my case, I ended up adding a separate layer of file list collection for arguments, when there already existed a functionality for collecting lists from directory entries. This additional layer could've most likely been fused with the existing implementation, had I realised earlier that the arguments to be listed to output need to be sorted as files first, directories second principle. A small-ish oversight, but took my sleep for a few days in the end.

Future learning objectives

Going forward, I'm seriously taking on a test-driven development approach, as at this point it's become evident that unit testing development code is extremely important especially in memory-considerate implementations. Since C compilers and semantics altogether are not the most helpful in providing useful feedback, extensive testing eliminates a set of worries during development.

Usual Hive school considerations

As usual, Hive programs are required to run error free: any build found to crash (segfault, bus error, double free, etc.) under any circumstances is a direct 0 point and nonpassable. Also, the code style is monitored by a 42-school-wide code of conduct called the Norm. Struct naming prefixes s_*, no declaration and initialization of mutables on the same line, etc. Tabs, not spaces.

ft_ls's People

Contributors

elehtoranta avatar

Watchers

Kostas Georgiou avatar  avatar

ft_ls's Issues

Erroneous output with multiple directory arguments

Input of multiple directory arguments and no non-directory arguments (e.g. regular files, symlinks, etc.) yields an extra newline to the start of the input. This might require either:

  1. Simply reordering the output listing and adding a condition to stop printing newlines at the last element, whatever it may be, or (preferably)
  2. Refactoring the output formatting functionality to a more modular approach, as the formatting done for list items is spread out to multiple functions as of now.
    If option 2. is followed, this warrants a more invasive refactoring of the list_* functions altogether. (See issue: TBD)

Refactoring file list collection functionality

Remotely same operations are done for collecting arguments into a sortable flist linked list, as for collecting directory entries and should be combined into a more streamlined and maintainable solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.