=============================================================================== WEST COAST WEB ADVENTURES, INC. NEWSLETTER - Vol #1, Issue #2, January 30, 2001 Online version at: http://www.WestCoastWebAdventures.com/news/news01302001.txt =============================================================================== Visit http://www.WestCoastWebAdventures.com for additional information, or to add your two sense, or to unsubscribe from this newsletter. =============================================================================== Contents - About this Newsletter - Cool Tools: WebGEN - Case Study: Dynamic Web Content - Working with Code: Building a Date/Time Object - FGL Tips: Typeless Variables - This Week's Referral: VirtualPROMOTE =============================================================================== About this Newsletter =============================================================================== This newletter was created as a free resource by West Coast Web Adventures for people interested in providing themselves with more control of their web presence and overall computer experience. It is published via email once or twice per month, more or less, as the opportunity and need arises. We hope that users of all experience levels will get something out of each issue. The newsletter is published in-house by West Coast Web Adventures staff members, but outside content contributions are always welcome. Contact the webmaster if you have something to contribute. =============================================================================== COOL TOOLS: WebGEN =============================================================================== Code generators have become all the rage lately as a means to simplify web development. Some take the kitchen sink approach by providing everything imaginable --- including really ugly code. Others simply provide task specific generation with an eye towards simplicity --- with really ugly code. WebGEN started as a means to simpify internal web development by reducing repetitive tasks related to common yet complex coding. It also became a fun excercise in the abilities of FGL and the Active Page environment. ALong the way the main criteria was versatility --- and really tight code! As a product it will never achieve commercial fame because that is not its target. Rather it will forever be enhanced and modified to meet the ever-changing web development environment. Currently, its primary features include: HTML Initialization Code, Color Conversion, Symetric Buttons, Rollover Images, and dbObject. HTML INIT CODE: Starting a web page from scratch involves retyping the same basic code over and over again. In addition to the minimum required HTML tags, standard style and meta information is also generated by this function. COLOR CONVERSION: This function converts standard RGB integrer color values to its web-based hexadecimal equivelent. SYMETRIC BUTTONS: When designing an interface it is often desireable to create a series of buttons that are symetrically distributed across a given area. This function calculates the optimum width for a given number of buttons over a specified width. ROLLOVER IMAGES: This function will generate the code neceassary to utilize JavaScript-based rollover images within a web page. dbOBJECT: This function creates an object-based wrapper around an existing database file encapsulating most of the database functionality with a class structure. You may utilize the WebGEN interface by accessing at: http://216.115.232.27/webgen/ =============================================================================== CASE STUDY: Dynamic Web Content =============================================================================== For a long time the web was populated primarily by static web content, that is, web pages whose content does not change just because you request them. In many cases this is in fact a good thing, after all, a disertation that does not change does not have to be served up dynamically. However, the age of personalization, customization, and time-sensitive material requires the embracing of a means to deliver content dynamically. In the world of the web this can occur in three primary ways: manually, server based, or client based. Consider the date. Simply adding a date and time stamp to a page can reflect its freshness (or age). You can accomplish this manually by editing the HTML source code for the page each day and FTPing it up to the site. While this technically does not constitute dynamic content...it seams to partially bridge the gap of static content. But this method is a pain and real time waster. JavaScript can be used to display the current time and date by using client based processing. Essentially the user would request a static page that contained the necessary JavaScript instructions. Once delivered to the requesting machine the code would be executed and dynamically alter the page before it was displayed. This has the benefit of being processed by the server as static content, but has the trade-off of having to transmit extra instructions so that the local system knows how to dynamically modify the page. Server based dynamic content dynamically alters the requested page before it is transmitted to the requesting system. This allows the server to perform and necessary calcualtions or formating and only send the minimum information necessary to display the results. This greatly reduces the transmittal requirements but adds to the processing burden of the server. In many cases server based dynamic content delivery is the only option. Querying a database, for example, requires a server to process the request and return the formated results. Server based systems capable of providing dynamic content include Perl, CGI, ASP, and Active Pages, among others. For our purposes Active Pages provide all of the functionality that we would ever need in a highly optimized environment. Active Pages allow us to easily integrate sophisticated server based commands with standard HTML as well as client side JavaScript and other such functionality. From the user's perspective, an Active Page is nothing more than a regular web page, and accessed in just the same manner as any other HTML document. From the server's perspective, however, the same Active Page tells the server how to process and format the page before sending the results back to the user. Active Pages to the programmer empowers them to easily integrate sophisticated code with standard HTML and other languages without having to worry about the final delivery mechanism. For more information about Active Pages and for specific examples, visit the developer's area and download page within the West Coast web site. =============================================================================== WORKING WITH CODE: Building a Date/Time Object =============================================================================== Working with date and time values can at first glance be a simple process, however the complexity that really exists can be quite daunting. The numerous applications and their related functions can fill an entire section of documentation even though all you really want to do is add a couple of dates together and generate a formatted result. The Data/Time object was created to consolidate all of the date and time functionality and greatly simplify its use. When the object is first created a date is passed that is stored internally as a date string as well as its numeric day/month/year components. Subsequent method accesses reference these internal values so as not to require the date to be passed at each call. Once the object has been created, the internal date can easily be modified through simple assignment. If no date is provided during object creation, the current system date is used. The object also realies heavily on the concept of parameter overloading in which certain methods operate differently depending on the number of parameters passed. Example use of the object includes: // create the object using the current date d = new( "DateTime" ) println( d.date ) // displays: 01/30/2001 println( d.year ) // displays: 2001 println( d.dow( ) ) // displays: 3 println( d.cdow( ) ) // displays: Tuesday println( d.DateString( ) ) // displays: Tuesday the 30th day of January, 2001 println( d.time( ) ) // displays: 14:38:12 println( d.timeh( ) ) // displays: 14:28:12.77 println( d.timeAmPm( ) ) // displays: 2:28pm You also utilize the julian functions within the object for doing date math, such as with the following: // calculate the date 30 days from now... x = d.dtoj( ) d.date = d.jtod( x + 30 ) println( d.date ) // displays: 03/01/2001 This object can be integrated directly into any FGL program or executable as well as any Active Page for the web. It can also be added to a library using the SLIB librarian utility. ////////////////////////////////// // Date/Time Object Source Code // ////////////////////////////////// CLASS DateTime PUBLIC: local _date, format, delim, yearlen local day, month, year, leapyear METHOD new( d ) ::format = "MM-DD-YYYY" ::delim = "-" ::yearlen = 4 ::date = type( d ) == "C" ? d : date( ::format ) return( 1 ) END ASSIGN date( d ) ::_date = d ::Split( ) ::LeapYear = ::IsLeapYear( ) END ACCESS date return( ::_date ) END METHOD Split( ) ::day = 0 + substr( ::_date, ati( "D", ::format ), 2 ) ::month = 0 + substr( ::_date, ati( "M", ::format ), 2 ) ::year = 0 + substr( ::_date, ati( "Y", ::format ), ::yearlen ) if ( ::year < 100 ) if ( ::year > 2001 ) ::year += 1900 else ::year += 2000 end end return( 1 ) END METHOD IsLeapYear( y ) local year year = type( y ) == "N" ? y : ::year return( year % 4 == 0 ? 1 : 0 ) END METHOD DaysInMonth( m, y ) local days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } local month, year month = type( m ) == "N" ? m : ::month year = type( y ) == "N" ? m : ::year if ( ( month == 2 ) && ( year % 4 == 0 ) ) return( 29 ) end return( days[ month ] ) END METHOD DaysInYear( y ) local year year = type( y ) == "N" ? y : ::year return( year % 4 == 0 ? 366 : 365 ) END METHOD DaysInMillenium( ) local i, d=0 for ( i=2000; i<::year; i++ ) if ( i % 4 == 0 ) d += 366 else d += 365 end end for ( i=1; i<::month; i++ ) d += ::DaysInMonth( i, ::year ) end d += ::day return( d ) END METHOD cdow( _dow ) local days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } local dow dow = type( _dow ) == "N" ? _dow : ::dow( ) if ( ( dow < 1 ) || ( dow > 7 ) ) return( "unknown" ) end return( days[ dow ] ) END METHOD dow( ) local d if ( ::year < 2000 ) return( dow( ::_date ) ) end d = ::DaysInMillenium( ) // offset for dow of 01-01-2000 d -= 2 return( ( d % 7 ) + 1 ) END METHOD DateString( ) local d, rval d = date( ) dateset( ::_date ) rval = date( ::cdow( ) + " the DDDD day of MMMM, YYYY" ) dateset( d ) return( rval ) END METHOD dtoj( ) local d, rval d = date( ) dateset( ::_date ) rval = jdate( ) dateset( d ) return( rval ) END METHOD jtod( ) return( dtoc( ::_date ) ) END METHOD time( ) return( time( ) ) END METHOD timeh( ) return( timeh( ) ) END METHOD timeAmPm( pmFlag ) local flag flag = type( pmFlag ) == "N" ? pmFlag : 0 return( timetostr( time( ), flag ) + ( flag ? "" : "m" ) ) END END //////////////////// // End of Listing // //////////////////// =============================================================================== FGL TIPS: Typeless Variables =============================================================================== Programmers from way back remember "fondly" languages that were easily crashed by commands such as this: 1 + "hello there" = crash_and_burn In this example two elements are added together producing a compiler or runtime error at the very least or a complete reboot at the worst. This is because the addition involves two different types of variables: a numeric value added to a string data type. While there are actually good reasons to have a hard-casted typed language, today's development environment is better served with a typeless language. JavaScript and FGL are specific examples of typeless languages. With a typeless language, variables are represented internally by a specific type, such as numeric or string, but can be combined with other data types or even converted on-the-fly from one type to another. Typed languages such as "C" require that variables be pre-defined and memory allocated before their use. Likewise memory must be freed after they are no longer needed. And, mixing types is a no-no. The primary benefits of this typed environment is the enhanced speed and error checking that occurs internally with a typed language as well as the higher degree of control (and burden) related to memory management. FGL maintains its own internal error handler as well as optimized automated memory manager thereby circumventing the only real benefits of the typed language. With FGL, the process of "typing" a variable occurs through it actual use. For example: a = "Hello There" b = 1 c = a + " #" + b d = b + a e = "47" f = b + e println( c ) // prints: Hello There #1 println( d ) // prints: 1 println( f ) // prints: 48 The value of "c" is set to a string type because the first element it encounters is if type string. Thereafter all subsequent operations are automatically created to string type data. The value of "d", however is set to type numeric because that is the type of the first element encountered. Thereafter all other data elements are likewise converted to type numeric. In this case the string "Hello World" has a numeric value of 0 which when added to "b" equals 1. In the example involving the value "f", the initial value is type numeric and the string "e" is added to it. But it is first converted to a numeric value. Since the string contains valid numeric values though represented in string format, the system converts the string "47" to the numeric value 47 which is then added to "b" to produce the result 48. =============================================================================== THIS WEEK'S REFERRAL: VirtualPROMOTE =============================================================================== Building a web site is one thing, but letting everybody else know about it is another thing altogether. VirtualPROMOTE provides all the information you will ever need to get your site listed on the search engines and to build traffic and brand recognition along the way. Beyond the basic, thisd site includes extensive tutorials, case studies, and real-world suggestions that can separate you from the pack. One of the most useful features, however, is the extensive use of real-time forums to capture the latest information regrading this entire area of expertise while tapping into the expertise of the extensive VirtualPROMOTE web community. See for yourself at: http://www.virtualpromote.com =============================================================================== This newsletter is the copyrighted material of West Coast Web Adventures, Inc. (c) 2001 by West Coast Web Adventures, Inc., All Rights Reserved. ===============================================================================