Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Writing Sleek Functions

March 21, 2017
Abdul Azeez Idris

    Your functions must be small, very small. The number of lines a function take should be small enough so the main concept of the function is understood without having to go too far. Beyond having functions that are small, they should do only one thing and one thing alone, and they should do it very well.

    Knowing exactly what that one thing is might be rather difficult, but make sure you function executes a verb. When functions are small, it is easy to give them very descriptive names. The name is not doing much anyways. Function names should be such that the logic of the function is directly explained by the name. Having to comment a function name is a very bad sign and shows that the exact meaning is not given by the function name. Never be afraid to make a function name very long. As far as the name gives meaning. There is really no award for writing short names, which give no meaning. Take time to find a very good name, as it is far better to take the time to create a good name than to have to update later. Consistency in naming functions is also very important.

    Beyond creating functions, passing arguments is one basic thing you have to do to use a function. Ensure you pass very little arguments to a function. Remember to make it as small as possible. Try to create a class for the list of arguments if it is more than two. It allows for easy understanding of the parameters when passed as whole rather than different small parts. Try to make sure your function has no side effect. Let it do what it is supposed to do with no side effects. Ensure that your functions get or set but not both. That means that your method should either access or mutate but never both. This might lead to confusion as that means your function does more than one thing. Remember, we said let your function do only one thing.

    Error Handling is one thing. So ensure you have a separate method that handles that. Then you can have another method that implements the main function. Also, throw exceptions rather than Error codes.
    Do not repeat code. Once you discover a certain code is duplicated, it is time to make it a function and never duplicate functions. However, at the end, the most important is that your functions are testable and are tested. Unit tests for functions should be encouraged and improved.

    These guidelines given here are to guide you while creating your functions. You do not have to get it all the time. You simply need to know that they exist and try to follow them as much as you can refactoring the code along the way until you have the best code that you want.
    This is an excerpt from the Book “Clean Code” By Robert C. Martins


    Whether you are new to Linux or have experience, this cheat sheet can assist you when encountering tasks you haven’t done lately.  

    Last updated: March 20, 2017

    Recent Posts

    • Optimizing distributed AI inference: Advanced deployment patterns

    • Beyond regex: Harvesting security logic with LLMs

    • Build a Red Hat Enterprise Linux EUS image with image-builder CLI

    • Connect EvalHub to protected production model servers

    • Building a custom Red Hat Enterprise Linux kernel for NVIDIA DGX Spark

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.