47 points · by deanmoriarty · 4y ago · 80 comments
Over the years, I have accumulated many “calculators” in various spreadsheets to make my personal life easier: tax simulations, startup equity, investment allocation, real estate, …
Clearly calculators online are a dime a dozen, yet I’ve never found the competition (top hits on Google) as accurate as mine, they all seem very wonky, slapped together quickly and missing important details.
What would be the path of least friction to produce a no-backend static website that can host these calculators? I believe that with the right intuitive UX and user-friendly features (i.e. persist the input in the URL query string, instant recomputation on input change, …) they could be valuable for someone.
For context, I’m a software engineer working in FAANG as a backend developer in distributed systems and Linux kernel for many years. I just really dislike dealing with anything frontend-related and I’m utterly incompetent in it, I find CSS to be the biggest monster in computer science (and I troubleshooted bugs in distributed consensus algorithms, ha!), so I’m ideally looking for a framework/template where I can mostly focus on my business logic functions/invariants and get as a result a few static assets to host.
Thanks!
If you do want to go through the trouble of converting to another language, JavaScript would be the natural choice because it can run directly in the browser with just “a few static assets to host”. A template like the following would probably work fine as something simple and functional. (This should be a working example if you save the files to a directory and load foo.html in the browser.)
foo.js:
function foo(a, b, c) {
// do calculations and return output
return a + b + c;
}
foo.html: <!doctype html>
<meta charset=utf-8>
<title>Foo Calculator</title>
<link rel=stylesheet href=https://cdn.simplecss.org/simple.css>
<main>
<h1>Foo Calculator</h1>
<label for=a>A</label>
<input type=number id=a>
<label for=b>B</label>
<input type=number id=b>
<label for=c>C</label>
<input type=number id=c>
<label for=z>Z</label>
<output id=z></output>
</main>
<script src=foo.js></script>
<script>
// calculate output when any input changes
a.oninput = b.oninput = c.oninput = function () {
z.value = foo(
Number(a.value),
Number(b.value),
Number(c.value),
);
};
</script>
a, b, c, z, and foo will be global variables in foo.html so make sure they have unique names.simple.css could also be replaced with other classless CSS frameworks.
<script>
// calculate output and update query string when any input changes
a.oninput = b.oninput = c.oninput = function () {
z.value = foo(
Number(a.value),
Number(b.value),
Number(c.value),
);
var params = new URLSearchParams();
if (a.value) params.set('a', a.value);
if (b.value) params.set('b', b.value);
if (c.value) params.set('c', c.value);
history.replaceState(null, '', '?' + params);
};
// fill in input from query string when page is loaded
var params = new URLSearchParams(location.search);
a.value = params.get('a');
b.value = params.get('b');
c.value = params.get('c');
a.oninput();
</script><table contenteditable> a1.innertext = eval(a2.innerText)
That is one slick anonymous event handler... would never have thought of that having first learned listeners in the days of Java AWT/Swing addActionListener(new ActionListener()
Providing the actual spreadsheet files directly will be of far more use to other people than trying to turn them into an inferior website.
https://css-for-js.dev is a good course.
Instead of asking me to explain why OP should prioritise styling, why don’t you explain how styling allows OP to build financial calculators? Form over function is not a good thing and I would expect HN readers to understand this?
It compiles to javascript and will generate an index.html for you if you want.
Elm is highly opinionated… maybe you’ll love it, or maybe you’ll hate it, but it’s a good fit for what you want to do.
Some programmer who isn't familiar with the front-end world probably is going to develop a website by copying and pasting little HTML/CSS/JS snippets they find online that kinda solves their problems. It's not going to be particularly pretty code (and that's ok), but with a little brute force effort, they'll eventually make it work.
But using something like Elm means that probably somewhere near ~99% of the HTML/CSS/JS examples you find online aren't going to be helpful examples for you that you can easily translate into your own work.
You can use Bootstrap (or similar) for some minimal theming. No CSS knowledge required - just apply the classes as described in the docs.
Alternatively you might be able to find a similar project online that you can modify to fit your needs? There are a lot of simple single-page form based apps on Github.
Just found this one on YouTube for example: https://www.youtube.com/watch?v=CGftYT6KcrM https://github.com/kaizhelam/BMI-Calculator
Also, I would stay far away from any Javascript package manager. Your calculator should be working for 10 years at least since HTML, CSS, plain Javascript, and Rust will most likely still work in 10 years and math doesn’t change either.
I also suggest react because after extensively using multiple frameworks I can say without a doubt the react ecosystem stands out far above the rest. There’s many high quality graph and table libraries for React. And having also dealt with integrating these sorts of libraries into component frameworks, it’s just not the sort of thing you want to waste time on.
As for language I would highly recommend just embracing TypeScript and skipping JavaScript. This will certainly help eliminate a whole class of potential frontend-typical problems like strings being interpreted as numbers due to developer error.
For styling I would use tailwind (although if using react styled-components is another approach, but tailwind definitely gets out of your way). This will easily get you past the styling problem you mentioned.
For hosting I would use Vercel. I would have suggested Netlify and really both are good but I’m considering migrating my sites to Vercel because netlify appears to load CSS files in a weird order, but that’s not too relevant to the discussion here I suppose.
Happy to answer anymore questions or help you get started with the code and implementation - contact links in profile! I hope this advice has been practical.
My suggestion would be webflow or some other no code that lets you just write backend stuff.
I think it's worth pointing out to someone with this knee-jerk reaction that, today, a subset of CSS exists that allows you to make layouts that look decent without going cuckoo bananas in the process. I still don't like it, but I don't hate it, either.
Maybe I’m misunderstanding your use case, but if you want to create web apps out of your backend work, streamlit may be your ticket for “easy to understand on the back end, hyper-simple front end.”
At least worth giving it a look.
This is literally the reason frameworks exist: to handle user input, managing state over time, and then updating the UI in response to changing of state.
By suggesting a framework like I did, allows OP to focus on writing the actual calculation code and and to build their site - not spending time writing user inputs and bindings and manual DOM updates.
I have made little tools like this in pure html and JS before. Its really quite straight forward and using a framework is overkill.
You do make a good point (perhaps accidentally) about libraries for output. As a backend dev, the opening poster should be able to understand the concept of magicLibrary.drawGraphyThingy(wowSuchValues);
Also, could you explain how sending the data to a server is the answer when OP specifically asked for a static site without a backend? You did read the question in full before deciding on the answer, I hope.
If he/she doesn't want to learn front end, just dumping data to an API is a workable solution. If he/she really wants to go the quoted route - sure, learn everything. Again though, SPAs are NOT a substitute for learning HTML/CSS/JS basics. At the end of the day, he has to understand that || is raw Javascript, even though it's used to render or not render. That creating a <tr> from data is actually populating a <table> that needs a <th>, etc, etc.
So what we are recommending is "work around all that to your strengths". Your solution is pretty much "learn front end".
Served by NGINX on a Linux server. I host with DigitalOcean for $6/month
I use a CSS Framework template. I like Bulma for its simplicity: https://bulmatemplates.github.io/bulma-templates/
Summary of things to google:
- simple Serverside framework for <language>
- Digital ocean nginx tutorial
- CSS Framework Template
Also, one of my favorite websites for learning to build websites & webapps is: https://roadmap.sh/
It guides you through some of the common steps involved in building the skills, for frontend, backend, phone apps, and devops
___________
Regarding presenting tabular data on a website for editing and downloading, I highly recommend this ReactJS framework: React Bootstrap Table v2
https://react-bootstrap-table.github.io/react-bootstrap-tabl...
That said, a prerequisite for using it is learning ReactJS.
For that, I recommend https://udemy.com/
They are meant for putting simple UIs on top of (Python) data apps, which I think is what you really have here. You focus on the logic and don't have to deal with the frontend directly.
I do understand this doesn’t meet your static site need. But if you’re in this for knowledge transfer and improving the state of the calculators you created perhaps opening up the code to those that could collaborate could be useful. Perhaps you could write the canonical library for those calculations. Keeping the presentation away from the business logic like this is a stated goal…
[2] https://blog.jupyter.org/and-voilà-f6a2c08a4a93 has a pretty good demo that would be effectively what you need to create an interactive calculator.
Google Sheets, Zoho Calc, Airtable and Streamlit offer functionality I like but I want something that will work in a local browser without a cloud link. Ideally something that could be served statically as you describe from Vercel or perhaps a webserver on the user's local machine.
I couldn't find anything so I started playing around with Pyodide, Elm, Typescript, XState and Tauri before discovering Yew and WebAssembly. I like the idea of a small interactive calculation engine in Rust with a customizable table/spreadsheet interface that a user could load and run entirely in their browser.
CSS is indeed a beast. I tried avoiding it but eventually decided to see how far I can go with just Bulma, CSS media queries and CSS grid-template-areas. I've started making mockups with Zola to figure out the subset of CSS that will work for me. Then I hope to port or incorporate the Zola templates in my Yew application.
If the goal is purely providing something functional to others on the internet, just create a simple page. Describe your calculators. Add links to download your calculators as excel spreadsheets.
No need to over complicate and build a spreadsheet in a browser.
If you don’t want to do that, just create some HTML pages with forms and use some JS to chain together input boxes and spit out a calculation.
Many of the suggestions here will take you the route of complicated layers of abstraction. Unless your goal is to learn these abstractions, you can avoid that complexity.
From this I am assuming you will be comfortable with C++.
> I just really dislike dealing with anything frontend-related and I’m utterly incompetent in it
May I then suggest Wt[0] to you?
If you have some front-end developers that you are close with, I would ask for some guidance and an occasional push in the right direction once you get started. If you really do dislike front end, I would try to reframe how you approach this problem, because it will just end up being a slog for you :(
I'm not sure what the best tool for a calculator app is, but there are probably many options
As for functionality, if you're "just" doing some calculations and presenting it like a spreadsheet, you probably don't need a framework. Some plain Javascript onChange event listeners for your various input fields might be all you need.
That said, to convert spreadsheet formulas (which often depend one from another) look for something reactive. Svelte might be a good choice if you can figure out its model of reactivity.
I'd recommend Vue or Svelte if looking for something similar.
With Svelte you need a build step, and can’t change the app without setting that up first.
Certainly you can achieve it but I’d argue it’s more work to avoid build tools than to adopt one.
Can you share example links for what you have in mind?
Without a clear goal you will get as many suggestions as there are developers in this thread.
Best of luck with whatever you end up doing
I think these tools should work for someone coming in without prior experience and figuring it out from the docs.
Or, you could Google “classless CSS”, if you’re OK writing some HTML.
I made a plug and play CSS library here for those that don’t want to write CSS: https://github.com/andybrewer/mvp
Bootstrap is very popular and easy to find components for.
For simple interactions look into htmx or alpinejs. Or jquery.
These recommendations presume you want to get things off the ground asap, without spending months learning.
I would deploy using Netlify with their CDN or Cloudflare.
Short of hiring/partnering with someone, learning yourself is the closest best bet.
I'd say have the api ready, go through vuejs tutorials to build something, and then ask for help ?
The best I've found is NextJS (you can use their API support if you don't have a separate one yet) + Chakra UI (removes practically all the need for css).
You can pick it up in a weekend and build beautiful products.
Otherwise the Python community likes to avoid touching anything that is not Python. Dash Plotly or Streamlit are great tools to make web apps in Python.
Learn the tool designed for the puropse instead of looking for shortcuts
Unless you mean, "How do I monetize this?" in which case, good luck.
Do give it a try. There are plenty of YouTube tutorials out there.
Telling someone to just “use css html and js” is about as helpful as telling someone to “just write code”.
Find some minimal CSS framework. My preference is Skeleton [0] or Bootstrap [1]. The key is just finding something minimal that works without too much fuss. Personally, I rather have a minimal framework provide 'responsiveness' so I don't have to worry about it but I also want it to get out of the way of anything I do.
Use JQuery [2]. Don't rely on CSS for animations or interactivity. In theory CSS does a lot. In practice it's a nightmare to use and to get it play well with whatever else I'm doing in the page.
Write in "bare" HTML and "vanilla" JavaScript. Don't use a static site generator and don't use a JavaScript framework.
Port in JavaScript libraries as needed. Some of the ones I tend to use are numeric.js [3], downlaod.js [4] and audience-minutes [5]. If you're doing spreadsheet things, maybe there's some JS package out there that will help.
Doing "raw" HTML/"vanilla" JavaScript makes me effectively unhirable but for limited scope side projects where I have full control and want to minimize bit-rot, this is fine.
The point is to create something that's minimal and focuses on functionality. The CSS is just there to make it not look like a Web 1.0 page but otherwise steps out of the way to focus on the actual usage of the application.
For context, here are some projects where I've used this philosophy (all open source, feel free to pilfer): Noixer [6], Resonator Voyant Tarot [7], Boston Train Track (now defunct) [8], CalebHarrington.com (an artist friend) [9], What Is This License [10], HSV Hero [11].
[3] https://github.com/sloisel/numeric
[4] https://github.com/rndme/download
[5] https://github.com/berthubert/audience-minutes
[6] https://mechaelephant.com/noixer/
[7] https://abetusk.github.io/ResonatorVoyantTarot/
[8] https://github.com/abetusk/bostontraintrack
[9] https://calebharrington.com/