Traveller Store CotI Features New Posts Mark Forums Read Register


Go Back TravellerRPG.com > Citizens of the Imperium > General Traveller Discussions > Software Solutions

Software Solutions Discussions on Traveller related software.

View Poll Results: What Programming Languages do you currently code in?
C/C++ 31 39.24%
Go 6 7.59%
Windows Based (C#, .Net, etc) 25 31.65%
Python 32 40.51%
Perl 18 22.78%
Java 15 18.99%
Ruby 5 6.33%
PHP 10 12.66%
Shell 20 25.32%
Other(please post) 25 31.65%
JavaScript/ECMAScript 22 27.85%
SQL 24 30.38%
Multiple Choice Poll. Voters: 79. You may not vote on this poll

Reply
 
Thread Tools Display Modes
  #191  
Old January 16th, 2021, 04:04 AM
ShawnDriscoll's Avatar
ShawnDriscoll ShawnDriscoll is offline
Citizen: SOC-13
 
Join Date: Apr 2017
Posts: 910
Gallery : 0
ShawnDriscoll Citizen+ShawnDriscoll Citizen+
Default

Cython is Python code that is compiled into C code. It does simple things like convert dynamic type variables into strong type variables. The compiled code can be called by Python apps. Cython code can be be embedded into C code. C code can by embedded into Python code, etc. Back and forth usage, basically.
Reply With Quote
  #192  
Old January 16th, 2021, 12:26 PM
zamosc's Avatar
zamosc zamosc is offline
Citizen: SOC-6
 
Join Date: Dec 2020
Posts: 17
Gallery : 0
zamosc Citizen
Default

Quote:
Originally Posted by ShawnDriscoll View Post
Cython is Python code that is compiled into C code. It does simple things like convert dynamic type variables into strong type variables. The compiled code can be called by Python apps. Cython code can be be embedded into C code. C code can by embedded into Python code, etc. Back and forth usage, basically.
That sounds very portable and very similar to why I use Tcl and recently started to look into Lua. When you say 'Python code that is compiled into C code', does that mean you can generate C code/files with GCC or Clang?

I remember recently (not very recent, but recently) that I was trying to use an external module/library in a Python 3.6 and I downloaded the compiler via pip. Seemed like after compiling to native code, when some sections of the module would be called the compiled code would barf. Due to the latter, rushed around to find a similar Cpan module, and compiled via Perl. The end target machine was not going to have Python, nor would policy allow for Python to be installed. However, I could sign my own executable, to have a 'in-house' developed solution installed. ++wink++ don't ask.

It is events like that, which made me start looking at Go. Not many folks coming fresh out of university today want to code in C. Or create create Lua libraries to be called.

On another trek, I had great hopes for Objective-C and the replacement Swift. Not being a MAC/Apple supporter since the loss of MOS chips then PowerPC, but with IBM backing of Swift on mainframes it was refreshing to see something of the sort, yet it looks like IBM stopped funding or openly supporting Swift.

To be honest, I never learned how to think in Object Oriented Programming (OOP) models. And still to this day I struggle with OOP concepts. I would love to say I can use C++ and Qt; however, that is not the case. I know they are very similar to structures, but cannot get the old 6502 running at 1 Mhz to compute. ++deep laugh++, could you imagine how long it would take a 6502 to build a SSL/SSH handshake negotiation, or generate a sha512sum key....

If you know of any good OOP books for C++, C# or even .NET Basic I would be interested. Not looking for GUI design books, all my stuff lives in CLI or embedded hardware. However, at the end of the day, I still have STRUCTURES in my C.
Reply With Quote
  #193  
Old January 16th, 2021, 01:31 PM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,755
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

Once I started dealing with objects and messages, things became a lot clearer. Just like Go objects, a Python or Perl object is usually a mix of data and methods. Of course, Go doesn't have inheritance, but it does have polymorphism via interfaces.

Here's a Perl example, fresh from this morning's work. A section of text will have a "reading grade level", often based on the Flesch-Kincaid scale. Naturally, I make a "Section" object that has a test to see what the grade level is. However, sections don't actually store the data, they get it from a Report object.

Being able to mentally isolate things like that really helps me focus on small bits at a time. The Section gives the Report a copy of the text, and asks for an evaluation. I can change how the work is done and as long as the tests pass, life is good. The Book object will ask each section for their grade levels, and average them out for a total.

The flip side, of course, is trying to talk to someone about objects and they start going into 27,315 levels of indirection. It can be over done, but a little bit goes a long way to make life simpler and code easier to comprehend.
__________________
Chronicler, the Domici War
Reply With Quote
  #194  
Old January 17th, 2021, 02:04 AM
ShawnDriscoll's Avatar
ShawnDriscoll ShawnDriscoll is offline
Citizen: SOC-13
 
Join Date: Apr 2017
Posts: 910
Gallery : 0
ShawnDriscoll Citizen+ShawnDriscoll Citizen+
Default

Quote:
Originally Posted by zamosc View Post
When you say 'Python code that is compiled into C code', does that mean you can generate C code/files with GCC or Clang?
Yes. I use GCC.
Quote:
Originally Posted by zamosc View Post
I remember recently (not very recent, but recently) that I was trying to use an external module/library in a Python 3.6 and I downloaded the compiler via pip. Seemed like after compiling to native code, when some sections of the module would be called the compiled code would barf. Due to the latter, rushed around to find a similar Cpan module, and compiled via Perl. The end target machine was not going to have Python, nor would policy allow for Python to be installed. However, I could sign my own executable, to have a 'in-house' developed solution installed. ++wink++ don't ask.
If you are compiling a C program for Python to run (a .pyd file), you will need to use a C compiler that matches the one used for that version of Python you're running. Pretty much every other version of Python was created with a different version of Microsoft Visual Studio.
Quote:
Originally Posted by zamosc View Post
If you know of any good OOP books for C++, C# or even .NET Basic I would be interested. Not looking for GUI design books, all my stuff lives in CLI or embedded hardware. However, at the end of the day, I still have STRUCTURES in my C.
Only 1% of the programming I do needs OOP features. I do programming like in the '70s. Top-down structural procedural programming. No one talks like that anymore, even though they are using languages from the '70s. They call it coding now. Or app development, etc.

Amazon has all the O'Reilly books. Just get the OOP book for the language you are programming in.
Reply With Quote
  #195  
Old January 17th, 2021, 09:09 AM
Leitz's Avatar
Leitz Leitz is offline
Baron
 
Join Date: Mar 2009
Location: Wretched hive of scum and villany
Posts: 2,755
Gallery : 0
Leitz Citizen+Leitz Citizen+Leitz Citizen+
Default

Quote:
Originally Posted by zamosc View Post
If you know of any good OOP books for C++, C# or even .NET Basic I would be interested.
I enjoyed the first edition of Head First Design Patterns, and that might help you see how objects can be used. Having a "useful why" often helps motivate more than just a passing interest. The concepts are presented easily, so you will likely be able to mentally translate that to whatever language you prefer.
__________________
Chronicler, the Domici War
Reply With Quote
  #196  
Old January 17th, 2021, 01:09 PM
zamosc's Avatar
zamosc zamosc is offline
Citizen: SOC-6
 
Join Date: Dec 2020
Posts: 17
Gallery : 0
zamosc Citizen
Default

Quote:
Originally Posted by ShawnDriscoll View Post
Only 1% of the programming I do needs OOP features. I do programming like in the '70s. Top-down structural procedural programming. No one talks like that anymore, even though they are using languages from the '70s. They call it coding now. Or app development, etc.
I am the same way - I started in the 80s, so a lot of my code, no matter what language looks like code from Byte or Commodore/Amiga of the same time.

I will look into Cython, since you can compile with GCC that might help me be able to deploy code. Thank you
Reply With Quote
  #197  
Old January 17th, 2021, 01:12 PM
zamosc's Avatar
zamosc zamosc is offline
Citizen: SOC-6
 
Join Date: Dec 2020
Posts: 17
Gallery : 0
zamosc Citizen
Default

Quote:
Originally Posted by Leitz View Post
I enjoyed the first edition of Head First Design Patterns, and that might help you see how objects can be used. Having a "useful why" often helps motivate more than just a passing interest. The concepts are presented easily, so you will likely be able to mentally translate that to whatever language you prefer.
I agree... Thank you for the book recommendation.
Reply With Quote
  #198  
Old January 17th, 2021, 02:40 PM
whartung whartung is offline
Citizen: SOC-14
 
Join Date: Nov 2004
Posts: 2,744
Gallery : 0
whartung Citizen+whartung Citizen+whartung Citizen+
Default

Quote:
Originally Posted by zamosc View Post
To be honest, I never learned how to think in Object Oriented Programming (OOP) models.
Simply, your programs aren't big enough, or you're not sharing the code amongst independent programs much.

If you were, you'd find the OOP stuff much more intuitive as it solves these needs readily and easily.

The simplest example, especially for a C developer, is probably standard file I/O, ye old FILE *fp.

In C, you pass the context to all of the stdio IO routines (fread, fwrite, fopen, fclose). In a (typical) OOP system, rather than passing the context to the function, you call the function on the context. The context has code attached to the instance of the object.

You also have the stdio routines in your global namespace. Which is why we have fread, fwrite etc, because read and write were already taken by low level I/O.

Consider this simple routine (apologies if this is imperfect it's representative, rather than normative)
Code:
    int count(FILE* fp) {
        char ch;
        int cnt;
        ch = getc(fp);
        while(ch != EOF) {
            cnt++;
            ch = getc(fp);
        }
        return cnt;
    }
Given a file pointer, you can count the number of characters in the file.

The issue here is, as is, this is as far as you can go.

Here's two use cases:
Code:
    FILE *fp = fopen("file.dat", "r");
    printf("file had %d characters", count(fp));
and

Code:
    printf("stdin has %d characters", count(STDIN));
STDIN is predefined FILE pointer to represent standard input.

But that's as far as you can go.

Now let's consider Java.

Code:
    public int count(InputStream is) {
        int cnt = 0;
        int b;
        b = is.read();
        while(b != -1) {
            cnt++;
            b = is.read();
        }
        return cnt;
    }
Very similar to the C code. The key difference is we're using InputStream vs a FILE *.

Here's how it comes in to play as a difference:
Code:
    FileInputStream fis = new FileInputStream("file.dat");
    int cnt = count(fis);
    System.out.println ("file has " + cnt + " bytes");

    cnt = count(System.in); // System.in is the STDIN as an InputStream
    System.out.println ("stdin has " + cnt + " bytes");

    String str = "This is a test";
    StringBuffer sb = new StringBuffer(str);
    StringInputStream sis = new StringBufferInputStream(s);
    cnt = count(sis);
    System.out.println("StringBuffer has " + cnt + " bytes");

    ByteArray ba = str.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream();
    cnt = count(bis);
    // This number may be different than the previous example, 
    // for reasons out of scope in this discussion
    System.out.println("String byte array has " + cnt + " bytes");

    ServerSocket server = new ServerSocket(8888);
    Socket socket = server.accept();
    cnt = count(socket.getInputStream());
    System.out.println ("socket client sent " + cnt + " bytes");
Here you can see InputStream as the universal abstraction across all of these different higher level concepts. Files, buffers, sockets, etc. The actual code is the same. This "count" code can be shared readily across programs in these different domains.

But an important concept is that the "read" method from InputStream, while named the same across all of the constructs, all do different things. Any byte level data structure can have expose an InputStream. An image, a sound, etc. Anything that's worth iterating over at a byte level can be made manifest as an InputStream. But the namespace is tied to the implementation class, rather than the entire of the file.

C++ solved these kind of problems two different ways. One was through standard OOP inheritance and method dispatch, much like Java. The other is through generic programming via Templates.

Whereas in standard OOP, that "count" method would be written once and rely on dispatch via the implementation class to do the work, C++ Templates would have essentially re-written the "count" method for each use case. It's a different mechanism of abstraction.

Now, in practice, most applications themselves do very little OOP. They rely a lot on OOP frameworks (such as the java.io system mentioned here), but rarely have to implement their own. Most folks are just writing code to do work: process a file, handle some input, do some math. This is typically very rote work. Input -> Magic -> Output.

The utility space is where you'll see OOP more in action. I/O frameworks, data structures, GUIs. Common code used by lot of programs where re-use and extensibility are key long term values.

In all of my work over the years, in Java, I've created very few base classes or interfaces for our own work. There's certainly been some, and they were re-used heavily. But when 90% of your work is pushing stuff in to and pulling stuff out of SQL data bases, which is what the majority of back office work is nowadays, there's just not a lot of code sharing. The Person table isn't like the Invoice table at all when the rubber meets the road, and that's the code that I write. Someone else did the interface to the database, in a nice generic way so I could swap that out to most any database I like.

In C the Postgres C library is completely different from the MySQL C library. If you wanted to switch databases, you would you have to rewrite good chunks of your code. In Java, there's a generic layer that handles that for you, so if you wanted to switch, most of your code would not have to be rewritten.

You could write a generic layer in C, but C doesn't make that easy. It just relies on idioms (structs of function pointers, essentially). The technique is there, it's just not a first class citizen.

But most folks enjoy the benefits of OOP without necessarily writing OOP style code themselves. In fact they get themselves in to trouble trying to force it on their application that doesn't need it. OOP is great for infrastructure, most folks don't write infrastructure.

As systems get larger and more complex, when more code wants to be reused, then concepts like OOP make things easier. Obviously there are large systems in C, nothing is impossible, but OOP structure can make these systems easier. OOP rose out of frustrations with baser languages like C.
Reply With Quote
  #199  
Old January 18th, 2021, 05:17 PM
aramis's Avatar
aramis aramis is offline
Administrator
 
Join Date: May 2001
Location: Anchorage, AK, USofA
Posts: 29,518
Gallery : 56
Visit aramis's Blog
aramis has disabled reputation
Send a message via ICQ to aramis Send a message via AIM to aramis Send a message via Yahoo to aramis
Default

Quote:
Originally Posted by zamosc View Post
I am the same way - I started in the 80s, so a lot of my code, no matter what language looks like code from Byte or Commodore/Amiga of the same time.

I will look into Cython, since you can compile with GCC that might help me be able to deploy code. Thank you
I broke from that "spaghetti code" mode in the late 1990's.
C will break one of it. But it only forces one to function-based programming.
I've never successfully made the conceptual leap to proper OOP...

As for programming, python 3+ has a standalone maker while it's not compiled, it's just the needed parts of the python interpreter to run the object code .pyo.

Pretty nifty. pyinstaller
__________________
~ Aramis
aramis.hostman.us /trav
Smith & Wesson: The Original Point and Click interface!

Archduke of Sylea (CORE 2118)
Duke of the Third Imperium (SPIN 0534)
Count Terra (SOLO 1827)
Count Gorod (REFT 1302)
Count of the Third Imperium (SPIN 2232)
Viscount of Adabicci (SPIN 1824)
Marquis of the Solomani Rim (SOLO 0606)
Marquis of the Third Imperium (SPIN 2410)
Baron of the Third Imperium (SPIN 2231)
Knight of the Iridium Throne (CORE 1434)
Sir William Hostman (OLDE 0512)
Sir William Hostman (DAGU 0622)
Knight of Deneb (REFT 2239)
Knight of Deneb (Spin 2532)
SEH w/Diamonds for Extreme Heroism - Battle of Boughene
MCG - Battle of Boughene
TAS: William Hostman (CORR 2506)
TAS: Bearer (DAIB 1326)
IMTU ct+ tm++ tne tg-- tt+ tmo+ t4- t20+ to ru+ ge+ 3i+ c+ jt au ls pi+ ta he+ st+
Wil Hostman 0602 C539857-9 S A724
OTU: 95% 3i an+ au+ br- cpu± dt± f+ fs++ ge± ih- inf± j± jf+ jm+ jt+ ls- n= nc+ pi+ pp-- tp+ tr+ tv- vi-- xb+-
Unless there is bold red text, presume my posts to be my personal material only.
Reply With Quote
  #200  
Old January 20th, 2021, 02:33 PM
zamosc's Avatar
zamosc zamosc is offline
Citizen: SOC-6
 
Join Date: Dec 2020
Posts: 17
Gallery : 0
zamosc Citizen
Default

Quote:
Originally Posted by aramis View Post
I broke from that "spaghetti code" mode in the late 1990's.
C will break one of it. But it only forces one to function-based programming.
I've never successfully made the conceptual leap to proper OOP...

As for programming, python 3+ has a standalone maker while it's not compiled, it's just the needed parts of the python interpreter to run the object code .pyo.

Pretty nifty. pyinstaller
I am glad you recommended 'pyinstaller'. I believe some on another team have used it already for 'matplotlib'. I see these item have been tested already according to the website, which is reassuring. When I have to build a gui, I am still stuck in Tkinter land, but I suspect due to coming from Tcl/Tk and Perl/Tk.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Programming Language(s)? Vargas Software Solutions 82 November 27th, 2016 08:25 PM
Vilani Programming robject Software Solutions 14 June 6th, 2014 02:55 AM
LBB2 Ship Programming Idears jawillroy Classic Traveller 13 June 6th, 2008 01:36 PM
languages sid6.7 Contact! 4 June 13th, 2006 01:52 AM
[Semi-OT] What programming language should I learn? Golan2072 Software Solutions 60 June 9th, 2006 12:17 PM

This website and its contents are copyright ©2010- Far Future Enterprises. All rights reserved. Traveller is a registered trademark of Far Future Enterprises .
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright (c) 2010-2013, Far Future Enterprises. All Rights Reserved.