Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 423357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:10:20+00:00 2026-05-12T19:10:20+00:00

I am writing an interface to a sorted collection of objects. As is the

  • 0

I am writing an interface to a sorted collection of objects. As is the usual, I leave it up to the user to specify how these items are sorted. I am currently torn however, between offering a key-value interface (where the sort key is explicitly separate from the value) or a value-only interface (where the value is either also the sort key, or the user must handle a separate sort key by passing in some comparison function).

In my view, a key-value interface forces the user to always have a key separate from the value, even when some value naturally forms its own key. It does take away responsibility for handling the key from the user however, possibly leading to simpler and cleaner user code when using my API. A value-only interface allows for a more compact representation of values that are their own key, but forces the user to track and handle their own keys in cases where there is a natural key-value distinction.

There is literature to support both approaches of course, though it seems to me (could be wrong on this) that older literature tends to prefer a value-only approach, while newer literature prefers a key-value approach.

I am curious as to your preferences in cases like these. Have we arrived at a point in time where one is generally preferred over the other? If not, what do you usually use, and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:10:20+00:00Added an answer on May 12, 2026 at 7:10 pm

    You seem to be torn between what are called (in various languages, with various distinction, but essentially…)

    • A Dictionary (aka a hashtable even a hash)
    • A List / Array

    These two types of containers serve different purposes, altough, with a few tweaks, there’s little a List can do that a Dictionary cannot. That’s simply because the Dictionary has more information.

    In general it is better to be explicit than implicit.
    If I hand you a "2 dollars blue crayon" (a list), you’ll infer that it is an object with the following properties: {Price = 2$, Color = blue, Type = Crayon} (Dictionary). However such parsing (when needed) requires both effort and knowledge of the domain or the implicit structure of the data; the dictionary approach allows you to handle information in a generic way.

    There are a few cases when lists are “better”, but that is often tied to a technical / operational consideration, rather than to a intrinsic property of the list approach. For example for implementing search indexes with a simple full text engine, mashing all properties together may be required (This mirrors the way the end-user types in un-labelled keywords, expecting them to be found in any property).

    A practical recommendation, in response to the question is to offer:

    • An API which exposes the usage/behavior of both Lists and Dictionary
    • An optimized (size-wise and/or space-wise, depending where it matters) implementation that preserves some of the List’s approach “edge” with regards to performance, at least until the container is used as a Dictionary.

    Unless of a priori obvious concern regarding performance (eg: containers will receive tens of thousands of items, there will thousands of container instances, the containers will transit over a slow channel etc.), I would focus on the API first, taking my ease with the implementation, for example basing it on a Dictionary. At a later date, if that becomes necessary, the implementation can be revised, for example with the two lists and a map schema.

    One last thing: there are plenty of libraries (or even language-builtins) which offer this kind of polymorphic containers: maybe see if one is available for your target system/language…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a C extension, providing an interface between Ruby and an asynchronous I/O
Let's say I'm writing an interface for a class A that keeps a list
I am writing a Ruby CLI (Command Line Interface) program and I would like
I am still writing on a python interface for my c code with ctypes.
I'm writing a proxy library (called Library A) that is just an interface to
I'm in the process of re-writing some code whilst maintaining the external interface. The
I am writing a game in the landscape mode. In *.plist I've set the
For a CS class I am writing a linked list implementation of a linked
I've written a Generic Handler so I can access my server's COM port through
I would like to use the same code for copying files to an FTP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.