Jump to content

User:OrenBochman/sandbox/code tabs: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created idea
 
added an example
Line 9: Line 9:


<br />
<br />


=== C# ==

<source lang="c#">

interface IBillingStrategy
{
double GetActPrice(double rawPrice);
}
</source>

=== Java ===

The following example is in [[Java (programming language)|Java]].

<source lang="java">
import java.util.ArrayList;

@FunctionalInterface
interface BillingStrategy {
// Use a price in cents to avoid floating point round-off error
int getActPrice(int rawPrice);
}
</source>

Revision as of 10:14, 22 November 2019

Code tabs

  • One often need to showcase the same example in different languages or programming languages. For examples microsoft and Google's developers sites.
  • The current tab needs to be active.
  • Ideally one would also like to persist the user's preferred language to show by default or better yet just make it sticky across sessions.
  • This is a also a good solution to wikipedia is not a list - which strikes a balance between the problem of long lists of code disrupting content by using tabs ui/ux to compress a list into the space of a single example.




= C#

interface IBillingStrategy
{
    double GetActPrice(double rawPrice);
}

Java

The following example is in Java.

import java.util.ArrayList;

@FunctionalInterface
interface BillingStrategy {
    // Use a price in cents to avoid floating point round-off error
    int getActPrice(int rawPrice);
}