while (true) {

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
topham":34hi0gvp said:
Faramir":34hi0gvp said:
What's the cultural deal with github? I keep on hearing it referenced as some sort of programmer equivalent to an artists portfolio, but I'm not quite sure how it all works. Do people just upload whatever they happen to be playing around with?
Short answer: yes, people do that.

Basically, you should put anything you do in source control and you might as well put it out for the public to see so you can point to it as an example of your work.

Mike
 
I had a simple HTML question (simple because it's either retarded or there's a simple solution) and figured it didn't really deserve its own thread, so hopefully it's cool to post here in a misc thread. For background, I'm not any kind of web developer. I am a mechanical engineer, and used to write a personal webpage in HTML 4.0 in BB Edit over a decade ago, and occaisionally make little C programs to do math for me. I have tried Googling this problem, but must not know the magic keywords that will help me. If the answer is as simple as "Get this book/go to this webpage, the answer is in there" I will gladly do that. I'm not trying to get anybody to do my homework.

I'm trying to make a little internal webpage for the company that sets both a long name and a short name for a part through a series of pulldown menus. I have the long name working, and it looks more or less like this:
Code:
<script type="text/javascript">
function combName()
{
var word1 = document.forms[0].word1.value;
var word2 = document.forms[0].word2.value;
document.forms[0].name.value = word1+word2;
}
</script>

<form action="#" method="post">
<select name="word1" onchange="document.forms.word1.value=this.value" onclick="combName()">
<option value="Word1 Option1">Word1 Option1</option>
<option value="Word1 Option2">Word1 Option2</option>
</select>
<select name="word2" onchange="document.forms.word2.value=this.value" onclick="combName()">
<option value="Word2 Option1 ">Word2 Option1</option>
<option value="Word2 Option2 ">Word2 Option2</option>
</select>
<input type="text" id="name" name="name" size="128" readonly="readonly">
</form>
What I want to do is have one option set two values- one string for the long name, and one for the short name. Something like:
Code:
<script type="text/javascript">
function combName()
{
var word1 = document.forms[0].word1.value;
var word2 = document.forms[0].word2.value;
document.forms[0].name.value = word1+word2;
var shortword1 = document.forms[0].shortword1.shortvalue
var shortword2 = document.forms[0].shortword2.shortvalue
document.forms[0].shortname.value = shortword1+shortword2;
}
</script>

<form action="#" method="post">
<select name="word1" onchange="document.forms.word1.value=this.value"
onchange="document.forms.shortword1.shortvalue=this.shortvalue" onclick="combName()">
<option value="Word1 Option1" shortvalue="W1O1">Word1 Option1</option>
<option value="Word1 Option2" shortvalue="W1O2">>Word1 Option2</option>
</select>
<select name="word2" onchange="document.forms.word2.value=this.value"
onchange="document.forms.shortword2.shortvalue=this.shortvalue" onclick="combName()">
<option value="Word2 Option1" shortvalue="W2O1">>>Word2 Option1</option>
<option value="Word2 Option2" shortvalue="W2O1">>>Word2 Option2</option>
</select>
<input type="text" id="name" name="name" size="128" readonly="readonly">
<input type="text" id="shortname" name="shortname" size="40" readonly="readonly">
</form>
That doesn't work of course, but I hope it conveys the idea. The reason why it needs to generate two names is that drawings can take up to 128 characters, but the product database itself can only take 40 characers for a name. So thus, I may want to call something
"SPRING HOUSING, F/ 1IN 312 SERIES VALVE, GLOBE BODY, 150# FLANGE, CARBON STEEL"
on the drawing, and
"SHOUSE 1IN 312 GB 150# CS"
in the database. Help?
 
Hm. You'll basically need to get the currently selected <option> and then call its getAttribute method, if I'm understanding the question correctly.

Something like:
Code:
document.forms[0].shortword1.options[document.forms[0].shortword1.selectedIndex].getAttribute('shortvalue')
should get what you want, given the above markup, IIRC.

The other way to go would be to just set the value of each option as the short value, and use the text of each option as the long value; this is probably what I would do.
 

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
technophile":13onkf9z said:
jQuery is very nice, agreed. For a one-off though, there's nothing in that code sample that has any browser peculiarities or is really all that complex. :)

"document.forms.shortword2.shortvalue=this.shortvalue" is overly verbose and complex. At the very least assign the repeating elements to a variable.

Mike
 
Sure; there are a number of ways that the code can be made less verbose. But for a one-off, you have to ask how much of an investment it's really worth. The code isn't going to have perf problems (it's too short to possibly do so), etc. Just like adding several KB of scripts so you can use jQuery may or may not be worth it depending on usage and such.

Premature optimization, etc.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
vherrera0079":1jbexpao said:
Depends on the project, yeah.
But for any non-trivial project where you're going to be screwing around with the DOM, it's definitely a win, I'd say. Plus you get a bunch of other useful stuff with it.
++

My default setup for JavaScript is jQuery and Underscore. I default to them just because of how awesomely useful they are.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
Trivial projects are even more trivial-er if you start with a a good baseline for all your projects. Having to make a decision at the beginning of a project to use your standard or not adds complication. Use the standard boilerplate code everywhere, use the tests every time and do the standard best-practices js and css compression for every project.

Doing things the same way every time is easier and has a higher quality end result than inventing a "shorter" path for projects that seem "easy."

If one thing has held true over my life, its that easy/quick/one-off projects are the ones that end up in production and being supported for years and years. Make life easy on your future self.
 
tinyMan":2ibzrkui said:
Trivial projects are even more trivial-er if you start with a a good baseline for all your projects. Having to make a decision at the beginning of a project to use your standard or not adds complication. Use the standard boilerplate code everywhere, use the tests every time and do the standard best-practices js and css compression for every project.

Doing things the same way every time is easier and has a higher quality end result than inventing a "shorter" path for projects that seem "easy."
Sure, and this is what I do. It's what I would recommend what anyone who is writing software for a living do. :p

But for a mechanical engineer who is one-offing a small internal project for his company, identifying that baseline, learning all the tools in it (just what they should be, let alone finding, downloading, learning their APIs, etc), and then writing the project in it is going to be a waste of his time.

It's like if I asked what the best way to change the oil in my car was and you recommended I get a full OBD-II setup; yeah, that's probably the Right Way to do it for someone who makes their living that way (or at least does it on a relatively frequent basis), but that's not a very good recommendation for what I actually need. :p
 
tinyMan":8cdmpcoe said:
Trivial projects are even more trivial-er if you start with a a good baseline for all your projects. Having to make a decision at the beginning of a project to use your standard or not adds complication. Use the standard boilerplate code everywhere, use the tests every time and do the standard best-practices js and css compression for every project.

Doing things the same way every time is easier and has a higher quality end result than inventing a "shorter" path for projects that seem "easy."

If one thing has held true over my life, its that easy/quick/one-off projects are the ones that end up in production and being supported for years and years. Make life easy on your future self.

plusity plus plus plus

Avoid complications.
Avoid wrong assumptions.
Avoid surprises.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
But for a mechanical engineer who is one-offing a small internal project for his company, identifying that baseline, learning all the tools in it (just what they should be, let alone finding, downloading, learning their APIs, etc), and then writing the project in it is going to be a waste of his time.

It's like if I asked what the best way to change the oil in my car was and you recommended I get a full OBD-II setup; yeah, that's probably the Right Way to do it for someone who makes their living that way (or at least does it on a relatively frequent basis), but that's not a very good recommendation for what I actually need.

I, personally, believe that its always worth learning how to do it right if you are going to do it at all.

In my experience, "cheaping out" or implementing "ad-hoc" solutions always bites me in the ass. Usually at 2am on a holiday weekend.
 
  • Like
Reactions: NetMage

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
Blacken00100":28cex566 said:
vherrera0079":28cex566 said:
Depends on the project, yeah.
But for any non-trivial project where you're going to be screwing around with the DOM, it's definitely a win, I'd say. Plus you get a bunch of other useful stuff with it.
++

My default setup for JavaScript is jQuery and Underscore. I default to them just because of how awesomely useful they are.

winnar!
 
topham":ptsljoik said:
Complex Dom access has a much higher failure on future changes than a well chosen jquery statement.
If, and only if, you make the commitment to keeping jQuery upgraded (and test each version), which is a non-trivial commitment. Otherwise jQuery 1.6 is as likely to break as pure DOM access when HTML6 and JavaScript 7 become the norm.

You're acting like implementing a framework is free or better-than-free, when the truth is that it's a maintenance cost like any other, and it does have downsides.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
Adjustments to web pages are done for a variety of reasons, but upgrading jquery is not necessary over the short term, possibly even long term. Even if you do upgrade it you can plan for issues, but editing a one-off project that ends up in production (I've seen plenty) with horrible code ends up being a nightmare to fix. In many environments the approvals necessary can be ridiculous, but if it's written properly it can be much easier to get approvals, nobody wants someone touching a system put together with bailing wire, everybody is too concerned it'll break.
 
tinyMan":3m3ozijj said:
Trivial projects are even more trivial-er if you start with a a good baseline for all your projects. Having to make a decision at the beginning of a project to use your standard or not adds complication. Use the standard boilerplate code everywhere, use the tests every time and do the standard best-practices js and css compression for every project.

Doing things the same way every time is easier and has a higher quality end result than inventing a "shorter" path for projects that seem "easy."

If one thing has held true over my life, its that easy/quick/one-off projects are the ones that end up in production and being supported for years and years. Make life easy on your future self.
I agree with that sentiment, but looking through HTML 5 Boilerplate seems like a waste of time. I'm not building a big beautiful webpage, I'm just trying to automate name generation. Also, I see being more verbose as a plus, not a negative- if I ever have to explain this to another fellow non-web designer, I'm not going to remember what "$('#shortword :selected").text() + ' - ' + $('#longword :selected').text();" means, but reading "document.forms[0].shortword1.options[document.forms[0].shortword1.selectedIndex].getAttribute('shortvalue')", although much longer, is pretty straightforward.

As a minor illustration, I just had a sales guy come by and ask what the flow coefficient of a valve means. I could have gone into specific gravity and so on, but instead told him "It's a value that lets you compare flow rates between valves, regardless of the fluid or pressure. Higher Cv values generally correspond to a higher flow rate for a given fluid and pressure." Yesterday, a guy in the shop asked how high to torque some bolts. I didn't hand him a copy of ASME B1.1 and API 6A and suggest he go nuts, I just opened the spreadsheet I wrote for myself, estimated the coefficient of friction, and rounded it off to a nice round number that his torque wrench supports ("Torque them to 40 ft-lbs").

My point isn't that any professional should condone ugly hacks and shortcuts, but just that sometimes you don't need to know every detail. I don't mean any disrespect by that- I have seen many of the programs and webpages that Arsians have made over the years, and been very impressed.

technophile":3m3ozijj said:
Hm. You'll basically need to get the currently selected <option> and then call its getAttribute method, if I'm understanding the question correctly.

Something like:
Code:
document.forms[0].shortword1.options[document.forms[0].shortword1.selectedIndex].getAttribute('shortvalue')

should get what you want, given the above markup, IIRC.

The other way to go would be to just set the value of each option as the short value, and use the text of each option as the long value; this is probably what I would do.
I'm trying both of these today, but the second one does sound easier. I tried
Code:
<script type="text/javascript">
function combName()
{
var word1 = document.forms[0].word1.value;
var word2 = document.forms[0].word2.value;
document.forms[0].name.value = word1+word2;
var shortword1 = document.forms[0].shortword1.value
var shortword2 = document.forms[0].shortword2.value
document.forms[0].shortname.value = shortword1+shortword2;
}
</script>

<form action="#" method="post">
<select name="word1" onchange="document.forms.word1.value=this.text; document.forms.shortword1.shortvalue=this.value" onclick="combName()">
<option value="Word1 Option1" shortvalue="W1O1">Word1 Option1</option>
<option value="Word1 Option2" shortvalue="W1O2">>Word1 Option2</option>
</select>
<select name="word2" onchange="document.forms.word2.value=this.text; document.forms.shortword2.value=this.value" onclick="combName()">
<option value="Word2 Option1" shortvalue="W2O1">Word2 Option1</option>
<option value="Word2 Option2" shortvalue="W2O1">Word2 Option2</option>
</select>
<input type="text" id="name" name="name" size="128" readonly="readonly">
<input type="text" id="shortname" name="shortname" size="40" readonly="readonly">
</form>
but that was gibberish. I'm looking around the web to get a better handle on getAttribute and will try that too.
 
I believe I have a solution. It works, but since I'm not a real programmer, I don't know if this is hacktacular or not.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Namejs</title>
<script type="text/javascript">
function combName()
{
var longword1 = document.forms[0].longword1.value;
var longword1Split = longword1.split("_");
var shortword1 = longword1Split[0];
var word1 = longword1Split[1];
var longword2 = document.forms[0].longword2.value;
var longword2Split = longword2.split("_");
var shortword2 = longword2Split[0];
var word2 = longword2Split[1];
document.forms[0].name.value = word1+word2;
document.forms[0].shortname.value = shortword1+shortword2;
}
</script>
</head>
<body>
<form action="#" method="post">
<input type="text" id="name" name="name" size="128" readonly="readonly">
<br>
<input type="text" id="shortname" name="shortname" size="40" readonly="readonly">
<br>
<select name="longword1" onclick="combName()">
<option value="W1O1_Word1 Option 1">Word1 Option1</option>
<option value="W1O2_Word1 Option 2">Word1 Option2</option>
<option value="W1O3_Word1 Option 3">Word1 Option3</option>
</select>
<select name="longword2" onclick="combName()">
<option value="W2O1_Word2 Option 1">Word1 Option1</option>
<option value="W2O2_Word2 Option 2">Word1 Option2</option>
<option value="W2O3_Word2 Option 3">Word1 Option3</option>
</select>
</form>
</body>
</html>
If you copy that into a file, it should show what I was trying to describe (badly) several posts ago. You make the selections in the drop down menus, then a long name and a short name are automagically generated. The thing that makes me feel like this is wrong is that IE 8 (we have to use it at work) kicks out two errors: 'documents.forms.longword1' is null or not an object, ditto for longword2.

Edit: Changed the way combName() was being called so to agree with technophile suggested.
 

Pont

Ars Legatus Legionis
26,160
Subscriptor
technophile":2615fsn4 said:
topham":2615fsn4 said:
Complex Dom access has a much higher failure on future changes than a well chosen jquery statement.
If, and only if, you make the commitment to keeping jQuery upgraded (and test each version), which is a non-trivial commitment. Otherwise jQuery 1.6 is as likely to break as pure DOM access when HTML6 and JavaScript 7 become the norm.

You're acting like implementing a framework is free or better-than-free, when the truth is that it's a maintenance cost like any other, and it does have downsides.
But in the jQuery case, it's entirely likely that *someone else* will have faced the same problem and fixed it. Instead of updating all your code to jQuery 2.1, you'll just use jQuery-1.6-bobsHTML6fix.

Browser makers are also much more likeley to test their shit against common jQuery usage than your site specifically.
 
If you're writing to the DOM standards you're unlikely to have a problem that jQuery wouldn't.

And locating, implementing, and testing jQuery-1.6-bobsHTML6fix is likely to be at least as time-intensive as fixing whatever it is yourself.

Look, I'm all for not doing work when you can just use the work someone else already did, but using jQuery for a single-page, one-form, static content deal like this is sledgehammering a 5" nail into the wall to hold up a notecard you're going to throw away next week. I mean, jQuery itself, even minified, is larger than the entire rest of the needed code. That's not overkill to you guys?
 
technophile":9nnz9jcp said:
I think you want to change the "onchange" handlers to be combName() and remove onclick. That should resolve the errors.

As far as hacks, yeah, it's hacky, but not awfully so. :)
Public shame time- I don't know exactly what that means. Does that mean modify the select element to read
Code:
<select name="longword1" onchange="combName(this.value)">
and modify combName to put this.value into the right longword#? But I'm not sure how to make the right value go to the right variable. I will try to make this work.
 

Pont

Ars Legatus Legionis
26,160
Subscriptor
technophile":1pnq6b0j said:
If you're writing to the DOM standards you're unlikely to have a problem that jQuery wouldn't.

And locating, implementing, and testing jQuery-1.6-bobsHTML6fix is likely to be at least as time-intensive as fixing whatever it is yourself.

Look, I'm all for not doing work when you can just use the work someone else already did, but using jQuery for a single-page, one-form, static content deal like this is sledgehammering a 5" nail into the wall to hold up a notecard you're going to throw away next week. I mean, jQuery itself, even minified, is larger than the entire rest of the needed code. That's not overkill to you guys?
Is the bottleneck bandwidth or developer time?
 
Are you sure jQuery is a win in terms of either for an unskilled (no offense), non-professional programmer?

Acquiring and maintaining familiarity with any toolset -- including jQuery -- comes at a cost. Professional programmers pay that cost as part of doing business. For a non-professional programmer, it may or may not make sense to pay that cost -- and here, I'm not sure it makes sense to.
 
technophile":43dtxaz4 said:
Are you sure jQuery is a win in terms of either for an unskilled (no offense), non-professional programmer?

Acquiring and maintaining familiarity with any toolset -- including jQuery -- comes at a cost. Professional programmers pay that cost as part of doing business. For a non-professional programmer, it may or may not make sense to pay that cost -- and here, I'm not sure it makes sense to.

Acquiring and maintaining familiarity with raw DOM screwing comes at a much higher cost.

JQuery should be part of the language, plain and simple.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
Plus, no one is really going to be very surprised by having to learn a jQuery "selector" since they basically match CSS anyways.

The same selector you use to pick-out a div for styling can, and should, be the same as the selector used to apply "interactivity" to that element.

Having the "DOM" way and the "CSS/jQuery" way actually complicates things for any page that already has CSS styling AND javascript, since now you are using two methods of describing the same thing. If you dropped the JS DOM manipulation and used jQuery instead, then you are only using a single "method" of identifying elements.

Native js DOM is about as useful to me as Assembly Language. I understand that the code I am writing ends-up as assembly, and that is what runs on the processors (basically) but I don't write in it, or think much about it, since modern tools abstract it away.
 

zeotherm

Ars Legatus Legionis
10,960
Moderator
Shades047":11u7r8pm said:
Can you guys recommend a good book for writing Excel macros? What I'm aiming for is to write a spreadsheet that I can then output as the HTML page I've outlined previously.
Excel macros are really just a subset of Visual Basic and fairly simple as far as programmability goes. Here is a webpage that offers up a tutorial (can't vouch for its goodness/usefulness) that mentions the concepts you'd need to learn: selecting an Excel cell and writing to a file*. Just handle the HTML formatting in the code and add in the selections and you'll be all set.

* Second link is a different tutorial, the original one didn't mention file writing.
 
  • Like
Reactions: NetMage

hanser

Ars Legatus Legionis
43,855
Subscriptor++
zeotherm":zvsyjwhi said:
Shades047":zvsyjwhi said:
Can you guys recommend a good book for writing Excel macros? What I'm aiming for is to write a spreadsheet that I can then output as the HTML page I've outlined previously.
Excel macros are really just a subset of Visual Basic and fairly simple as far as programmability goes. Here is a webpage that offers up a tutorial (can't vouch for its goodness/usefulness) that mentions the concepts you'd need to learn: selecting an Excel cell and writing to a file*. Just handle the HTML formatting in the code and add in the selections and you'll be all set.

* Second link is a different tutorial, the original one didn't mention file writing.
You may not even need to handle the table formatting in the code itself, if Excel allows you to directly access the "Save as Web Page" capability. (Though its output may be quite ugly.)
 

topham

Ars Legatus Legionis
13,756
Subscriptor
Blacken00100":2syisvbd said:
Contributing to open-source software is a pain in the ass. Never do it.

(I kid, of course, but holy mother o' god is it a pain.)

Which is why I laughed when contributing to open-source was mentioned in the 'entry level developer' thread. Some projects make it easy and straight forward, some make it demoralizing, others are typically somewhere between, but ego and arrogance negatively affect most at just the wrong time.


I submitted a minor bugfix to a drupal module and was pleasantly surprised it was accepted pretty much as is; while I've seen other projects drive away submissions arguing over the stupidest aspects.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Yeah - I'm building a patch for a niche C++ project (itself daunting, I haven't written significant C++ since I was 15) to support a feature I need and other people have asked for, but when I go "hey, can anyone point me in the right direction?" for wiring it into the UI (my modifications for the backing library already work), it's tumbleweeds.

Arg.